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