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