Chromium Code Reviews| 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/profiles/profile.h" | |
| 11 #include "chrome/browser/tab_contents/origins_seen_service.h" | |
| 12 #include "chrome/browser/tab_contents/origins_seen_service_factory.h" | |
| 10 #include "components/navigation_metrics/navigation_metrics.h" | 13 #include "components/navigation_metrics/navigation_metrics.h" |
| 11 #include "components/rappor/rappor_utils.h" | 14 #include "components/rappor/rappor_utils.h" |
| 15 #include "content/public/browser/browser_context.h" | |
| 12 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 14 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 15 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/render_widget_host.h" | 20 #include "content/public/browser/render_widget_host.h" |
| 17 #include "content/public/browser/render_widget_host_view.h" | 21 #include "content/public/browser/render_widget_host_view.h" |
| 18 #include "content/public/common/frame_navigate_params.h" | 22 #include "content/public/common/frame_navigate_params.h" |
| 19 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 #include "url/origin.h" | |
| 20 | 25 |
| 21 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 22 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
| 23 #endif | 28 #endif |
| 24 | 29 |
| 25 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder); | 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder); |
| 26 | 31 |
| 27 NavigationMetricsRecorder::NavigationMetricsRecorder( | 32 NavigationMetricsRecorder::NavigationMetricsRecorder( |
| 28 content::WebContents* web_contents) | 33 content::WebContents* web_contents) |
| 29 : content::WebContentsObserver(web_contents) { | 34 : content::WebContentsObserver(web_contents) { |
| 30 } | 35 } |
| 31 | 36 |
| 32 NavigationMetricsRecorder::~NavigationMetricsRecorder() { | 37 NavigationMetricsRecorder::~NavigationMetricsRecorder() { |
| 33 } | 38 } |
| 34 | 39 |
| 35 void NavigationMetricsRecorder::DidNavigateMainFrame( | 40 void NavigationMetricsRecorder::DidNavigateMainFrame( |
| 36 const content::LoadCommittedDetails& details, | 41 const content::LoadCommittedDetails& details, |
| 37 const content::FrameNavigateParams& params) { | 42 const content::FrameNavigateParams& params) { |
| 38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 39 navigation_metrics::RecordMainFrameNavigation(details.entry->GetVirtualURL(), | 44 |
| 40 details.is_in_page); | 45 content::BrowserContext* context = web_contents()->GetBrowserContext(); |
| 46 Profile* profile = Profile::FromBrowserContext(context); | |
| 47 OriginsSeenService* service = | |
| 48 OriginsSeenServiceFactory::GetForProfile(profile); | |
|
Avi (use Gerrit)
2016/04/14 02:43:26
You shouldn't need to pass in a Profile here, just
palmer
2016/04/14 18:47:33
Done.
| |
| 49 const url::Origin origin(details.entry->GetVirtualURL()); | |
| 50 bool have_already_seen_origin = service->HaveAlreadySeenOrigin(origin); | |
| 51 | |
| 52 navigation_metrics::RecordMainFrameNavigation( | |
| 53 details.entry->GetVirtualURL(), details.is_in_page, | |
| 54 context->IsOffTheRecord(), have_already_seen_origin); | |
| 55 | |
| 41 // Record the domain and registry of the URL that resulted in a navigation to | 56 // Record the domain and registry of the URL that resulted in a navigation to |
| 42 // a |data:| URL, either by redirects or user clicking a link. | 57 // a |data:| URL, either by redirects or user clicking a link. |
| 43 if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) && | 58 if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) && |
| 44 params.transition != ui::PAGE_TRANSITION_TYPED && | 59 params.transition != ui::PAGE_TRANSITION_TYPED && |
| 45 !details.previous_url.is_empty()) { | 60 !details.previous_url.is_empty()) { |
| 46 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 61 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
| 47 "Navigation.Scheme.Data", | 62 "Navigation.Scheme.Data", |
| 48 details.previous_url); | 63 details.previous_url); |
| 49 } | 64 } |
| 50 } | 65 } |
| OLD | NEW |