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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/browser/prerender/prerender_manager.h" | 10 #include "chrome/browser/prerender/prerender_manager.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 base::Histogram::kUmaTargetedHistogramFlag); | 73 base::Histogram::kUmaTargetedHistogramFlag); |
74 } | 74 } |
75 base::Histogram* count_hover_events() { return count_hover_events_; } | 75 base::Histogram* count_hover_events() { return count_hover_events_; } |
76 base::Histogram* time_hover_until_click() { return time_hover_until_click_; } | 76 base::Histogram* time_hover_until_click() { return time_hover_until_click_; } |
77 | 77 |
78 private: | 78 private: |
79 base::Histogram* count_hover_events_; | 79 base::Histogram* count_hover_events_; |
80 base::Histogram* time_hover_until_click_; | 80 base::Histogram* time_hover_until_click_; |
81 }; | 81 }; |
82 | 82 |
| 83 enum PAGEVIEW_EVENTS { |
| 84 PAGEVIEW_EVENT_NEW_URL = 0, |
| 85 PAGEVIEW_EVENT_TOP_SITE_NEW_URL = 1, |
| 86 PAGEVIEW_EVENT_LOAD_START = 2, |
| 87 PAGEVIEW_EVENT_TOP_SITE_LOAD_START = 3, |
| 88 PAGEVIEW_EVENT_MAX = 4 |
| 89 }; |
| 90 |
| 91 void RecordPageviewEvent(PAGEVIEW_EVENTS event) { |
| 92 UMA_HISTOGRAM_ENUMERATION("Prerender.PageviewEvents", |
| 93 event, PAGEVIEW_EVENT_MAX); |
| 94 } |
| 95 |
83 } // namespace | 96 } // namespace |
84 | 97 |
85 class PrerenderObserver::HoverData { | 98 class PrerenderObserver::HoverData { |
86 public: | 99 public: |
87 void SetHoverThreshold(int threshold_ms) { | 100 void SetHoverThreshold(int threshold_ms) { |
88 hover_threshold_ = base::TimeDelta::FromMilliseconds(threshold_ms); | 101 hover_threshold_ = base::TimeDelta::FromMilliseconds(threshold_ms); |
89 histograms_.reset(new PerHoverThresholdHistograms(threshold_ms)); | 102 histograms_.reset(new PerHoverThresholdHistograms(threshold_ms)); |
90 } | 103 } |
91 | 104 |
92 void RecordHover(const GURL& url) { | 105 void RecordHover(const GURL& url) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 last_hovers_(new HoverData[kNumHoverThresholds]) { | 186 last_hovers_(new HoverData[kNumHoverThresholds]) { |
174 for (int i = 0; i < kNumHoverThresholds; i++) | 187 for (int i = 0; i < kNumHoverThresholds; i++) |
175 last_hovers_[i].SetHoverThreshold(kMinHoverThresholdsMs[i]); | 188 last_hovers_[i].SetHoverThreshold(kMinHoverThresholdsMs[i]); |
176 } | 189 } |
177 | 190 |
178 PrerenderObserver::~PrerenderObserver() { | 191 PrerenderObserver::~PrerenderObserver() { |
179 } | 192 } |
180 | 193 |
181 void PrerenderObserver::ProvisionalChangeToMainFrameUrl(const GURL& url, | 194 void PrerenderObserver::ProvisionalChangeToMainFrameUrl(const GURL& url, |
182 bool has_opener_set) { | 195 bool has_opener_set) { |
| 196 RecordPageviewEvent(PAGEVIEW_EVENT_NEW_URL); |
| 197 if (IsTopSite(url)) |
| 198 RecordPageviewEvent(PAGEVIEW_EVENT_TOP_SITE_NEW_URL); |
183 if (!tab_->delegate()) | 199 if (!tab_->delegate()) |
184 return; // PrerenderManager needs a delegate to handle the swap. | 200 return; // PrerenderManager needs a delegate to handle the swap. |
185 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); | 201 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); |
186 if (!prerender_manager) | 202 if (!prerender_manager) |
187 return; | 203 return; |
188 if (prerender_manager->IsTabContentsPrerendering(tab_contents())) | 204 if (prerender_manager->IsTabContentsPrerendering(tab_contents())) |
189 return; | 205 return; |
190 prerender_manager->MarkTabContentsAsNotPrerendered(tab_contents()); | 206 prerender_manager->MarkTabContentsAsNotPrerendered(tab_contents()); |
191 MaybeUsePrerenderedPage(url, has_opener_set); | 207 MaybeUsePrerenderedPage(url, has_opener_set); |
192 } | 208 } |
193 | 209 |
194 bool PrerenderObserver::OnMessageReceived(const IPC::Message& message) { | 210 bool PrerenderObserver::OnMessageReceived(const IPC::Message& message) { |
195 IPC_BEGIN_MESSAGE_MAP(PrerenderObserver, message) | 211 IPC_BEGIN_MESSAGE_MAP(PrerenderObserver, message) |
196 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, | 212 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, |
197 OnDidStartProvisionalLoadForFrame) | 213 OnDidStartProvisionalLoadForFrame) |
198 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnMsgUpdateTargetURL) | 214 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnMsgUpdateTargetURL) |
199 IPC_END_MESSAGE_MAP() | 215 IPC_END_MESSAGE_MAP() |
200 return false; | 216 return false; |
201 } | 217 } |
202 | 218 |
203 void PrerenderObserver::OnDidStartProvisionalLoadForFrame(int64 frame_id, | 219 void PrerenderObserver::OnDidStartProvisionalLoadForFrame(int64 frame_id, |
204 bool is_main_frame, | 220 bool is_main_frame, |
205 bool has_opener_set, | 221 bool has_opener_set, |
206 const GURL& url) { | 222 const GURL& url) { |
207 if (is_main_frame) { | 223 if (is_main_frame) { |
| 224 RecordPageviewEvent(PAGEVIEW_EVENT_LOAD_START); |
| 225 if (IsTopSite(url)) |
| 226 RecordPageviewEvent(PAGEVIEW_EVENT_TOP_SITE_LOAD_START); |
| 227 |
208 // Record the beginning of a new PPLT navigation. | 228 // Record the beginning of a new PPLT navigation. |
209 pplt_load_start_ = base::TimeTicks::Now(); | 229 pplt_load_start_ = base::TimeTicks::Now(); |
210 | 230 |
211 // Update hover stats. | 231 // Update hover stats. |
212 for (int i = 0; i < kNumHoverThresholds; i++) | 232 for (int i = 0; i < kNumHoverThresholds; i++) |
213 last_hovers_[i].RecordNavigation(url); | 233 last_hovers_[i].RecordNavigation(url); |
214 | 234 |
215 MaybeLogCurrentHover(current_hover_url_ == url); | 235 MaybeLogCurrentHover(current_hover_url_ == url); |
216 } | 236 } |
217 } | 237 } |
(...skipping 16 matching lines...) Expand all Loading... |
234 // Compute the PPLT metric and report it in a histogram, if needed. | 254 // Compute the PPLT metric and report it in a histogram, if needed. |
235 if (!pplt_load_start_.is_null() && !IsPrerendering()) { | 255 if (!pplt_load_start_.is_null() && !IsPrerendering()) { |
236 PrerenderManager::RecordPerceivedPageLoadTime( | 256 PrerenderManager::RecordPerceivedPageLoadTime( |
237 base::TimeTicks::Now() - pplt_load_start_, tab_contents()); | 257 base::TimeTicks::Now() - pplt_load_start_, tab_contents()); |
238 } | 258 } |
239 | 259 |
240 // Reset the PPLT metric. | 260 // Reset the PPLT metric. |
241 pplt_load_start_ = base::TimeTicks(); | 261 pplt_load_start_ = base::TimeTicks(); |
242 } | 262 } |
243 | 263 |
244 PrerenderManager* PrerenderObserver::MaybeGetPrerenderManager() { | 264 PrerenderManager* PrerenderObserver::MaybeGetPrerenderManager() const { |
245 Profile* profile = | 265 Profile* profile = |
246 Profile::FromBrowserContext(tab_contents()->browser_context()); | 266 Profile::FromBrowserContext(tab_contents()->browser_context()); |
247 return profile->GetPrerenderManager(); | 267 return profile->GetPrerenderManager(); |
248 } | 268 } |
249 | 269 |
250 bool PrerenderObserver::MaybeUsePrerenderedPage(const GURL& url, | 270 bool PrerenderObserver::MaybeUsePrerenderedPage(const GURL& url, |
251 bool has_opener_set) { | 271 bool has_opener_set) { |
252 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); | 272 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); |
253 if (!prerender_manager) | 273 if (!prerender_manager) |
254 return false; | 274 return false; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 UMA_HISTOGRAM_ENUMERATION("Prerender.HoverStats_TimeUntilClicked", | 316 UMA_HISTOGRAM_ENUMERATION("Prerender.HoverStats_TimeUntilClicked", |
297 elapsed_ms, num_buckets); | 317 elapsed_ms, num_buckets); |
298 } else { | 318 } else { |
299 UMA_HISTOGRAM_ENUMERATION("Prerender.HoverStats_TimeUntilDiscarded", | 319 UMA_HISTOGRAM_ENUMERATION("Prerender.HoverStats_TimeUntilDiscarded", |
300 elapsed_ms, num_buckets); | 320 elapsed_ms, num_buckets); |
301 } | 321 } |
302 | 322 |
303 current_hover_url_ = GURL(); | 323 current_hover_url_ = GURL(); |
304 } | 324 } |
305 | 325 |
| 326 bool PrerenderObserver::IsTopSite(const GURL& url) const { |
| 327 PrerenderManager* pm = MaybeGetPrerenderManager(); |
| 328 return (pm && pm->IsTopSite(url)); |
| 329 } |
| 330 |
306 } // namespace prerender | 331 } // namespace prerender |
OLD | NEW |