Home | History | Annotate | Download | only in prerender
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_OBSERVER_H_
      6 #define CHROME_BROWSER_PRERENDER_PRERENDER_OBSERVER_H_
      7 #pragma once
      8 
      9 #include <list>
     10 #include <vector>
     11 
     12 #include "base/memory/scoped_ptr.h"
     13 #include "base/time.h"
     14 #include "content/browser/tab_contents/tab_contents_observer.h"
     15 #include "googleurl/src/gurl.h"
     16 
     17 class PrerenderContents;
     18 class Profile;
     19 class TabContents;
     20 
     21 namespace prerender {
     22 
     23 class PrerenderManager;
     24 
     25 // PrerenderObserver is responsible for recording perceived pageload times
     26 // to compare PLT's with prerendering enabled and disabled.
     27 class PrerenderObserver : public TabContentsObserver {
     28  public:
     29   explicit PrerenderObserver(TabContents* tab_contents);
     30   virtual ~PrerenderObserver();
     31 
     32   // TabContentsObserver implementation.
     33   virtual void ProvisionalChangeToMainFrameUrl(const GURL& url);
     34   virtual bool OnMessageReceived(const IPC::Message& message);
     35 
     36   // Message handler.
     37   void OnDidStartProvisionalLoadForFrame(int64 frame_id,
     38                                          bool main_frame,
     39                                          const GURL& url);
     40 
     41   virtual void DidStopLoading();
     42 
     43  private:
     44   // Retrieves the PrerenderManager, or NULL, if none was found.
     45   PrerenderManager* MaybeGetPrerenderManager();
     46 
     47   // Checks with the PrerenderManager if the specified URL has been preloaded,
     48   // and if so, swap the RenderViewHost with the preload into this TabContents
     49   // object.
     50   bool MaybeUsePreloadedPage(const GURL& url);
     51 
     52   // System time at which the current load was started for the purpose of
     53   // the perceived page load time (PPLT).
     54   base::TimeTicks pplt_load_start_;
     55 
     56   DISALLOW_COPY_AND_ASSIGN(PrerenderObserver);
     57 };
     58 
     59 }  // prerender
     60 
     61 #endif  // CHROME_BROWSER_PRERENDER_PRERENDER_OBSERVER_H_
     62