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 <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // to compare PLT's with prerendering enabled and disabled. | 24 // to compare PLT's with prerendering enabled and disabled. |
25 class PrerenderTabHelper | 25 class PrerenderTabHelper |
26 : public content::WebContentsObserver, | 26 : public content::WebContentsObserver, |
27 public content::WebContentsUserData<PrerenderTabHelper> { | 27 public content::WebContentsUserData<PrerenderTabHelper> { |
28 public: | 28 public: |
29 ~PrerenderTabHelper() override; | 29 ~PrerenderTabHelper() override; |
30 | 30 |
31 // content::WebContentsObserver implementation. | 31 // content::WebContentsObserver implementation. |
32 void DidGetRedirectForResourceRequest( | 32 void DidGetRedirectForResourceRequest( |
33 const content::ResourceRedirectDetails& details) override; | 33 const content::ResourceRedirectDetails& details) override; |
34 void DidStopLoading() override; | |
35 void DidStartNavigation( | 34 void DidStartNavigation( |
36 content::NavigationHandle* navigation_handle) override; | 35 content::NavigationHandle* navigation_handle) override; |
37 void DidFinishNavigation( | 36 void DidFinishNavigation( |
38 content::NavigationHandle* navigation_handle) override; | 37 content::NavigationHandle* navigation_handle) override; |
39 | 38 |
40 // Called when the URL of the main frame changed, either when the load | 39 // Called when the URL of the main frame changed, either when the load |
41 // commits, or a redirect happens. | 40 // commits, or a redirect happens. |
42 void MainFrameUrlDidChange(const GURL& url); | 41 void MainFrameUrlDidChange(const GURL& url); |
43 | 42 |
44 // Called when this prerendered WebContents has just been swapped in. | 43 // Called when this prerendered WebContents has just been swapped in. |
45 void PrerenderSwappedIn(); | 44 void PrerenderSwappedIn(); |
46 | 45 |
47 base::TimeTicks swap_ticks() const { return swap_ticks_; } | 46 base::TimeTicks swap_ticks() const { return swap_ticks_; } |
48 | 47 |
49 Origin origin() const { return origin_; } | 48 Origin origin() const { return origin_; } |
50 | 49 |
51 private: | 50 private: |
52 explicit PrerenderTabHelper(content::WebContents* web_contents); | 51 explicit PrerenderTabHelper(content::WebContents* web_contents); |
53 friend class content::WebContentsUserData<PrerenderTabHelper>; | 52 friend class content::WebContentsUserData<PrerenderTabHelper>; |
54 | 53 |
55 void RecordPerceivedPageLoadTime( | |
56 base::TimeDelta perceived_page_load_time, | |
57 double fraction_plt_elapsed_at_swap_in); | |
58 | |
59 // Retrieves the PrerenderManager, or NULL, if none was found. | 54 // Retrieves the PrerenderManager, or NULL, if none was found. |
60 PrerenderManager* MaybeGetPrerenderManager() const; | 55 PrerenderManager* MaybeGetPrerenderManager() const; |
61 | 56 |
62 // Returns the current TimeTicks synchronized with PrerenderManager ticks. In | 57 // Returns the current TimeTicks synchronized with PrerenderManager ticks. In |
63 // tests the clock can be mocked out in PrerenderManager, but in production | 58 // tests the clock can be mocked out in PrerenderManager, but in production |
64 // this should be always TimeTicks::Now(). | 59 // this should be always TimeTicks::Now(). |
65 base::TimeTicks GetTimeTicksFromPrerenderManager() const; | 60 base::TimeTicks GetTimeTicksFromPrerenderManager() const; |
66 | 61 |
67 // Returns whether the WebContents being observed is currently prerendering. | 62 // Returns whether the WebContents being observed is currently prerendering. |
68 bool IsPrerendering(); | 63 bool IsPrerendering(); |
69 | 64 |
70 // The type the current pending navigation, if there is one. If the tab is a | 65 // The type the current pending navigation, if there is one. If the tab is a |
71 // prerender before swap, the value is always NAVIGATION_TYPE_PRERENDERED, | 66 // prerender before swap, the value is always NAVIGATION_TYPE_PRERENDERED, |
72 // even if the prerender is not currently loading. | 67 // even if the prerender is not currently loading. |
73 NavigationType navigation_type_; | 68 NavigationType navigation_type_; |
74 | 69 |
75 // If |navigation_type_| is not NAVIGATION_TYPE_NORMAL, the origin of the | 70 // If |navigation_type_| is not NAVIGATION_TYPE_NORMAL, the origin of the |
76 // relevant prerender. Otherwise, ORIGIN_NONE. | 71 // relevant prerender. Otherwise, ORIGIN_NONE. |
77 Origin origin_; | 72 Origin origin_; |
78 | 73 |
79 // System time at which the current load was started for the purpose of | 74 // Record the most recent swap time. |
80 // the perceived page load time (PPLT). If null, there is no current | |
81 // load. | |
82 base::TimeTicks pplt_load_start_; | |
83 | |
84 // System time at which the actual pageload started (pre-swapin), if | |
85 // a applicable (in cases when a prerender that was still loading was | |
86 // swapped in). | |
87 base::TimeTicks actual_load_start_; | |
88 | |
89 // Record the most recent swap time. This differs from |pplt_load_start_| in | |
90 // that it is not reset in various circumstances, like a load being stopped. | |
91 base::TimeTicks swap_ticks_; | 75 base::TimeTicks swap_ticks_; |
92 | 76 |
93 // Current URL being loaded. | 77 // Current URL being loaded. |
94 GURL url_; | 78 GURL url_; |
95 | 79 |
96 base::WeakPtrFactory<PrerenderTabHelper> weak_factory_; | 80 base::WeakPtrFactory<PrerenderTabHelper> weak_factory_; |
97 | 81 |
98 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper); | 82 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper); |
99 }; | 83 }; |
100 | 84 |
101 } // namespace prerender | 85 } // namespace prerender |
102 | 86 |
103 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ | 87 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_ |
OLD | NEW |