| 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 predictors::LoggedInPredictorTable* MaybeGetLoggedInTable() const; |
| 88 |
| 62 // Returns whether the WebContents being observed is currently prerendering. | 89 // Returns whether the WebContents being observed is currently prerendering. |
| 63 bool IsPrerendering(); | 90 bool IsPrerendering(); |
| 64 | 91 |
| 65 // Returns whether the WebContents being observed was prerendered. | 92 // Returns whether the WebContents being observed was prerendered. |
| 66 bool IsPrerendered(); | 93 bool IsPrerendered(); |
| 67 | 94 |
| 68 // System time at which the current load was started for the purpose of | 95 // System time at which the current load was started for the purpose of |
| 69 // the perceived page load time (PPLT). | 96 // the perceived page load time (PPLT). |
| 70 base::TimeTicks pplt_load_start_; | 97 base::TimeTicks pplt_load_start_; |
| 71 | 98 |
| 72 // System time at which the actual pageload started (pre-swapin), if | 99 // System time at which the actual pageload started (pre-swapin), if |
| 73 // a applicable (in cases when a prerender that was still loading was | 100 // a applicable (in cases when a prerender that was still loading was |
| 74 // swapped in). | 101 // swapped in). |
| 75 base::TimeTicks actual_load_start_; | 102 base::TimeTicks actual_load_start_; |
| 76 | 103 |
| 77 // Current URL being loaded. | 104 // Current URL being loaded. |
| 78 GURL url_; | 105 GURL url_; |
| 79 | 106 |
| 107 base::WeakPtrFactory<PrerenderTabHelper> weak_factory_; |
| 108 |
| 80 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper); | 109 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper); |
| 81 }; | 110 }; |
| 82 | 111 |
| 83 } // namespace prerender | 112 } // namespace prerender |
| 84 | 113 |
| 85 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ | 114 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ |
| OLD | NEW |