Index: chrome/browser/net/predictor_tab_helper.cc |
diff --git a/chrome/browser/net/predictor_tab_helper.cc b/chrome/browser/net/predictor_tab_helper.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a4a3fd22383f4ba87f511dc9d312a721080ab447 |
--- /dev/null |
+++ b/chrome/browser/net/predictor_tab_helper.cc |
@@ -0,0 +1,92 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/net/predictor_tab_helper.h" |
+ |
+#include "chrome/browser/net/predictor.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "content/public/browser/notification_details.h" |
+#include "content/public/browser/notification_source.h" |
+#include "content/public/browser/notification_types.h" |
+#include "content/public/browser/resource_request_details.h" |
+ |
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); |
+ |
+namespace { |
+ |
+bool IsUserLinkNavigationRequest(content::ResourceRequestDetails* details) { |
+ if (details->resource_type != ResourceType::MAIN_FRAME) |
+ return false; |
+ |
+ content::PageTransition page_transition = details->page_transition; |
+ bool isLink = (content::PageTransitionStripQualifier(page_transition) == |
+ content::PAGE_TRANSITION_LINK); |
+ bool isForwardBack = (page_transition & |
+ content::PAGE_TRANSITION_FORWARD_BACK); |
+ bool isPrerender = (page_transition & |
+ content::PAGE_TRANSITION_PRERENDER); |
+ // tracking navigation session including client-side redirect |
+ // is currently not supported |
+ bool isClientRedirect = (page_transition & |
+ content::PAGE_TRANSITION_CLIENT_REDIRECT); |
+ return isLink && !isForwardBack && !isPrerender && !isClientRedirect; |
+} |
+ |
+} // namespace |
+ |
+namespace chrome_browser_net { |
+ |
+PredictorTabHelper::PredictorTabHelper( |
+ content::WebContents* web_contents) |
+ : web_contents_(web_contents) { |
+ registrar_.Add(this, |
+ content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, |
+ content::Source<content::WebContents>(web_contents)); |
+ registrar_.Add(this, |
+ content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
+ content::Source<content::WebContents>(web_contents)); |
+} |
+ |
+PredictorTabHelper::~PredictorTabHelper() { |
+} |
+ |
+void PredictorTabHelper::Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ switch (type) { |
+ case content::NOTIFICATION_RESOURCE_RESPONSE_STARTED: { |
+ content::ResourceRequestDetails* resource_request_details = |
+ content::Details<content::ResourceRequestDetails>(details).ptr(); |
+ if (IsUserLinkNavigationRequest(resource_request_details)) { |
+ DidNavigation(resource_request_details->url, |
+ resource_request_details->original_url); |
+ } |
+ } |
+ break; |
jar (doing other things)
2013/06/18 01:33:49
nit: break inside the curlie. Same on line 75
kouhei (in TOK)
2013/06/18 22:28:41
Done.
|
+ case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { |
+ content::ResourceRedirectDetails* resource_redirect_details = |
+ content::Details<content::ResourceRedirectDetails>(details).ptr(); |
+ if (IsUserLinkNavigationRequest(resource_redirect_details)) { |
+ DidNavigation(resource_redirect_details->url, |
+ resource_redirect_details->original_url); |
+ } |
+ } |
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
+} |
+ |
+void PredictorTabHelper::DidNavigation(const GURL& url, |
+ const GURL& original_url) { |
+ if (!url.SchemeIs("http") && !url.SchemeIs("https")) |
+ return; |
+ |
+ Profile* profile = Profile::FromBrowserContext( |
+ web_contents_->GetBrowserContext()); |
+ profile->GetNetworkPredictor()->RecordPreconnectNavigationStat( |
+ url, original_url); |
+} |
+ |
+} // namespace chrome_browser_net |