Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: chrome/browser/tab_contents/navigation_metrics_recorder.cc

Issue 2510803003: Pass RapporService to content/browser/ (Closed)
Patch Set: Fix more compile errors in JNI files Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/public/rappor_utils.h"
14 #include "components/rappor/rappor_utils.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" 17 #include "content/public/browser/navigation_details.h"
18 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.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 "url/gurl.h" 23 #include "url/gurl.h"
24 #include "url/origin.h" 24 #include "url/origin.h"
25 25
26 #if defined(OS_WIN) 26 #if defined(OS_WIN)
27 #include "base/win/windows_version.h" 27 #include "base/win/windows_version.h"
28 #endif 28 #endif
29 29
30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder); 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder);
31 31
32 NavigationMetricsRecorder::NavigationMetricsRecorder( 32 NavigationMetricsRecorder::NavigationMetricsRecorder(
33 content::WebContents* web_contents) 33 content::WebContents* web_contents)
34 : content::WebContentsObserver(web_contents), 34 : content::WebContentsObserver(web_contents),
35 rappor_service_(g_browser_process->rappor_service()) {} 35 rappor_service_(g_browser_process->rappor_service()) {}
36 36
37 NavigationMetricsRecorder::~NavigationMetricsRecorder() { 37 NavigationMetricsRecorder::~NavigationMetricsRecorder() {
38 } 38 }
39 39
40 void NavigationMetricsRecorder::set_rappor_service_for_testing( 40 void NavigationMetricsRecorder::set_rappor_service_for_testing(
41 rappor::RapporService* service) { 41 rappor::RapporServiceImpl* service) {
42 rappor_service_ = service; 42 rappor_service_ = service;
43 } 43 }
44 44
45 void NavigationMetricsRecorder::DidNavigateMainFrame( 45 void NavigationMetricsRecorder::DidNavigateMainFrame(
46 const content::LoadCommittedDetails& details, 46 const content::LoadCommittedDetails& details,
47 const content::FrameNavigateParams& params) { 47 const content::FrameNavigateParams& params) {
48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
49 49
50 content::BrowserContext* context = web_contents()->GetBrowserContext(); 50 content::BrowserContext* context = web_contents()->GetBrowserContext();
51 navigation_metrics::OriginsSeenService* service = 51 navigation_metrics::OriginsSeenService* service =
52 OriginsSeenServiceFactory::GetForBrowserContext(context); 52 OriginsSeenServiceFactory::GetForBrowserContext(context);
53 const url::Origin origin(details.entry->GetVirtualURL()); 53 const url::Origin origin(details.entry->GetVirtualURL());
54 bool have_already_seen_origin = service->Insert(origin); 54 bool have_already_seen_origin = service->Insert(origin);
55 55
56 navigation_metrics::RecordMainFrameNavigation( 56 navigation_metrics::RecordMainFrameNavigation(
57 details.entry->GetVirtualURL(), details.is_in_page, 57 details.entry->GetVirtualURL(), details.is_in_page,
58 context->IsOffTheRecord(), have_already_seen_origin); 58 context->IsOffTheRecord(), have_already_seen_origin);
59 59
60 // 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
61 // a |data:| URL, either by redirects or user clicking a link. 61 // a |data:| URL, either by redirects or user clicking a link.
62 if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) && 62 if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) &&
63 !ui::PageTransitionCoreTypeIs(params.transition, 63 !ui::PageTransitionCoreTypeIs(params.transition,
64 ui::PAGE_TRANSITION_TYPED) && 64 ui::PAGE_TRANSITION_TYPED) &&
65 !details.previous_url.is_empty()) { 65 !details.previous_url.is_empty()) {
66 rappor::SampleDomainAndRegistryFromGURL( 66 rappor::SampleDomainAndRegistryFromGURL(
67 rappor_service_, "Navigation.Scheme.Data", details.previous_url); 67 rappor_service_, "Navigation.Scheme.Data", details.previous_url);
68 } 68 }
69 } 69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698