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

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

Issue 342053002: Add UMA metrics for Android Chrome Google Search. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' 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_util.h" 5 #include "chrome/browser/google/google_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "components/google/core/browser/google_switches.h" 16 #include "components/google/core/browser/google_switches.h"
17 #include "components/google/core/browser/google_url_tracker.h" 17 #include "components/google/core/browser/google_url_tracker.h"
18 #include "components/url_fixer/url_fixer.h" 18 #include "components/url_fixer/url_fixer.h"
19 #include "content/public/browser/navigation_entry.h"
19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
20 #include "net/base/url_util.h" 21 #include "net/base/url_util.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 // Only use Link Doctor on official builds. It uses an API key, too, but 24 // Only use Link Doctor on official builds. It uses an API key, too, but
24 // seems best to just disable it, for more responsive error pages and to reduce 25 // seems best to just disable it, for more responsive error pages and to reduce
25 // server load. 26 // server load.
26 #if defined(GOOGLE_CHROME_BUILD) 27 #if defined(GOOGLE_CHROME_BUILD)
27 #define LINKDOCTOR_SERVER_REQUEST_URL "https://www.googleapis.com/rpc" 28 #define LINKDOCTOR_SERVER_REQUEST_URL "https://www.googleapis.com/rpc"
28 #else 29 #else
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 65
65 // True if |url| is a valid URL with HTTP or HTTPS scheme. If |port_permission| 66 // True if |url| is a valid URL with HTTP or HTTPS scheme. If |port_permission|
66 // is DISALLOW_NON_STANDARD_PORTS, this also requires |url| to use the standard 67 // is DISALLOW_NON_STANDARD_PORTS, this also requires |url| to use the standard
67 // port for its scheme (80 for HTTP, 443 for HTTPS). 68 // port for its scheme (80 for HTTP, 443 for HTTPS).
68 bool IsValidURL(const GURL& url, google_util::PortPermission port_permission) { 69 bool IsValidURL(const GURL& url, google_util::PortPermission port_permission) {
69 return url.is_valid() && url.SchemeIsHTTPOrHTTPS() && 70 return url.is_valid() && url.SchemeIsHTTPOrHTTPS() &&
70 (url.port().empty() || 71 (url.port().empty() ||
71 (port_permission == google_util::ALLOW_NON_STANDARD_PORTS)); 72 (port_permission == google_util::ALLOW_NON_STANDARD_PORTS));
72 } 73 }
73 74
75 // Returns true iff |entry| represents a Google search from the Omnibox.
76 // This method assumes that we have already verified that |entry|'s URL is a
77 // Google search URL.
78 bool IsOmniboxGoogleSearchNavigation(const content::NavigationEntry& entry) {
Peter Kasting 2014/06/19 21:20:32 Given that these two functions are extremely short
kmadhusu 2014/06/19 22:52:49 Done.
79 const content::PageTransition stripped_transition =
80 PageTransitionStripQualifier(entry.GetTransitionType());
81 DCHECK(google_util::IsGoogleSearchUrl(entry.GetURL()));
82 return stripped_transition == content::PAGE_TRANSITION_GENERATED;
Peter Kasting 2014/06/19 21:20:32 Don't you also need to check for PAGE_TRANSITION_F
kmadhusu 2014/06/19 22:52:49 I moved this code from GoogleSearchCounter to here
Peter Kasting 2014/06/19 22:58:05 I would grep the codebase for PAGE_TRANSITION_GENE
kmadhusu 2014/06/19 23:21:45 Okay.
kmadhusu 2014/06/20 01:15:07 Updated the check.
83 }
84
85 // Returns true iff |entry| represents a Google search from the Google Search
86 // App. This method assumes that we have already verified that |entry|'s URL is
87 // a Google search URL.
88 bool IsSearchAppGoogleSearchNavigation(const content::NavigationEntry& entry) {
89 DCHECK(google_util::IsGoogleSearchUrl(entry.GetURL()));
90 return entry.GetURL().query().find("source=search_app") !=
91 std::string::npos;
Peter Kasting 2014/06/19 21:20:32 Nit: Indent 4, not even
kmadhusu 2014/06/19 22:52:49 Fixed.
92 }
93
74 } // namespace 94 } // namespace
75 95
76 96
77 namespace google_util { 97 namespace google_util {
78 98
79 // Global functions ----------------------------------------------------------- 99 // Global functions -----------------------------------------------------------
80 100
81 bool HasGoogleSearchQueryParam(const std::string& str) { 101 bool HasGoogleSearchQueryParam(const std::string& str) {
82 url::Component query(0, str.length()), key, value; 102 url::Component query(0, str.length()), key, value;
83 while (url::ExtractQueryKeyValue(str.c_str(), &query, &key, &value)) { 103 while (url::ExtractQueryKeyValue(str.c_str(), &query, &key, &value)) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 (!is_home_page_base && HasGoogleSearchQueryParam(url.query())); 227 (!is_home_page_base && HasGoogleSearchQueryParam(url.query()));
208 } 228 }
209 229
210 bool IsYoutubeDomainUrl(const GURL& url, 230 bool IsYoutubeDomainUrl(const GURL& url,
211 SubdomainPermission subdomain_permission, 231 SubdomainPermission subdomain_permission,
212 PortPermission port_permission) { 232 PortPermission port_permission) {
213 return IsValidURL(url, port_permission) && 233 return IsValidURL(url, port_permission) &&
214 IsValidHostName(url.host(), "youtube", subdomain_permission); 234 IsValidHostName(url.host(), "youtube", subdomain_permission);
215 } 235 }
216 236
237 GoogleSearchMetrics::AccessPoint GetGoogleSearchAccessPointForNavEntry(
238 const content::NavigationEntry& entry) {
239 DCHECK(google_util::IsGoogleSearchUrl(entry.GetURL()));
240
241 // If the commit is a GENERATED commit with a Google search URL, we know it's
242 // an Omnibox search.
Peter Kasting 2014/06/19 21:20:32 This comment goes into detail that isn't visible h
kmadhusu 2014/06/19 22:52:49 Inlined IsOmniboxGoogleSearchNavigation() definiti
243 if (IsOmniboxGoogleSearchNavigation(entry))
244 return GoogleSearchMetrics::AP_OMNIBOX;
245
246 // For all other cases that we have not yet implemented or care to measure,
247 // we log a generic "catch-all" metric.
248 return IsSearchAppGoogleSearchNavigation(entry) ?
249 GoogleSearchMetrics::AP_SEARCH_APP : GoogleSearchMetrics::AP_OTHER;
250 }
251
217 } // namespace google_util 252 } // namespace google_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698