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