OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ |
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" |
9 #include "base/time.h" | 10 #include "base/time.h" |
10 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
11 #include "content/public/browser/web_contents_user_data.h" | 12 #include "content/public/browser/web_contents_user_data.h" |
12 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
13 | 14 |
| 15 namespace predictors { |
| 16 class LoggedInPredictorTable; |
| 17 } |
| 18 |
14 namespace prerender { | 19 namespace prerender { |
15 | 20 |
16 class PrerenderManager; | 21 class PrerenderManager; |
17 | 22 |
18 // PrerenderTabHelper is responsible for recording perceived pageload times | 23 // PrerenderTabHelper is responsible for recording perceived pageload times |
19 // to compare PLT's with prerendering enabled and disabled. | 24 // to compare PLT's with prerendering enabled and disabled. |
20 class PrerenderTabHelper | 25 class PrerenderTabHelper |
21 : public content::WebContentsObserver, | 26 : public content::WebContentsObserver, |
22 public content::WebContentsUserData<PrerenderTabHelper> { | 27 public content::WebContentsUserData<PrerenderTabHelper> { |
23 public: | 28 public: |
| 29 enum Event { |
| 30 EVENT_LOGGED_IN_TABLE_REQUESTED = 0, |
| 31 EVENT_LOGGED_IN_TABLE_PRESENT = 1, |
| 32 EVENT_MAINFRAME_CHANGE = 2, |
| 33 EVENT_MAINFRAME_CHANGE_DOMAIN_LOGGED_IN = 3, |
| 34 EVENT_MAINFRAME_COMMIT = 4, |
| 35 EVENT_MAINFRAME_COMMIT_DOMAIN_LOGGED_IN = 5, |
| 36 EVENT_LOGIN_ACTION_ADDED = 6, |
| 37 EVENT_MAX_VALUE |
| 38 }; |
| 39 |
24 virtual ~PrerenderTabHelper(); | 40 virtual ~PrerenderTabHelper(); |
25 | 41 |
26 // content::WebContentsObserver implementation. | 42 // content::WebContentsObserver implementation. |
27 virtual void ProvisionalChangeToMainFrameUrl( | 43 virtual void ProvisionalChangeToMainFrameUrl( |
28 const GURL& url, | 44 const GURL& url, |
29 content::RenderViewHost* render_view_host) OVERRIDE; | 45 content::RenderViewHost* render_view_host) OVERRIDE; |
30 virtual void DidStopLoading( | 46 virtual void DidStopLoading( |
31 content::RenderViewHost* render_view_host) OVERRIDE; | 47 content::RenderViewHost* render_view_host) OVERRIDE; |
32 virtual void DidStartProvisionalLoadForFrame( | 48 virtual void DidStartProvisionalLoadForFrame( |
33 int64 frame_id, | 49 int64 frame_id, |
34 int64 parent_frame_id, | 50 int64 parent_frame_id, |
35 bool is_main_frame, | 51 bool is_main_frame, |
36 const GURL& validated_url, | 52 const GURL& validated_url, |
37 bool is_error_page, | 53 bool is_error_page, |
38 bool is_iframe_srcdoc, | 54 bool is_iframe_srcdoc, |
39 content::RenderViewHost* render_view_host) OVERRIDE; | 55 content::RenderViewHost* render_view_host) OVERRIDE; |
40 virtual void DidCommitProvisionalLoadForFrame( | 56 virtual void DidCommitProvisionalLoadForFrame( |
41 int64 frame_id, | 57 int64 frame_id, |
42 bool is_main_frame, | 58 bool is_main_frame, |
43 const GURL& validated_url, | 59 const GURL& validated_url, |
44 content::PageTransition transition_type, | 60 content::PageTransition transition_type, |
45 content::RenderViewHost* render_view_host) OVERRIDE; | 61 content::RenderViewHost* render_view_host) OVERRIDE; |
| 62 virtual void DidNavigateAnyFrame( |
| 63 const content::LoadCommittedDetails& details, |
| 64 const content::FrameNavigateParams& params) OVERRIDE; |
| 65 |
46 // Called when this prerendered WebContents has just been swapped in. | 66 // Called when this prerendered WebContents has just been swapped in. |
47 void PrerenderSwappedIn(); | 67 void PrerenderSwappedIn(); |
48 | 68 |
49 private: | 69 private: |
50 explicit PrerenderTabHelper(content::WebContents* web_contents); | 70 explicit PrerenderTabHelper(content::WebContents* web_contents); |
51 friend class content::WebContentsUserData<PrerenderTabHelper>; | 71 friend class content::WebContentsUserData<PrerenderTabHelper>; |
52 | 72 |
| 73 void RecordEvent(Event event) const; |
| 74 void RecordEventIfLoggedInURL(Event event, const GURL& url); |
| 75 void RecordEventIfLoggedInURLResult(Event event, scoped_ptr<bool> is_present, |
| 76 scoped_ptr<bool> lookup_succeeded); |
53 // Helper class to compute pixel-based stats on the paint progress | 77 // 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 | 78 // between when a prerendered page is swapped in and when the onload event |
55 // fires. | 79 // fires. |
56 class PixelStats; | 80 class PixelStats; |
57 scoped_ptr<PixelStats> pixel_stats_; | 81 scoped_ptr<PixelStats> pixel_stats_; |
58 | 82 |
59 // Retrieves the PrerenderManager, or NULL, if none was found. | 83 // Retrieves the PrerenderManager, or NULL, if none was found. |
60 PrerenderManager* MaybeGetPrerenderManager() const; | 84 PrerenderManager* MaybeGetPrerenderManager() const; |
61 | 85 |
| 86 // Retrieves the LoggedInPredictorTable, or NULL, if none was found. |
| 87 scoped_refptr<predictors::LoggedInPredictorTable> |
| 88 MaybeGetLoggedInTable() const; |
| 89 |
62 // Returns whether the WebContents being observed is currently prerendering. | 90 // Returns whether the WebContents being observed is currently prerendering. |
63 bool IsPrerendering(); | 91 bool IsPrerendering(); |
64 | 92 |
65 // Returns whether the WebContents being observed was prerendered. | 93 // Returns whether the WebContents being observed was prerendered. |
66 bool IsPrerendered(); | 94 bool IsPrerendered(); |
67 | 95 |
68 // System time at which the current load was started for the purpose of | 96 // System time at which the current load was started for the purpose of |
69 // the perceived page load time (PPLT). | 97 // the perceived page load time (PPLT). |
70 base::TimeTicks pplt_load_start_; | 98 base::TimeTicks pplt_load_start_; |
71 | 99 |
72 // System time at which the actual pageload started (pre-swapin), if | 100 // System time at which the actual pageload started (pre-swapin), if |
73 // a applicable (in cases when a prerender that was still loading was | 101 // a applicable (in cases when a prerender that was still loading was |
74 // swapped in). | 102 // swapped in). |
75 base::TimeTicks actual_load_start_; | 103 base::TimeTicks actual_load_start_; |
76 | 104 |
77 // Current URL being loaded. | 105 // Current URL being loaded. |
78 GURL url_; | 106 GURL url_; |
79 | 107 |
| 108 base::WeakPtrFactory<PrerenderTabHelper> weak_factory_; |
| 109 |
80 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper); | 110 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper); |
81 }; | 111 }; |
82 | 112 |
83 } // namespace prerender | 113 } // namespace prerender |
84 | 114 |
85 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ | 115 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ |
OLD | NEW |