1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_
8 #include "base/memory/scoped_ptr.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/browser/web_contents_user_data.h"
12 #include "googleurl/src/gurl.h"
16 class PrerenderManager
;
18 // PrerenderTabHelper is responsible for recording perceived pageload times
19 // to compare PLT's with prerendering enabled and disabled.
20 class PrerenderTabHelper
21 : public content::WebContentsObserver
,
22 public content::WebContentsUserData
<PrerenderTabHelper
> {
24 virtual ~PrerenderTabHelper();
26 // content::WebContentsObserver implementation.
27 virtual void ProvisionalChangeToMainFrameUrl(
29 content::RenderViewHost
* render_view_host
) OVERRIDE
;
30 virtual void DidStopLoading(
31 content::RenderViewHost
* render_view_host
) OVERRIDE
;
32 virtual void DidStartProvisionalLoadForFrame(
34 int64 parent_frame_id
,
36 const GURL
& validated_url
,
38 bool is_iframe_srcdoc
,
39 content::RenderViewHost
* render_view_host
) OVERRIDE
;
40 virtual void DidCommitProvisionalLoadForFrame(
43 const GURL
& validated_url
,
44 content::PageTransition transition_type
,
45 content::RenderViewHost
* render_view_host
) OVERRIDE
;
46 // Called when this prerendered WebContents has just been swapped in.
47 void PrerenderSwappedIn();
50 explicit PrerenderTabHelper(content::WebContents
* web_contents
);
51 friend class content::WebContentsUserData
<PrerenderTabHelper
>;
53 // Helper class to compute pixel-based stats on the paint progress
54 // between when a prerendered page is swapped in and when the onload event
57 scoped_ptr
<PixelStats
> pixel_stats_
;
59 // Retrieves the PrerenderManager, or NULL, if none was found.
60 PrerenderManager
* MaybeGetPrerenderManager() const;
62 // Returns whether the WebContents being observed is currently prerendering.
63 bool IsPrerendering();
65 // Returns whether the WebContents being observed was prerendered.
68 // System time at which the current load was started for the purpose of
69 // the perceived page load time (PPLT).
70 base::TimeTicks pplt_load_start_
;
72 // System time at which the actual pageload started (pre-swapin), if
73 // a applicable (in cases when a prerender that was still loading was
75 base::TimeTicks actual_load_start_
;
77 // Current URL being loaded.
80 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper
);
83 } // namespace prerender
85 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_