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

Unified 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: remove PRERENDER flag change Created 7 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 side-by-side diff with in-line comments
Download patch
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..5f7fb3730949be7623f9a45042245b1d8ca16818
--- /dev/null
+++ b/chrome/browser/net/predictor_tab_helper.cc
@@ -0,0 +1,61 @@
+// 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/browser_thread.h"
+#include "content/public/common/frame_navigate_params.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper);
+
+using content::BrowserThread;
+
+namespace {
+
+bool IsUserLinkNavigationRequest(content::PageTransition page_transition) {
+ bool is_link = (content::PageTransitionStripQualifier(page_transition) ==
+ content::PAGE_TRANSITION_LINK);
+ bool is_forward_back = (page_transition &
+ content::PAGE_TRANSITION_FORWARD_BACK) != 0;
+ // Tracking navigation session including client-side redirect
+ // is currently not supported.
+ bool is_client_redirect = (page_transition &
+ content::PAGE_TRANSITION_CLIENT_REDIRECT) != 0;
+ return is_link && !is_forward_back && !is_client_redirect;
+}
+
+} // namespace
+
+namespace chrome_browser_net {
+
+PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents) {
+}
+
+PredictorTabHelper::~PredictorTabHelper() {
+}
+
+void PredictorTabHelper::DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) {
+ if (!IsUserLinkNavigationRequest(params.transition) ||
+ !(params.url.SchemeIs("http") || params.url.SchemeIs("https")))
+ return;
+
+ Profile* profile = Profile::FromBrowserContext(
+ web_contents()->GetBrowserContext());
+ Predictor* predictor = profile->GetNetworkPredictor();
+ if (predictor) {
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&Predictor::RecordLinkNavigation,
+ base::Unretained(predictor),
+ params.url));
+ }
+}
+
+} // namespace chrome_browser_net
« no previous file with comments | « chrome/browser/net/predictor_tab_helper.h ('k') | chrome/browser/renderer_host/chrome_render_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698