Chromium Code Reviews| Index: chrome/browser/search/search.cc |
| diff --git a/chrome/browser/search/search.cc b/chrome/browser/search/search.cc |
| index 52165f97ba6cc72579a8638d46a338798fd75b0a..a3f79dd84c9225f470c80f0cc9e091e6a86f0715 100644 |
| --- a/chrome/browser/search/search.cc |
| +++ b/chrome/browser/search/search.cc |
| @@ -6,7 +6,6 @@ |
| #include "base/command_line.h" |
| #include "base/metrics/field_trial.h" |
| -#include "base/metrics/histogram.h" |
| #include "base/prefs/pref_service.h" |
| #include "base/rand_util.h" |
| #include "base/strings/string_number_conversions.h" |
| @@ -64,7 +63,7 @@ const char kShowNtpFlagName[] = "show_ntp"; |
| const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs"; |
| const char kUseCacheableNTP[] = "use_cacheable_ntp"; |
| const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; |
| -const char kSuppressInstantExtendedOnSRPFlagName[] = "suppress_on_srp"; |
| +const char kEnableQueryExtractionFlagName[] = "query_extraction"; |
| // Constants for the field trial name and group prefix. |
| // Note in M30 and below this field trial was named "InstantExtended" and in |
| @@ -81,9 +80,6 @@ const char kGroupNumberPrefix[] = "Group"; |
| // be ignored and Instant Extended will not be enabled by default. |
| const char kDisablingSuffix[] = "DISABLED"; |
| -// Remember if we reported metrics about opt-in/out state. |
| -bool instant_extended_opt_in_state_gate = false; |
| - |
| // Used to set the Instant support state of the Navigation entry. |
| const char kInstantSupportStateKey[] = "instant_support_state"; |
| @@ -155,22 +151,6 @@ bool MatchesAnySearchURL(const GURL& url, TemplateURL* template_url) { |
| return false; |
| } |
| -void RecordInstantExtendedOptInState() { |
| - if (instant_extended_opt_in_state_gate) |
| - return; |
| - |
| - instant_extended_opt_in_state_gate = true; |
| - OptInState state = INSTANT_EXTENDED_NOT_SET; |
| - const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| - if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) |
| - state = INSTANT_EXTENDED_OPT_OUT; |
| - else if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) |
| - state = INSTANT_EXTENDED_OPT_IN; |
| - |
| - UMA_HISTOGRAM_ENUMERATION("InstantExtended.NewOptInState", state, |
| - INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT); |
| -} |
| - |
| // Returns true if |contents| is rendered inside the Instant process for |
| // |profile|. |
| bool IsRenderedInInstantProcess(const content::WebContents* contents, |
| @@ -229,8 +209,7 @@ bool IsInstantURL(const GURL& url, Profile* profile) { |
| if (MatchesOriginAndPath(url, instant_url)) |
| return true; |
| - return !ShouldSuppressInstantExtendedOnSRP() && |
| - MatchesAnySearchURL(url, template_url); |
| + return IsQueryExtractionEnabled() && MatchesAnySearchURL(url, template_url); |
| } |
| string16 GetSearchTermsImpl(const content::WebContents* contents, |
| @@ -271,7 +250,6 @@ bool IsInstantExtendedAPIEnabled() { |
| #if defined(OS_IOS) || defined(OS_ANDROID) |
| return false; |
| #else |
| - RecordInstantExtendedOptInState(); |
| return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; |
|
David Black
2013/09/30 20:47:10
Do we actually want to retain the ability to turn
samarth
2013/10/02 00:18:00
Good point. I'd kept it in to give us the flexibi
|
| #endif // defined(OS_IOS) || defined(OS_ANDROID) |
| } |
| @@ -279,34 +257,34 @@ bool IsInstantExtendedAPIEnabled() { |
| // Determine what embedded search page version to request from the user's |
| // default search provider. If 0, the embedded search UI should not be enabled. |
| uint64 EmbeddedSearchPageVersion() { |
| - RecordInstantExtendedOptInState(); |
| - |
| - // Check the command-line/about:flags setting first, which should have |
| - // precedence and allows the trial to not be reported (if it's never queried). |
| - const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| - if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) |
| - return kEmbeddedPageVersionDisabled; |
| - if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { |
| - // The user has set the about:flags switch to Enabled - give the default |
| - // UI version. |
| - return kEmbeddedPageVersionDefault; |
| - } |
| - |
| FieldTrialFlags flags; |
| - uint64 group_num = 0; |
| - if (GetFieldTrialInfo(&flags, &group_num)) { |
| - if (group_num == 0) |
| - return kEmbeddedPageVersionDisabled; |
| + if (GetFieldTrialInfo(&flags)) { |
| return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, |
| kEmbeddedPageVersionDefault, |
| flags); |
| } |
| - return kEmbeddedPageVersionDisabled; |
| + return kEmbeddedPageVersionDefault; |
| } |
| bool IsQueryExtractionEnabled() { |
| - return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled && |
| - !ShouldSuppressInstantExtendedOnSRP(); |
| +#if defined(OS_IOS) || defined(OS_ANDROID) |
| + return true; |
| +#else |
| + if (!IsInstantExtendedAPIEnabled()) |
| + return false; |
| + |
| + const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(switches::kEnableQueryExtraction)) |
| + return true; |
| + |
| + FieldTrialFlags flags; |
| + if (GetFieldTrialInfo(&flags)) { |
| + return GetBoolValueForFlagWithDefault( |
| + kEnableQueryExtractionFlagName, false, flags); |
| + } |
| + |
| + return false; |
| +#endif // defined(OS_IOS) || defined(OS_ANDROID) |
| } |
| string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) { |
| @@ -438,18 +416,8 @@ GURL GetLocalInstantURL(Profile* profile) { |
| } |
| bool ShouldPreferRemoteNTPOnStartup() { |
| - // Check the command-line/about:flags setting first, which should have |
| - // precedence and allows the trial to not be reported (if it's never queried). |
| - const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| - if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || |
| - command_line->HasSwitch(switches::kEnableLocalFirstLoadNTP)) { |
| - return false; |
| - } |
| - if (command_line->HasSwitch(switches::kDisableLocalFirstLoadNTP)) |
| - return true; |
| - |
| FieldTrialFlags flags; |
| - if (GetFieldTrialInfo(&flags, NULL)) { |
| + if (GetFieldTrialInfo(&flags)) { |
| return GetBoolValueForFlagWithDefault(kUseRemoteNTPOnStartupFlagName, true, |
| flags); |
| } |
| @@ -458,7 +426,7 @@ bool ShouldPreferRemoteNTPOnStartup() { |
| bool ShouldHideTopVerbatimMatch() { |
| FieldTrialFlags flags; |
| - if (GetFieldTrialInfo(&flags, NULL)) { |
| + if (GetFieldTrialInfo(&flags)) { |
| return GetBoolValueForFlagWithDefault(kHideVerbatimFlagName, false, flags); |
| } |
| return false; |
| @@ -470,7 +438,7 @@ bool ShouldUseCacheableNTP() { |
| return true; |
| FieldTrialFlags flags; |
| - if (GetFieldTrialInfo(&flags, NULL)) { |
| + if (GetFieldTrialInfo(&flags)) { |
| return GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags); |
| } |
| return false; |
| @@ -483,7 +451,7 @@ bool ShouldShowInstantNTP() { |
| return false; |
| FieldTrialFlags flags; |
| - if (GetFieldTrialInfo(&flags, NULL)) { |
| + if (GetFieldTrialInfo(&flags)) { |
| return GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); |
| } |
| return true; |
| @@ -491,7 +459,7 @@ bool ShouldShowInstantNTP() { |
| bool ShouldShowRecentTabsOnNTP() { |
| FieldTrialFlags flags; |
| - if (GetFieldTrialInfo(&flags, NULL)) { |
| + if (GetFieldTrialInfo(&flags)) { |
| return GetBoolValueForFlagWithDefault( |
| kRecentTabsOnNTPFlagName, false, flags); |
| } |
| @@ -499,16 +467,6 @@ bool ShouldShowRecentTabsOnNTP() { |
| return false; |
| } |
| -bool ShouldSuppressInstantExtendedOnSRP() { |
| - FieldTrialFlags flags; |
| - if (GetFieldTrialInfo(&flags, NULL)) { |
| - return GetBoolValueForFlagWithDefault( |
| - kSuppressInstantExtendedOnSRPFlagName, false, flags); |
| - } |
| - |
| - return false; |
| -} |
| - |
| bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { |
| return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); |
| } |
| @@ -548,7 +506,7 @@ GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { |
| int GetInstantLoaderStalenessTimeoutSec() { |
| int timeout_sec = kStalePageTimeoutDefault; |
| FieldTrialFlags flags; |
| - if (GetFieldTrialInfo(&flags, NULL)) { |
| + if (GetFieldTrialInfo(&flags)) { |
| timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName, |
| kStalePageTimeoutDefault, |
| flags); |
| @@ -633,34 +591,20 @@ InstantSupportState GetInstantSupportStateFromNavigationEntry( |
| } |
| bool ShouldPrefetchSearchResultsOnSRP() { |
| - // Check the command-line/about:flags setting first, which should have |
| - // precedence and allows the trial to not be reported (if it's never queried). |
| - const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| - if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || |
| - command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { |
| - return false; |
| - } |
| - |
| FieldTrialFlags flags; |
| - if (GetFieldTrialInfo(&flags, NULL)) { |
| + if (GetFieldTrialInfo(&flags)) { |
| return GetBoolValueForFlagWithDefault(kPrefetchSearchResultsOnSRP, false, |
| flags); |
| } |
| return false; |
| } |
| -void EnableInstantExtendedAPIForTesting() { |
| - CommandLine* cl = CommandLine::ForCurrentProcess(); |
| - cl->AppendSwitch(switches::kEnableInstantExtendedAPI); |
| -} |
| - |
| -void DisableInstantExtendedAPIForTesting() { |
| +void EnableQueryExtractionForTesting() { |
| CommandLine* cl = CommandLine::ForCurrentProcess(); |
| - cl->AppendSwitch(switches::kDisableInstantExtendedAPI); |
| + cl->AppendSwitch(switches::kEnableQueryExtraction); |
| } |
| -bool GetFieldTrialInfo(FieldTrialFlags* flags, |
| - uint64* group_number) { |
| +bool GetFieldTrialInfo(FieldTrialFlags* flags) { |
| // Get the group name. If the EmbeddedSearch trial doesn't exist, look for |
| // the older InstantExtended name. |
| std::string group_name = base::FieldTrialList::FindFullName( |
| @@ -673,10 +617,8 @@ bool GetFieldTrialInfo(FieldTrialFlags* flags, |
| if (EndsWith(group_name, kDisablingSuffix, true)) |
| return false; |
| - // We have a valid trial that isn't disabled. |
| - // First extract the flags. |
| + // We have a valid trial that isn't disabled. Extract the flags. |
| std::string group_prefix(group_name); |
| - |
| size_t first_space = group_name.find(" "); |
| if (first_space != std::string::npos) { |
| // There is a flags section of the group name. Split that out and parse it. |
| @@ -689,20 +631,6 @@ bool GetFieldTrialInfo(FieldTrialFlags* flags, |
| } |
| } |
| - // Now extract the group number, making sure we get a non-zero value. |
| - uint64 temp_group_number = 0; |
| - if (StartsWithASCII(group_name, kGroupNumberPrefix, true)) { |
| - std::string group_suffix = group_prefix.substr(strlen(kGroupNumberPrefix)); |
| - if (!base::StringToUint64(group_suffix, &temp_group_number)) |
| - return false; |
| - if (group_number) |
| - *group_number = temp_group_number; |
| - } else { |
| - // Instant Extended is not enabled. |
| - if (group_number) |
| - *group_number = 0; |
| - } |
| - |
| return true; |
| } |
| @@ -755,8 +683,4 @@ GURL GetNewTabPageURL(Profile* profile) { |
| kDisableStartMargin, false); |
| } |
| -void ResetInstantExtendedOptInStateGateForTest() { |
| - instant_extended_opt_in_state_gate = false; |
| -} |
| - |
| } // namespace chrome |