OLD | NEW |
---|---|
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 Loading... | |
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. | |
Alexei Svitkine (slow)
2014/01/30 15:19:24
Mention that this is used in an UMA macro, so new
samarth
2014/01/30 16:45:29
Done.
| |
92 enum LocalNTPFallbackReason { | |
93 LOCAL_NTP_FALLBACK_INSECURE_URL = 1, | |
94 LOCAL_NTP_FALLBACK_SUGGEST_OFF = 2, | |
95 LOCAL_NTP_FALLBACK_BLOCKED_URL = 3, | |
96 LOCAL_NTP_FALLBACK_MAX = 4 | |
Alexei Svitkine (slow)
2014/01/30 15:19:24
Maybe better to remove the = 4 here, so that it au
samarth
2014/01/30 16:45:29
Done.
| |
97 }; | |
98 | |
89 // Used to set the Instant support state of the Navigation entry. | 99 // Used to set the Instant support state of the Navigation entry. |
90 const char kInstantSupportStateKey[] = "instant_support_state"; | 100 const char kInstantSupportStateKey[] = "instant_support_state"; |
91 | 101 |
92 const char kInstantSupportEnabled[] = "Instant support enabled"; | 102 const char kInstantSupportEnabled[] = "Instant support enabled"; |
93 const char kInstantSupportDisabled[] = "Instant support disabled"; | 103 const char kInstantSupportDisabled[] = "Instant support disabled"; |
94 const char kInstantSupportUnknown[] = "Instant support unknown"; | 104 const char kInstantSupportUnknown[] = "Instant support unknown"; |
95 | 105 |
96 InstantSupportState StringToInstantSupportState(const base::string16& value) { | 106 InstantSupportState StringToInstantSupportState(const base::string16& value) { |
97 if (value == base::ASCIIToUTF16(kInstantSupportEnabled)) | 107 if (value == base::ASCIIToUTF16(kInstantSupportEnabled)) |
98 return INSTANT_SUPPORT_YES; | 108 return INSTANT_SUPPORT_YES; |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 result.push_back(TemplateURLRefToGURL(ref, kDisableStartMargin, false, | 457 result.push_back(TemplateURLRefToGURL(ref, kDisableStartMargin, false, |
448 false)); | 458 false)); |
449 } | 459 } |
450 return result; | 460 return result; |
451 } | 461 } |
452 | 462 |
453 GURL GetNewTabPageURL(Profile* profile) { | 463 GURL GetNewTabPageURL(Profile* profile) { |
454 if (!profile || profile->IsOffTheRecord()) | 464 if (!profile || profile->IsOffTheRecord()) |
455 return GURL(); | 465 return GURL(); |
456 | 466 |
457 if (!IsSuggestPrefEnabled(profile)) | |
458 return GURL(chrome::kChromeSearchLocalNtpUrl); | |
459 | |
460 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 467 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); |
461 if (!template_url) | 468 if (!template_url) |
462 return GURL(chrome::kChromeSearchLocalNtpUrl); | 469 return GURL(chrome::kChromeSearchLocalNtpUrl); |
463 | 470 |
464 GURL url(TemplateURLRefToGURL(template_url->new_tab_url_ref(), | 471 GURL url(TemplateURLRefToGURL(template_url->new_tab_url_ref(), |
465 kDisableStartMargin, false, false)); | 472 kDisableStartMargin, false, false)); |
466 if (!url.is_valid() || !url.SchemeIsSecure()) | 473 if (!url.is_valid()) |
467 return GURL(chrome::kChromeSearchLocalNtpUrl); | 474 return GURL(chrome::kChromeSearchLocalNtpUrl); |
468 | 475 |
469 if (!IsURLAllowedForSupervisedUser(url, profile)) | 476 if (!url.SchemeIsSecure()) { |
477 UMA_HISTOGRAM_ENUMERATION("InstantExtended.LocalNTPFallbackReason", | |
Alexei Svitkine (slow)
2014/01/30 15:19:24
Can you make a small helper function in the anon n
samarth
2014/01/30 16:45:29
Done.
| |
478 LOCAL_NTP_FALLBACK_INSECURE_URL, | |
479 LOCAL_NTP_FALLBACK_MAX); | |
470 return GURL(chrome::kChromeSearchLocalNtpUrl); | 480 return GURL(chrome::kChromeSearchLocalNtpUrl); |
481 } | |
482 | |
483 if (!IsSuggestPrefEnabled(profile)) { | |
484 UMA_HISTOGRAM_ENUMERATION("InstantExtended.LocalNTPFallbackReason", | |
485 LOCAL_NTP_FALLBACK_SUGGEST_OFF, | |
486 LOCAL_NTP_FALLBACK_MAX); | |
487 return GURL(chrome::kChromeSearchLocalNtpUrl); | |
488 } | |
489 | |
490 if (!IsURLAllowedForSupervisedUser(url, profile)) { | |
491 UMA_HISTOGRAM_ENUMERATION("InstantExtended.LocalNTPFallbackReason", | |
492 LOCAL_NTP_FALLBACK_BLOCKED_URL, | |
493 LOCAL_NTP_FALLBACK_MAX); | |
494 return GURL(chrome::kChromeSearchLocalNtpUrl); | |
495 } | |
471 | 496 |
472 return url; | 497 return url; |
473 } | 498 } |
474 | 499 |
475 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { | 500 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { |
476 return ShouldPrefetchSearchResults() ? | 501 return ShouldPrefetchSearchResults() ? |
477 GetInstantURL(profile, kDisableStartMargin, true) : GURL(); | 502 GetInstantURL(profile, kDisableStartMargin, true) : GURL(); |
478 } | 503 } |
479 | 504 |
480 bool ShouldPrefetchSearchResults() { | 505 bool ShouldPrefetchSearchResults() { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 | 728 |
704 // Given a FieldTrialFlags object, returns the boolean value of the provided | 729 // Given a FieldTrialFlags object, returns the boolean value of the provided |
705 // flag. | 730 // flag. |
706 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 731 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
707 bool default_value, | 732 bool default_value, |
708 const FieldTrialFlags& flags) { | 733 const FieldTrialFlags& flags) { |
709 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 734 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
710 } | 735 } |
711 | 736 |
712 } // namespace chrome | 737 } // namespace chrome |
OLD | NEW |