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" | |
11 #include "components/navigation_metrics/navigation_metrics.h" | 10 #include "components/navigation_metrics/navigation_metrics.h" |
12 #include "components/navigation_metrics/origins_seen_service.h" | |
13 #include "components/rappor/public/rappor_utils.h" | 11 #include "components/rappor/public/rappor_utils.h" |
14 #include "components/rappor/rappor_service_impl.h" | 12 #include "components/rappor/rappor_service_impl.h" |
15 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/navigation_handle.h" | 16 #include "content/public/browser/navigation_handle.h" |
19 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/render_widget_host.h" | 18 #include "content/public/browser/render_widget_host.h" |
21 #include "content/public/browser/render_widget_host_view.h" | 19 #include "content/public/browser/render_widget_host_view.h" |
22 #include "content/public/common/frame_navigate_params.h" | 20 #include "content/public/common/frame_navigate_params.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 rappor_service_ = service; | 68 rappor_service_ = service; |
71 } | 69 } |
72 | 70 |
73 void NavigationMetricsRecorder::DidFinishNavigation( | 71 void NavigationMetricsRecorder::DidFinishNavigation( |
74 content::NavigationHandle* navigation_handle) { | 72 content::NavigationHandle* navigation_handle) { |
75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 73 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
76 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) | 74 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) |
77 return; | 75 return; |
78 | 76 |
79 content::BrowserContext* context = web_contents()->GetBrowserContext(); | 77 content::BrowserContext* context = web_contents()->GetBrowserContext(); |
80 navigation_metrics::OriginsSeenService* service = | |
81 OriginsSeenServiceFactory::GetForBrowserContext(context); | |
82 content::NavigationEntry* last_committed_entry = | 78 content::NavigationEntry* last_committed_entry = |
83 web_contents()->GetController().GetLastCommittedEntry(); | 79 web_contents()->GetController().GetLastCommittedEntry(); |
84 const url::Origin origin(last_committed_entry->GetVirtualURL()); | |
85 bool have_already_seen_origin = service->Insert(origin); | |
86 | 80 |
87 navigation_metrics::RecordMainFrameNavigation( | 81 navigation_metrics::RecordMainFrameNavigation( |
88 last_committed_entry->GetVirtualURL(), | 82 last_committed_entry->GetVirtualURL(), |
89 navigation_handle->IsSameDocument(), context->IsOffTheRecord(), | 83 navigation_handle->IsSameDocument(), context->IsOffTheRecord()); |
90 have_already_seen_origin); | |
91 | 84 |
92 // Record the domain and registry of the URL that resulted in a navigation to | 85 // Record the domain and registry of the URL that resulted in a navigation to |
93 // a |data:| URL, either by redirects or user clicking a link. | 86 // a |data:| URL, either by redirects or user clicking a link. |
94 if (last_committed_entry->GetVirtualURL().SchemeIs(url::kDataScheme) && | 87 if (last_committed_entry->GetVirtualURL().SchemeIs(url::kDataScheme) && |
95 !ui::PageTransitionCoreTypeIs(navigation_handle->GetPageTransition(), | 88 !ui::PageTransitionCoreTypeIs(navigation_handle->GetPageTransition(), |
96 ui::PAGE_TRANSITION_TYPED)) { | 89 ui::PAGE_TRANSITION_TYPED)) { |
97 if (!navigation_handle->GetPreviousURL().is_empty()) { | 90 if (!navigation_handle->GetPreviousURL().is_empty()) { |
98 rappor::SampleDomainAndRegistryFromGURL( | 91 rappor::SampleDomainAndRegistryFromGURL( |
99 rappor_service_, "Navigation.Scheme.Data", | 92 rappor_service_, "Navigation.Scheme.Data", |
100 navigation_handle->GetPreviousURL()); | 93 navigation_handle->GetPreviousURL()); |
101 } | 94 } |
102 | 95 |
103 // Also record the mime type of the data: URL. | 96 // Also record the mime type of the data: URL. |
104 std::string mime_type; | 97 std::string mime_type; |
105 std::string charset; | 98 std::string charset; |
106 if (net::DataURL::Parse(last_committed_entry->GetVirtualURL(), &mime_type, | 99 if (net::DataURL::Parse(last_committed_entry->GetVirtualURL(), &mime_type, |
107 &charset, nullptr)) { | 100 &charset, nullptr)) { |
108 RecordDataURLMimeType(mime_type); | 101 RecordDataURLMimeType(mime_type); |
109 } | 102 } |
110 } | 103 } |
111 } | 104 } |
OLD | NEW |