| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/tab_contents/navigation_metrics_recorder.h" | 5 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/tab_contents/origins_seen_service_factory.h" | 10 #include "chrome/browser/tab_contents/origins_seen_service_factory.h" |
| 11 #include "components/navigation_metrics/navigation_metrics.h" | 11 #include "components/navigation_metrics/navigation_metrics.h" |
| 12 #include "components/navigation_metrics/origins_seen_service.h" | 12 #include "components/navigation_metrics/origins_seen_service.h" |
| 13 #include "components/rappor/rappor_service.h" |
| 13 #include "components/rappor/rappor_utils.h" | 14 #include "components/rappor/rappor_utils.h" |
| 14 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 17 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 18 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 19 #include "content/public/browser/render_widget_host.h" | 20 #include "content/public/browser/render_widget_host.h" |
| 20 #include "content/public/browser/render_widget_host_view.h" | 21 #include "content/public/browser/render_widget_host_view.h" |
| 21 #include "content/public/common/frame_navigate_params.h" | 22 #include "content/public/common/frame_navigate_params.h" |
| 22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 23 #include "url/origin.h" | 24 #include "url/origin.h" |
| 24 | 25 |
| 25 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 26 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 29 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder); | 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder); |
| 30 | 31 |
| 31 NavigationMetricsRecorder::NavigationMetricsRecorder( | 32 NavigationMetricsRecorder::NavigationMetricsRecorder( |
| 32 content::WebContents* web_contents) | 33 content::WebContents* web_contents) |
| 33 : content::WebContentsObserver(web_contents) { | 34 : content::WebContentsObserver(web_contents), |
| 35 rappor_service_(g_browser_process->rappor_service()) {} |
| 36 |
| 37 NavigationMetricsRecorder::~NavigationMetricsRecorder() { |
| 34 } | 38 } |
| 35 | 39 |
| 36 NavigationMetricsRecorder::~NavigationMetricsRecorder() { | 40 void NavigationMetricsRecorder::set_rappor_service_for_testing( |
| 41 rappor::RapporService* service) { |
| 42 rappor_service_ = service; |
| 37 } | 43 } |
| 38 | 44 |
| 39 void NavigationMetricsRecorder::DidNavigateMainFrame( | 45 void NavigationMetricsRecorder::DidNavigateMainFrame( |
| 40 const content::LoadCommittedDetails& details, | 46 const content::LoadCommittedDetails& details, |
| 41 const content::FrameNavigateParams& params) { | 47 const content::FrameNavigateParams& params) { |
| 42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 43 | 49 |
| 44 content::BrowserContext* context = web_contents()->GetBrowserContext(); | 50 content::BrowserContext* context = web_contents()->GetBrowserContext(); |
| 45 navigation_metrics::OriginsSeenService* service = | 51 navigation_metrics::OriginsSeenService* service = |
| 46 OriginsSeenServiceFactory::GetForBrowserContext(context); | 52 OriginsSeenServiceFactory::GetForBrowserContext(context); |
| 47 const url::Origin origin(details.entry->GetVirtualURL()); | 53 const url::Origin origin(details.entry->GetVirtualURL()); |
| 48 bool have_already_seen_origin = service->Insert(origin); | 54 bool have_already_seen_origin = service->Insert(origin); |
| 49 | 55 |
| 50 navigation_metrics::RecordMainFrameNavigation( | 56 navigation_metrics::RecordMainFrameNavigation( |
| 51 details.entry->GetVirtualURL(), details.is_in_page, | 57 details.entry->GetVirtualURL(), details.is_in_page, |
| 52 context->IsOffTheRecord(), have_already_seen_origin); | 58 context->IsOffTheRecord(), have_already_seen_origin); |
| 53 | 59 |
| 54 // Record the domain and registry of the URL that resulted in a navigation to | 60 // Record the domain and registry of the URL that resulted in a navigation to |
| 55 // a |data:| URL, either by redirects or user clicking a link. | 61 // a |data:| URL, either by redirects or user clicking a link. |
| 56 if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) && | 62 if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) && |
| 57 !ui::PageTransitionCoreTypeIs(params.transition, | 63 !ui::PageTransitionCoreTypeIs(params.transition, |
| 58 ui::PAGE_TRANSITION_TYPED) && | 64 ui::PAGE_TRANSITION_TYPED) && |
| 59 !details.previous_url.is_empty()) { | 65 !details.previous_url.is_empty()) { |
| 60 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 66 rappor::SampleDomainAndRegistryFromGURL( |
| 61 "Navigation.Scheme.Data", | 67 rappor_service_, "Navigation.Scheme.Data", details.previous_url); |
| 62 details.previous_url); | |
| 63 } | 68 } |
| 64 } | 69 } |
| OLD | NEW |