Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/prerender/prerender_observer.cc

Issue 7740029: Revert 98250 - Add code to keep track of what fraction of pageviews are top sites. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/prerender/prerender_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
96 } // namespace 83 } // namespace
97 84
98 class PrerenderObserver::HoverData { 85 class PrerenderObserver::HoverData {
99 public: 86 public:
100 void SetHoverThreshold(int threshold_ms) { 87 void SetHoverThreshold(int threshold_ms) {
101 hover_threshold_ = base::TimeDelta::FromMilliseconds(threshold_ms); 88 hover_threshold_ = base::TimeDelta::FromMilliseconds(threshold_ms);
102 histograms_.reset(new PerHoverThresholdHistograms(threshold_ms)); 89 histograms_.reset(new PerHoverThresholdHistograms(threshold_ms));
103 } 90 }
104 91
105 void RecordHover(const GURL& url) { 92 void RecordHover(const GURL& url) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 last_hovers_(new HoverData[kNumHoverThresholds]) { 173 last_hovers_(new HoverData[kNumHoverThresholds]) {
187 for (int i = 0; i < kNumHoverThresholds; i++) 174 for (int i = 0; i < kNumHoverThresholds; i++)
188 last_hovers_[i].SetHoverThreshold(kMinHoverThresholdsMs[i]); 175 last_hovers_[i].SetHoverThreshold(kMinHoverThresholdsMs[i]);
189 } 176 }
190 177
191 PrerenderObserver::~PrerenderObserver() { 178 PrerenderObserver::~PrerenderObserver() {
192 } 179 }
193 180
194 void PrerenderObserver::ProvisionalChangeToMainFrameUrl(const GURL& url, 181 void PrerenderObserver::ProvisionalChangeToMainFrameUrl(const GURL& url,
195 bool has_opener_set) { 182 bool has_opener_set) {
196 RecordPageviewEvent(PAGEVIEW_EVENT_NEW_URL);
197 if (IsTopSite(url))
198 RecordPageviewEvent(PAGEVIEW_EVENT_TOP_SITE_NEW_URL);
199 if (!tab_->delegate()) 183 if (!tab_->delegate())
200 return; // PrerenderManager needs a delegate to handle the swap. 184 return; // PrerenderManager needs a delegate to handle the swap.
201 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); 185 PrerenderManager* prerender_manager = MaybeGetPrerenderManager();
202 if (!prerender_manager) 186 if (!prerender_manager)
203 return; 187 return;
204 if (prerender_manager->IsTabContentsPrerendering(tab_contents())) 188 if (prerender_manager->IsTabContentsPrerendering(tab_contents()))
205 return; 189 return;
206 prerender_manager->MarkTabContentsAsNotPrerendered(tab_contents()); 190 prerender_manager->MarkTabContentsAsNotPrerendered(tab_contents());
207 MaybeUsePrerenderedPage(url, has_opener_set); 191 MaybeUsePrerenderedPage(url, has_opener_set);
208 } 192 }
209 193
210 bool PrerenderObserver::OnMessageReceived(const IPC::Message& message) { 194 bool PrerenderObserver::OnMessageReceived(const IPC::Message& message) {
211 IPC_BEGIN_MESSAGE_MAP(PrerenderObserver, message) 195 IPC_BEGIN_MESSAGE_MAP(PrerenderObserver, message)
212 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, 196 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
213 OnDidStartProvisionalLoadForFrame) 197 OnDidStartProvisionalLoadForFrame)
214 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnMsgUpdateTargetURL) 198 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnMsgUpdateTargetURL)
215 IPC_END_MESSAGE_MAP() 199 IPC_END_MESSAGE_MAP()
216 return false; 200 return false;
217 } 201 }
218 202
219 void PrerenderObserver::OnDidStartProvisionalLoadForFrame(int64 frame_id, 203 void PrerenderObserver::OnDidStartProvisionalLoadForFrame(int64 frame_id,
220 bool is_main_frame, 204 bool is_main_frame,
221 bool has_opener_set, 205 bool has_opener_set,
222 const GURL& url) { 206 const GURL& url) {
223 if (is_main_frame) { 207 if (is_main_frame) {
224 RecordPageviewEvent(PAGEVIEW_EVENT_LOAD_START);
225 if (IsTopSite(url))
226 RecordPageviewEvent(PAGEVIEW_EVENT_TOP_SITE_LOAD_START);
227
228 // Record the beginning of a new PPLT navigation. 208 // Record the beginning of a new PPLT navigation.
229 pplt_load_start_ = base::TimeTicks::Now(); 209 pplt_load_start_ = base::TimeTicks::Now();
230 210
231 // Update hover stats. 211 // Update hover stats.
232 for (int i = 0; i < kNumHoverThresholds; i++) 212 for (int i = 0; i < kNumHoverThresholds; i++)
233 last_hovers_[i].RecordNavigation(url); 213 last_hovers_[i].RecordNavigation(url);
234 214
235 MaybeLogCurrentHover(current_hover_url_ == url); 215 MaybeLogCurrentHover(current_hover_url_ == url);
236 } 216 }
237 } 217 }
(...skipping 16 matching lines...) Expand all
254 // Compute the PPLT metric and report it in a histogram, if needed. 234 // Compute the PPLT metric and report it in a histogram, if needed.
255 if (!pplt_load_start_.is_null() && !IsPrerendering()) { 235 if (!pplt_load_start_.is_null() && !IsPrerendering()) {
256 PrerenderManager::RecordPerceivedPageLoadTime( 236 PrerenderManager::RecordPerceivedPageLoadTime(
257 base::TimeTicks::Now() - pplt_load_start_, tab_contents()); 237 base::TimeTicks::Now() - pplt_load_start_, tab_contents());
258 } 238 }
259 239
260 // Reset the PPLT metric. 240 // Reset the PPLT metric.
261 pplt_load_start_ = base::TimeTicks(); 241 pplt_load_start_ = base::TimeTicks();
262 } 242 }
263 243
264 PrerenderManager* PrerenderObserver::MaybeGetPrerenderManager() const { 244 PrerenderManager* PrerenderObserver::MaybeGetPrerenderManager() {
265 Profile* profile = 245 Profile* profile =
266 Profile::FromBrowserContext(tab_contents()->browser_context()); 246 Profile::FromBrowserContext(tab_contents()->browser_context());
267 return profile->GetPrerenderManager(); 247 return profile->GetPrerenderManager();
268 } 248 }
269 249
270 bool PrerenderObserver::MaybeUsePrerenderedPage(const GURL& url, 250 bool PrerenderObserver::MaybeUsePrerenderedPage(const GURL& url,
271 bool has_opener_set) { 251 bool has_opener_set) {
272 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); 252 PrerenderManager* prerender_manager = MaybeGetPrerenderManager();
273 if (!prerender_manager) 253 if (!prerender_manager)
274 return false; 254 return false;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 UMA_HISTOGRAM_ENUMERATION("Prerender.HoverStats_TimeUntilClicked", 296 UMA_HISTOGRAM_ENUMERATION("Prerender.HoverStats_TimeUntilClicked",
317 elapsed_ms, num_buckets); 297 elapsed_ms, num_buckets);
318 } else { 298 } else {
319 UMA_HISTOGRAM_ENUMERATION("Prerender.HoverStats_TimeUntilDiscarded", 299 UMA_HISTOGRAM_ENUMERATION("Prerender.HoverStats_TimeUntilDiscarded",
320 elapsed_ms, num_buckets); 300 elapsed_ms, num_buckets);
321 } 301 }
322 302
323 current_hover_url_ = GURL(); 303 current_hover_url_ = GURL();
324 } 304 }
325 305
326 bool PrerenderObserver::IsTopSite(const GURL& url) const {
327 PrerenderManager* pm = MaybeGetPrerenderManager();
328 return (pm && pm->IsTopSite(url));
329 }
330
331 } // namespace prerender 306 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698