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

Side by Side Diff: chrome/browser/google/google_search_counter.cc

Issue 342053002: Add UMA metrics for Android Chrome Google Search. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated histogram name Created 6 years, 6 months 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 | Annotate | Revision Log
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/google/google_search_counter.h" 5 #include "chrome/browser/google/google_search_counter.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "components/google/core/browser/google_util.h" 8 #include "components/google/core/browser/google_util.h"
9 #include "content/public/browser/navigation_controller.h" 9 #include "content/public/browser/navigation_controller.h"
10 #include "content/public/browser/navigation_details.h" 10 #include "content/public/browser/navigation_details.h"
11 #include "content/public/browser/navigation_entry.h" 11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
14 14
15 namespace {
16
17 // Returns true iff |entry| represents a Google search from the Omnibox.
18 // This method assumes that we have already verified that |entry|'s URL is a
19 // Google search URL.
20 bool IsOmniboxGoogleSearchNavigation(const content::NavigationEntry& entry) {
21 const content::PageTransition stripped_transition =
22 PageTransitionStripQualifier(entry.GetTransitionType());
23 DCHECK(google_util::IsGoogleSearchUrl(entry.GetURL()));
24 return stripped_transition == content::PAGE_TRANSITION_GENERATED;
25 }
26
27 // Returns true iff |entry| represents a Google search from the Google Search
28 // App. This method assumes that we have already verified that |entry|'s URL is
29 // a Google search URL.
30 bool IsSearchAppGoogleSearchNavigation(const content::NavigationEntry& entry) {
31 DCHECK(google_util::IsGoogleSearchUrl(entry.GetURL()));
32 return entry.GetURL().query().find("source=search_app") !=
33 std::string::npos;
34 }
35
36 } // namespace
37
38 // static 15 // static
39 void GoogleSearchCounter::RegisterForNotifications() { 16 void GoogleSearchCounter::RegisterForNotifications() {
40 GoogleSearchCounter::GetInstance()->RegisterForNotificationsInternal(); 17 GoogleSearchCounter::GetInstance()->RegisterForNotificationsInternal();
41 } 18 }
42 19
43 // static 20 // static
44 GoogleSearchCounter* GoogleSearchCounter::GetInstance() { 21 GoogleSearchCounter* GoogleSearchCounter::GetInstance() {
45 return Singleton<GoogleSearchCounter>::get(); 22 return Singleton<GoogleSearchCounter>::get();
46 } 23 }
47 24
25 GoogleSearchMetrics::AccessPoint
26 GoogleSearchCounter::GetGoogleSearchAccessPointForSearchNavEntry(
27 const content::NavigationEntry& entry) const {
28 DCHECK(google_util::IsGoogleSearchUrl(entry.GetURL()));
29
30 // If the |entry| is FROM_ADDRESS_BAR, it comes from the omnibox; if it's
31 // GENERATED, the user was doing a search, rather than doing a navigation to a
32 // search URL (e.g. from hisotry, or pasted in).
33 if (entry.GetTransitionType() == (content::PAGE_TRANSITION_GENERATED |
34 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)) {
35 return GoogleSearchMetrics::AP_OMNIBOX;
36 }
37
38 // The string "source=search_app" in the |entry| URL represents a Google
39 // search from the Google Search App.
40 if (entry.GetURL().query().find("source=search_app") != std::string::npos)
41 return GoogleSearchMetrics::AP_SEARCH_APP;
42
43 // For all other cases that we have not yet implemented or care to measure, we
44 // log a generic "catch-all" metric.
45 return GoogleSearchMetrics::AP_OTHER;
46 }
47
48 bool GoogleSearchCounter::ShouldRecordCommittedDetails(
49 const content::NotificationDetails& details) const {
50 const content::LoadCommittedDetails* commit =
51 content::Details<content::LoadCommittedDetails>(details).ptr();
52 return google_util::IsGoogleSearchUrl(commit->entry->GetURL());
53 }
54
48 GoogleSearchCounter::GoogleSearchCounter() 55 GoogleSearchCounter::GoogleSearchCounter()
49 : search_metrics_(new GoogleSearchMetrics) { 56 : search_metrics_(new GoogleSearchMetrics) {
50 } 57 }
51 58
52 GoogleSearchCounter::~GoogleSearchCounter() { 59 GoogleSearchCounter::~GoogleSearchCounter() {
53 } 60 }
54 61
55 void GoogleSearchCounter::ProcessCommittedEntry( 62 void GoogleSearchCounter::ProcessCommittedEntry(
56 const content::NotificationSource& source, 63 const content::NotificationSource& source,
57 const content::NotificationDetails& details) { 64 const content::NotificationDetails& details) {
65 // Note that GoogleSearchMetrics logs metrics through UMA, which will only
66 // transmit these counts to the server if the user has opted into sending
67 // usage stats.
58 const content::LoadCommittedDetails* commit = 68 const content::LoadCommittedDetails* commit =
59 content::Details<content::LoadCommittedDetails>(details).ptr(); 69 content::Details<content::LoadCommittedDetails>(details).ptr();
60 const content::NavigationEntry& entry = *commit->entry; 70 const content::NavigationEntry& entry = *commit->entry;
61 71 if (ShouldRecordCommittedDetails(details)) {
62 // First see if this is a Google search URL at all. 72 search_metrics_->RecordGoogleSearch(
63 if (!google_util::IsGoogleSearchUrl(entry.GetURL())) 73 GetGoogleSearchAccessPointForSearchNavEntry(entry));
64 return;
65
66 // If the commit is a GENERATED commit with a Google search URL, we know it's
67 // an Omnibox search.
68 if (IsOmniboxGoogleSearchNavigation(entry)) {
69 // Note that GoogleSearchMetrics logs metrics through UMA, which will only
70 // transmit these counts to the server if the user has opted into sending
71 // usage stats.
72 search_metrics_->RecordGoogleSearch(GoogleSearchMetrics::AP_OMNIBOX);
73 } else if (IsSearchAppGoogleSearchNavigation(entry)) {
74 search_metrics_->RecordGoogleSearch(GoogleSearchMetrics::AP_SEARCH_APP);
75 } else {
76 // For all other cases that we have not yet implemented or care to measure,
77 // we log a generic "catch-all" metric.
78 search_metrics_->RecordGoogleSearch(GoogleSearchMetrics::AP_OTHER);
79 } 74 }
80 } 75 }
81 76
82 void GoogleSearchCounter::SetSearchMetricsForTesting( 77 void GoogleSearchCounter::SetSearchMetricsForTesting(
83 GoogleSearchMetrics* search_metrics) { 78 GoogleSearchMetrics* search_metrics) {
84 DCHECK(search_metrics); 79 DCHECK(search_metrics);
85 search_metrics_.reset(search_metrics); 80 search_metrics_.reset(search_metrics);
86 } 81 }
87 82
88 void GoogleSearchCounter::RegisterForNotificationsInternal() { 83 void GoogleSearchCounter::RegisterForNotificationsInternal() {
89 // We always listen for all COMMITTED navigations from all sources, as any 84 // We always listen for all COMMITTED navigations from all sources, as any
90 // one of them could be a navigation of interest. 85 // one of them could be a navigation of interest.
91 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 86 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
92 content::NotificationService::AllSources()); 87 content::NotificationService::AllSources());
93 } 88 }
94 89
95 void GoogleSearchCounter::Observe(int type, 90 void GoogleSearchCounter::Observe(int type,
96 const content::NotificationSource& source, 91 const content::NotificationSource& source,
97 const content::NotificationDetails& details) { 92 const content::NotificationDetails& details) {
98 switch (type) { 93 switch (type) {
99 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: 94 case content::NOTIFICATION_NAV_ENTRY_COMMITTED:
100 ProcessCommittedEntry(source, details); 95 ProcessCommittedEntry(source, details);
101 break; 96 break;
102 default: 97 default:
103 NOTREACHED(); 98 NOTREACHED();
104 } 99 }
105 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698