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

Side by Side Diff: chrome/browser/net/predictor_tab_helper.cc

Issue 16514008: Add metrics for calculating precision/recall of link navigation pre-connect triggers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 7 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/net/predictor_tab_helper.h"
6
7 #include "chrome/browser/net/predictor.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "content/public/browser/notification_details.h"
10 #include "content/public/browser/notification_source.h"
11 #include "content/public/browser/notification_types.h"
12 #include "content/public/browser/resource_request_details.h"
13
14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper);
15
16 namespace {
17
18 bool IsUserLinkNavigationRequest(content::ResourceRequestDetails* details) {
19 if (details->resource_type != ResourceType::MAIN_FRAME)
20 return false;
21
22 content::PageTransition page_transition = details->page_transition;
23 bool isLink = (content::PageTransitionStripQualifier(page_transition) ==
24 content::PAGE_TRANSITION_LINK);
25 bool isForwardBack = (page_transition &
26 content::PAGE_TRANSITION_FORWARD_BACK);
27 bool isPrerender = (page_transition &
28 content::PAGE_TRANSITION_PRERENDER);
29 // tracking navigation session including client-side redirect
30 // is currently not supported
31 bool isClientRedirect = (page_transition &
32 content::PAGE_TRANSITION_CLIENT_REDIRECT);
33 return isLink && !isForwardBack && !isPrerender && !isClientRedirect;
34 }
35
36 } // namespace
37
38 namespace chrome_browser_net {
39
40 PredictorTabHelper::PredictorTabHelper(
41 content::WebContents* web_contents)
42 : web_contents_(web_contents) {
43 registrar_.Add(this,
44 content::NOTIFICATION_RESOURCE_RESPONSE_STARTED,
45 content::Source<content::WebContents>(web_contents));
46 registrar_.Add(this,
47 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
48 content::Source<content::WebContents>(web_contents));
49 }
50
51 PredictorTabHelper::~PredictorTabHelper() {
52 }
53
54 void PredictorTabHelper::Observe(int type,
55 const content::NotificationSource& source,
56 const content::NotificationDetails& details) {
57 switch (type) {
58 case content::NOTIFICATION_RESOURCE_RESPONSE_STARTED: {
59 content::ResourceRequestDetails* resource_request_details =
60 content::Details<content::ResourceRequestDetails>(details).ptr();
61 if (IsUserLinkNavigationRequest(resource_request_details)) {
62 DidNavigation(resource_request_details->url,
63 resource_request_details->original_url);
64 }
65 break;
66 }
67 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: {
68 content::ResourceRedirectDetails* resource_redirect_details =
69 content::Details<content::ResourceRedirectDetails>(details).ptr();
70 if (IsUserLinkNavigationRequest(resource_redirect_details)) {
71 DidNavigation(resource_redirect_details->url,
72 resource_redirect_details->original_url);
73 }
74 break;
75 }
76 default:
77 NOTREACHED();
78 }
79 }
80
81 void PredictorTabHelper::DidNavigation(const GURL& url,
82 const GURL& original_url) {
83 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
84 return;
85
86 Profile* profile = Profile::FromBrowserContext(
87 web_contents_->GetBrowserContext());
88 profile->GetNetworkPredictor()->RecordPreconnectNavigationStat(
cbentzel 2013/06/24 01:46:46 This will be called on the UI thread but RecordPre
kouhei (in TOK) 2013/06/24 05:51:09 Done.
89 url, original_url);
90 }
91
92 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698