OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/prerender/prerender_observer.h" | 5 #include "chrome/browser/prerender/prerender_observer.h" |
6 | 6 |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "chrome/browser/prerender/prerender_manager.h" | 8 #include "chrome/browser/prerender/prerender_manager.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 void PrerenderObserver::ProvisionalChangeToMainFrameUrl(const GURL& url, | 25 void PrerenderObserver::ProvisionalChangeToMainFrameUrl(const GURL& url, |
26 bool has_opener_set) { | 26 bool has_opener_set) { |
27 if (!tab_->delegate()) | 27 if (!tab_->delegate()) |
28 return; // PrerenderManager needs a delegate to handle the swap. | 28 return; // PrerenderManager needs a delegate to handle the swap. |
29 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); | 29 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); |
30 if (!prerender_manager) | 30 if (!prerender_manager) |
31 return; | 31 return; |
32 if (prerender_manager->IsTabContentsPrerendering(tab_contents())) | 32 if (prerender_manager->IsTabContentsPrerendering(tab_contents())) |
33 return; | 33 return; |
34 prerender_manager->MarkTabContentsAsNotPrerendered(tab_contents()); | 34 prerender_manager->MarkTabContentsAsNotPrerendered(tab_contents()); |
35 MaybeUsePreloadedPage(url, has_opener_set); | 35 MaybeUsePrerenderedPage(url, has_opener_set); |
36 prerender_manager->RecordNavigation(url); | 36 prerender_manager->RecordNavigation(url); |
37 } | 37 } |
38 | 38 |
39 bool PrerenderObserver::OnMessageReceived(const IPC::Message& message) { | 39 bool PrerenderObserver::OnMessageReceived(const IPC::Message& message) { |
40 IPC_BEGIN_MESSAGE_MAP(PrerenderObserver, message) | 40 IPC_BEGIN_MESSAGE_MAP(PrerenderObserver, message) |
41 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, | 41 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, |
42 OnDidStartProvisionalLoadForFrame) | 42 OnDidStartProvisionalLoadForFrame) |
43 IPC_END_MESSAGE_MAP() | 43 IPC_END_MESSAGE_MAP() |
44 return false; | 44 return false; |
45 } | 45 } |
(...skipping 19 matching lines...) Expand all Loading... |
65 } | 65 } |
66 | 66 |
67 // Reset the PPLT metric. | 67 // Reset the PPLT metric. |
68 pplt_load_start_ = base::TimeTicks(); | 68 pplt_load_start_ = base::TimeTicks(); |
69 } | 69 } |
70 | 70 |
71 PrerenderManager* PrerenderObserver::MaybeGetPrerenderManager() { | 71 PrerenderManager* PrerenderObserver::MaybeGetPrerenderManager() { |
72 return tab_contents()->profile()->GetPrerenderManager(); | 72 return tab_contents()->profile()->GetPrerenderManager(); |
73 } | 73 } |
74 | 74 |
75 bool PrerenderObserver::MaybeUsePreloadedPage(const GURL& url, | 75 bool PrerenderObserver::MaybeUsePrerenderedPage(const GURL& url, |
76 bool has_opener_set) { | 76 bool has_opener_set) { |
77 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); | 77 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); |
78 if (!prerender_manager) | 78 if (!prerender_manager) |
79 return false; | 79 return false; |
80 DCHECK(!prerender_manager->IsTabContentsPrerendering(tab_contents())); | 80 DCHECK(!prerender_manager->IsTabContentsPrerendering(tab_contents())); |
81 return prerender_manager->MaybeUsePreloadedPage(tab_contents(), | 81 return prerender_manager->MaybeUsePrerenderedPage(tab_contents(), |
82 url, | 82 url, |
83 has_opener_set); | 83 has_opener_set); |
84 } | 84 } |
85 | 85 |
86 bool PrerenderObserver::IsPrerendering() { | 86 bool PrerenderObserver::IsPrerendering() { |
87 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); | 87 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); |
88 if (!prerender_manager) | 88 if (!prerender_manager) |
89 return false; | 89 return false; |
90 return prerender_manager->IsTabContentsPrerendering(tab_contents()); | 90 return prerender_manager->IsTabContentsPrerendering(tab_contents()); |
91 } | 91 } |
92 | 92 |
93 void PrerenderObserver::PrerenderSwappedIn() { | 93 void PrerenderObserver::PrerenderSwappedIn() { |
94 // Ensure we are not prerendering any more. | 94 // Ensure we are not prerendering any more. |
95 DCHECK(!IsPrerendering()); | 95 DCHECK(!IsPrerendering()); |
96 if (pplt_load_start_.is_null()) { | 96 if (pplt_load_start_.is_null()) { |
97 // If we have already finished loading, report a 0 PPLT. | 97 // If we have already finished loading, report a 0 PPLT. |
98 PrerenderManager::RecordPerceivedPageLoadTime(base::TimeDelta(), | 98 PrerenderManager::RecordPerceivedPageLoadTime(base::TimeDelta(), |
99 tab_contents()); | 99 tab_contents()); |
100 } else { | 100 } else { |
101 // If we have not finished loading yet, rebase the start time to now. | 101 // If we have not finished loading yet, rebase the start time to now. |
102 pplt_load_start_ = base::TimeTicks::Now(); | 102 pplt_load_start_ = base::TimeTicks::Now(); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 } // namespace prerender | 106 } // namespace prerender |
OLD | NEW |