Chromium Code Reviews| 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..4bb529736d8e81f88dc07c7b8897130d2edaa464 |
| --- /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; |
| + } |
| + 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( |
|
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.
|
| + url, original_url); |
| +} |
| + |
| +} // namespace chrome_browser_net |