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

Side by Side Diff: chrome/browser/search/search.cc

Issue 150033002: NTP: add histogram to track New Tab page URL status. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 6 years, 10 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/search/search.h" 5 #include "chrome/browser/search/search.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram.h"
9 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/google/google_util.h" 15 #include "chrome/browser/google/google_util.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/search/instant_service.h" 18 #include "chrome/browser/search/instant_service.h"
18 #include "chrome/browser/search/instant_service_factory.h" 19 #include "chrome/browser/search/instant_service_factory.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Dev & Canary, for now the code accepts both names. 80 // Dev & Canary, for now the code accepts both names.
80 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta 81 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta
81 // channel. 82 // channel.
82 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; 83 const char kInstantExtendedFieldTrialName[] = "InstantExtended";
83 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch"; 84 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch";
84 85
85 // If the field trial's group name ends with this string its configuration will 86 // If the field trial's group name ends with this string its configuration will
86 // be ignored and Instant Extended will not be enabled by default. 87 // be ignored and Instant Extended will not be enabled by default.
87 const char kDisablingSuffix[] = "DISABLED"; 88 const char kDisablingSuffix[] = "DISABLED";
88 89
90 // Reasons for falling back to the local NTP instead of using a valid search
91 // provider's URL. Used in a UMA histogram so values should only be added at the
92 // end and not reordered.
93 // (Keep in sync with InstantExtended_LocalNTPFallbackReason.)
94 enum LocalNTPFallbackReason {
95 LOCAL_NTP_FALLBACK_INSECURE_URL = 1,
96 LOCAL_NTP_FALLBACK_SUGGEST_OFF = 2,
97 LOCAL_NTP_FALLBACK_BLOCKED_URL = 3,
98 LOCAL_NTP_FALLBACK_MAX
99 };
100
89 // Used to set the Instant support state of the Navigation entry. 101 // Used to set the Instant support state of the Navigation entry.
90 const char kInstantSupportStateKey[] = "instant_support_state"; 102 const char kInstantSupportStateKey[] = "instant_support_state";
91 103
92 const char kInstantSupportEnabled[] = "Instant support enabled"; 104 const char kInstantSupportEnabled[] = "Instant support enabled";
93 const char kInstantSupportDisabled[] = "Instant support disabled"; 105 const char kInstantSupportDisabled[] = "Instant support disabled";
94 const char kInstantSupportUnknown[] = "Instant support unknown"; 106 const char kInstantSupportUnknown[] = "Instant support unknown";
95 107
96 InstantSupportState StringToInstantSupportState(const base::string16& value) { 108 InstantSupportState StringToInstantSupportState(const base::string16& value) {
97 if (value == base::ASCIIToUTF16(kInstantSupportEnabled)) 109 if (value == base::ASCIIToUTF16(kInstantSupportEnabled))
98 return INSTANT_SUPPORT_YES; 110 return INSTANT_SUPPORT_YES;
99 else if (value == base::ASCIIToUTF16(kInstantSupportDisabled)) 111 else if (value == base::ASCIIToUTF16(kInstantSupportDisabled))
100 return INSTANT_SUPPORT_NO; 112 return INSTANT_SUPPORT_NO;
101 else 113 else
102 return INSTANT_SUPPORT_UNKNOWN; 114 return INSTANT_SUPPORT_UNKNOWN;
103 } 115 }
104 116
105 base::string16 InstantSupportStateToString(InstantSupportState state) { 117 base::string16 InstantSupportStateToString(InstantSupportState state) {
106 switch (state) { 118 switch (state) {
107 case INSTANT_SUPPORT_NO: 119 case INSTANT_SUPPORT_NO:
108 return base::ASCIIToUTF16(kInstantSupportDisabled); 120 return base::ASCIIToUTF16(kInstantSupportDisabled);
109 case INSTANT_SUPPORT_YES: 121 case INSTANT_SUPPORT_YES:
110 return base::ASCIIToUTF16(kInstantSupportEnabled); 122 return base::ASCIIToUTF16(kInstantSupportEnabled);
111 case INSTANT_SUPPORT_UNKNOWN: 123 case INSTANT_SUPPORT_UNKNOWN:
112 return base::ASCIIToUTF16(kInstantSupportUnknown); 124 return base::ASCIIToUTF16(kInstantSupportUnknown);
113 } 125 }
114 return base::ASCIIToUTF16(kInstantSupportUnknown); 126 return base::ASCIIToUTF16(kInstantSupportUnknown);
115 } 127 }
116 128
129 void RecordLocalNTPFallbackReason(LocalNTPFallbackReason reason) {
130 UMA_HISTOGRAM_ENUMERATION("InstantExtended.LocalNTPFallbackReason",
131 reason,
132 LOCAL_NTP_FALLBACK_MAX);
133 }
134
117 TemplateURL* GetDefaultSearchProviderTemplateURL(Profile* profile) { 135 TemplateURL* GetDefaultSearchProviderTemplateURL(Profile* profile) {
118 TemplateURLService* template_url_service = 136 TemplateURLService* template_url_service =
119 TemplateURLServiceFactory::GetForProfile(profile); 137 TemplateURLServiceFactory::GetForProfile(profile);
120 if (template_url_service) 138 if (template_url_service)
121 return template_url_service->GetDefaultSearchProvider(); 139 return template_url_service->GetDefaultSearchProvider();
122 return NULL; 140 return NULL;
123 } 141 }
124 142
125 GURL TemplateURLRefToGURL(const TemplateURLRef& ref, 143 GURL TemplateURLRefToGURL(const TemplateURLRef& ref,
126 int start_margin, 144 int start_margin,
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 result.push_back(TemplateURLRefToGURL(ref, kDisableStartMargin, false, 465 result.push_back(TemplateURLRefToGURL(ref, kDisableStartMargin, false,
448 false)); 466 false));
449 } 467 }
450 return result; 468 return result;
451 } 469 }
452 470
453 GURL GetNewTabPageURL(Profile* profile) { 471 GURL GetNewTabPageURL(Profile* profile) {
454 if (!profile || profile->IsOffTheRecord()) 472 if (!profile || profile->IsOffTheRecord())
455 return GURL(); 473 return GURL();
456 474
457 if (!IsSuggestPrefEnabled(profile))
458 return GURL(chrome::kChromeSearchLocalNtpUrl);
459
460 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); 475 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
461 if (!template_url) 476 if (!template_url)
462 return GURL(chrome::kChromeSearchLocalNtpUrl); 477 return GURL(chrome::kChromeSearchLocalNtpUrl);
Jered 2014/01/30 17:13:12 How about adding another bucket, BAD_URL, to measu
samarth 2014/01/31 16:05:20 Done.
463 478
464 GURL url(TemplateURLRefToGURL(template_url->new_tab_url_ref(), 479 GURL url(TemplateURLRefToGURL(template_url->new_tab_url_ref(),
465 kDisableStartMargin, false, false)); 480 kDisableStartMargin, false, false));
466 if (!url.is_valid() || !url.SchemeIsSecure()) 481 if (!url.is_valid())
467 return GURL(chrome::kChromeSearchLocalNtpUrl); 482 return GURL(chrome::kChromeSearchLocalNtpUrl);
468 483
469 if (!IsURLAllowedForSupervisedUser(url, profile)) 484 if (!url.SchemeIsSecure()) {
Jered 2014/01/30 17:13:12 If you add a bucket NONE, then we can normalize as
samarth 2014/01/31 16:05:20 I ended up redoing this code to make it simpler an
485 RecordLocalNTPFallbackReason(LOCAL_NTP_FALLBACK_INSECURE_URL);
470 return GURL(chrome::kChromeSearchLocalNtpUrl); 486 return GURL(chrome::kChromeSearchLocalNtpUrl);
487 }
488
489 if (!IsSuggestPrefEnabled(profile)) {
490 RecordLocalNTPFallbackReason(LOCAL_NTP_FALLBACK_SUGGEST_OFF);
491 return GURL(chrome::kChromeSearchLocalNtpUrl);
492 }
493
494 if (!IsURLAllowedForSupervisedUser(url, profile)) {
495 RecordLocalNTPFallbackReason(LOCAL_NTP_FALLBACK_BLOCKED_URL);
496 return GURL(chrome::kChromeSearchLocalNtpUrl);
497 }
471 498
472 return url; 499 return url;
473 } 500 }
474 501
475 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { 502 GURL GetSearchResultPrefetchBaseURL(Profile* profile) {
476 return ShouldPrefetchSearchResults() ? 503 return ShouldPrefetchSearchResults() ?
477 GetInstantURL(profile, kDisableStartMargin, true) : GURL(); 504 GetInstantURL(profile, kDisableStartMargin, true) : GURL();
478 } 505 }
479 506
480 bool ShouldPrefetchSearchResults() { 507 bool ShouldPrefetchSearchResults() {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 730
704 // Given a FieldTrialFlags object, returns the boolean value of the provided 731 // Given a FieldTrialFlags object, returns the boolean value of the provided
705 // flag. 732 // flag.
706 bool GetBoolValueForFlagWithDefault(const std::string& flag, 733 bool GetBoolValueForFlagWithDefault(const std::string& flag,
707 bool default_value, 734 bool default_value,
708 const FieldTrialFlags& flags) { 735 const FieldTrialFlags& flags) {
709 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); 736 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags);
710 } 737 }
711 738
712 } // namespace chrome 739 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698