diff options
author | sreeram@chromium.org <sreeram@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-25 16:35:32 +0000 |
---|---|---|
committer | sreeram@chromium.org <sreeram@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-25 16:35:32 +0000 |
commit | 1499b7dd537a002bcda757cc795e92f865fa9af7 (patch) | |
tree | 849194072ff3b8e01770aec9054fe07401d95fe8 /chrome/browser/instant | |
parent | 19e15b1833ce965710b5f82822ec1708b60c949e (diff) | |
download | chromium_src-1499b7dd537a002bcda757cc795e92f865fa9af7.zip chromium_src-1499b7dd537a002bcda757cc795e92f865fa9af7.tar.gz chromium_src-1499b7dd537a002bcda757cc795e92f865fa9af7.tar.bz2 |
Remove Instant field trials.
This unlaunches the SILENT mode, but only for a little while. After the
rest of the refactoring is done, I'll put back the SILENT mode, along
with appropriate browser tests for all modes.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10453011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139057 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/instant')
-rw-r--r-- | chrome/browser/instant/OWNERS | 1 | ||||
-rw-r--r-- | chrome/browser/instant/instant_browsertest.cc | 179 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 91 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.h | 22 | ||||
-rw-r--r-- | chrome/browser/instant/instant_field_trial.cc | 121 | ||||
-rw-r--r-- | chrome/browser/instant/instant_field_trial.h | 56 |
6 files changed, 47 insertions, 423 deletions
diff --git a/chrome/browser/instant/OWNERS b/chrome/browser/instant/OWNERS index 90b3e80..20df7d8 100644 --- a/chrome/browser/instant/OWNERS +++ b/chrome/browser/instant/OWNERS @@ -1 +1,2 @@ sky@chromium.org +sreeram@chromium.org diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index 16104e2..960d116 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -54,8 +54,6 @@ class InstantTest : public InProcessBrowserTest { } void EnableInstant() { - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kInstantFieldTrial, switches::kInstantFieldTrialInstant); InstantController::Enable(browser()->profile()); } @@ -835,180 +833,3 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(TaskManagerPrefix)) { string16 title = task_manager->GetResourceTitle(2); EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; } - -// Tests the INSTANT experiment of the field trial. -class InstantFieldTrialInstantTest : public InstantTest { - public: - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - command_line->AppendSwitchASCII(switches::kInstantFieldTrial, - switches::kInstantFieldTrialInstant); - } -}; - -// Tests that instant is active, even without calling EnableInstant(). -IN_PROC_BROWSER_TEST_F(InstantFieldTrialInstantTest, MAYBE(ExperimentEnabled)) { - // Check that instant is enabled, despite not setting the preference. - Profile* profile = browser()->profile(); - EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)); - EXPECT_TRUE(InstantController::IsEnabled(profile)); - - ASSERT_TRUE(test_server()->Start()); - SetupInstantProvider("instant.html"); - DetermineInstantSupport(); - SearchAndWaitForPreviewToShow(); - - // Check that instant is active and showing a preview. - EXPECT_TRUE(preview()); - EXPECT_TRUE(loader()->ready()); - EXPECT_TRUE(instant()->is_displayable()); - EXPECT_TRUE(instant()->IsCurrent()); - - // Check that the suggested text has been set in the omnibox. - EXPECT_EQ("defghi", GetSuggestion()); - EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); - - // Press <Enter> in the omnibox, causing the preview to be committed. - WebContents* preview_tab = preview()->web_contents(); - ASSERT_TRUE(PressEnter()); - - // The preview contents should now be the active tab contents. - EXPECT_FALSE(preview()); - EXPECT_FALSE(instant()->is_displayable()); - EXPECT_FALSE(instant()->IsCurrent()); - EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents()); -} - -// Tests the HIDDEN experiment of the field trial. -class InstantFieldTrialHiddenTest : public InstantTest { - public: - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - command_line->AppendSwitchASCII(switches::kInstantFieldTrial, - switches::kInstantFieldTrialHidden); - } -}; - -// Tests that instant is active, even without calling EnableInstant(). -IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE(ExperimentEnabled)) { - // Check that instant is enabled, despite not setting the preference. - Profile* profile = browser()->profile(); - EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)); - EXPECT_TRUE(InstantController::IsEnabled(profile)); - - ASSERT_TRUE(test_server()->Start()); - SetupInstantProvider("instant.html"); - DetermineInstantSupport(); - - // Type into the omnibox, but don't press <Enter> yet. - omnibox()->SetUserText(ASCIIToUTF16("def")); - ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer()); - - // Check that instant is active, but the preview is not showing. - EXPECT_TRUE(preview()); - EXPECT_TRUE(loader()->ready()); - EXPECT_FALSE(instant()->is_displayable()); - EXPECT_FALSE(instant()->IsCurrent()); - - // Check that the suggested text hasn't actually been set in the omnibox. - EXPECT_EQ("defghi", GetSuggestion()); - EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText())); - - // Press <Enter> in the omnibox, causing the preview to be committed. - WebContents* preview_tab = preview()->web_contents(); - ASSERT_TRUE(PressEnter()); - - // The preview contents should now be the active tab contents. - EXPECT_FALSE(preview()); - EXPECT_FALSE(instant()->is_displayable()); - EXPECT_FALSE(instant()->IsCurrent()); - EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents()); -} - -// Tests the SILENT experiment of the field trial. -class InstantFieldTrialSilentTest : public InstantTest { - public: - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - command_line->AppendSwitchASCII(switches::kInstantFieldTrial, - switches::kInstantFieldTrialSilent); - } -}; - -// Tests that instant is active, even without calling EnableInstant(). -IN_PROC_BROWSER_TEST_F(InstantFieldTrialSilentTest, MAYBE(ExperimentEnabled)) { - // Check that instant is enabled, despite not setting the preference. - Profile* profile = browser()->profile(); - EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)); - EXPECT_TRUE(InstantController::IsEnabled(profile)); - - ASSERT_TRUE(test_server()->Start()); - SetupInstantProvider("instant.html"); - DetermineInstantSupport(); - - // Type into the omnibox, but don't press <Enter> yet. - omnibox()->SetUserText(ASCIIToUTF16("def")); - ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer()); - - // Check that instant is active, but the preview is not showing. - EXPECT_TRUE(preview()); - EXPECT_FALSE(loader()->ready()); - EXPECT_FALSE(instant()->is_displayable()); - EXPECT_FALSE(instant()->IsCurrent()); - - // There are no suggestions, as the loader hasn't seen the query yet. - EXPECT_EQ("", GetSuggestion()); - EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText())); - - // Press <Enter> in the omnibox, causing the preview to be committed. - WebContents* preview_tab = preview()->web_contents(); - ASSERT_TRUE(PressEnter()); - - // The preview contents should now be the active tab contents. - EXPECT_FALSE(preview()); - EXPECT_FALSE(instant()->is_displayable()); - EXPECT_FALSE(instant()->IsCurrent()); - EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents()); -} - -// Tests the SUGGEST experiment of the field trial. -class InstantFieldTrialSuggestTest : public InstantTest { - public: - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - command_line->AppendSwitchASCII(switches::kInstantFieldTrial, - switches::kInstantFieldTrialSuggest); - } -}; - -// Tests that instant is active, even without calling EnableInstant(). -IN_PROC_BROWSER_TEST_F(InstantFieldTrialSuggestTest, MAYBE(ExperimentEnabled)) { - // Check that instant is enabled, despite not setting the preference. - Profile* profile = browser()->profile(); - EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)); - EXPECT_TRUE(InstantController::IsEnabled(profile)); - - ASSERT_TRUE(test_server()->Start()); - SetupInstantProvider("instant.html"); - DetermineInstantSupport(); - - // Type into the omnibox, but don't press <Enter> yet. - omnibox()->SetUserText(ASCIIToUTF16("def")); - ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer()); - - // Check that instant is active, but the preview is not showing. - EXPECT_TRUE(preview()); - EXPECT_TRUE(loader()->ready()); - EXPECT_FALSE(instant()->is_displayable()); - EXPECT_FALSE(instant()->IsCurrent()); - - // Check that the suggested text has actually been set in the omnibox. - EXPECT_EQ("defghi", GetSuggestion()); - EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); - - // Press <Enter> in the omnibox, causing the preview to be committed. - WebContents* preview_tab = preview()->web_contents(); - ASSERT_TRUE(PressEnter()); - - // The preview contents should now be the active tab contents. - EXPECT_FALSE(preview()); - EXPECT_FALSE(instant()->is_displayable()); - EXPECT_FALSE(instant()->IsCurrent()); - EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents()); -} diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index b6de819c..d93ed1b0 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -8,11 +8,9 @@ #include "base/command_line.h" #include "base/message_loop.h" #include "base/metrics/histogram.h" -#include "base/rand_util.h" #include "build/build_config.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/instant/instant_delegate.h" -#include "chrome/browser/instant/instant_field_trial.h" #include "chrome/browser/instant/instant_loader.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/prefs/pref_service.h" @@ -36,7 +34,8 @@ #endif InstantController::InstantController(Profile* profile, - InstantDelegate* delegate) + InstantDelegate* delegate, + Mode mode) : delegate_(delegate), template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)), tab_contents_(NULL), @@ -44,14 +43,11 @@ InstantController::InstantController(Profile* profile, is_out_of_date_(true), commit_on_mouse_up_(false), last_transition_type_(content::PAGE_TRANSITION_LINK), - ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), + mode_(mode) { DCHECK(template_url_service_); - PrefService* prefs = profile->GetPrefs(); - if (prefs && prefs->GetBoolean(prefs::kInstantEnabled)) { - // kInstantEnabledOnce was added after Instant, set it now to make sure it - // is correctly set. - prefs->SetBoolean(prefs::kInstantEnabledOnce, true); - } + DCHECK(mode_ == INSTANT || mode_ == SUGGEST || mode_ == HIDDEN || + mode_ == SILENT); } InstantController::~InstantController() { @@ -65,9 +61,6 @@ void InstantController::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kInstantEnabled, false, PrefService::SYNCABLE_PREF); - prefs->RegisterBooleanPref(prefs::kInstantEnabledOnce, - false, - PrefService::SYNCABLE_PREF); } // static @@ -77,7 +70,8 @@ void InstantController::RecordMetrics(Profile* profile) { // static bool InstantController::IsEnabled(Profile* profile) { - return InstantFieldTrial::GetMode(profile) != InstantFieldTrial::CONTROL; + const PrefService* prefs = profile ? profile->GetPrefs() : 0; + return prefs && prefs->GetBoolean(prefs::kInstantEnabled); } // static @@ -86,14 +80,9 @@ void InstantController::Enable(Profile* profile) { if (!service) return; - base::Histogram* histogram = base::LinearHistogram::FactoryGet( - "Instant.Preference" + InstantFieldTrial::GetModeAsString(profile), - 1, 2, 3, base::Histogram::kUmaTargetedHistogramFlag); - histogram->Add(1); - - service->SetBoolean(prefs::kInstantEnabledOnce, true); service->SetBoolean(prefs::kInstantEnabled, true); service->SetBoolean(prefs::kInstantConfirmDialogShown, true); + UMA_HISTOGRAM_ENUMERATION("Instant.Preference", 1, 2); } // static @@ -102,13 +91,8 @@ void InstantController::Disable(Profile* profile) { if (!service || !IsEnabled(profile)) return; - base::Histogram* histogram = base::LinearHistogram::FactoryGet( - "Instant.Preference" + InstantFieldTrial::GetModeAsString(profile), - 1, 2, 3, base::Histogram::kUmaTargetedHistogramFlag); - histogram->Add(0); - - service->SetBoolean(prefs::kInstantEnabledOnce, true); service->SetBoolean(prefs::kInstantEnabled, false); + UMA_HISTOGRAM_ENUMERATION("Instant.Preference", 0, 2); } // static @@ -143,17 +127,14 @@ bool InstantController::Update(TabContentsWrapper* tab_contents, return false; } - if (!loader_.get()) { - loader_.reset(new InstantLoader(this, template_url->id(), - InstantFieldTrial::GetModeAsString(tab_contents->profile()))); - } + if (!loader_.get()) + loader_.reset(new InstantLoader(this, template_url->id(), std::string())); - // In some rare cases (involving group policy), Instant can go from the field - // trial to normal mode, with no intervening call to DestroyPreviewContents(). + // In some rare cases (involving group policy), Instant can go from a hidden + // mode to normal mode, with no intervening call to DestroyPreviewContents(). // This would leave the loader in a weird state, which would manifest if the // user pressed <Enter> without calling Update(). TODO(sreeram): Handle it. - if (InstantFieldTrial::GetMode(tab_contents->profile()) == - InstantFieldTrial::SILENT) { + if (mode_ == SILENT) { // For the SILENT mode, we process |user_text| at commit time, which means // we're never really out of date. is_out_of_date_ = false; @@ -179,11 +160,8 @@ void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { // bounds are in sync. omnibox_bounds_ = bounds; - if (loader_.get() && !is_out_of_date_ && - InstantFieldTrial::GetMode(tab_contents_->profile()) == - InstantFieldTrial::INSTANT) { + if (loader_.get() && !is_out_of_date_ && mode_ == INSTANT) loader_->SetOmniboxBounds(bounds); - } } void InstantController::DestroyPreviewContents() { @@ -218,11 +196,8 @@ bool InstantController::PrepareForCommit() { if (is_out_of_date_ || !loader_.get()) return false; - const InstantFieldTrial::Mode mode = - InstantFieldTrial::GetMode(tab_contents_->profile()); - // If we are in the visible (INSTANT) mode, return the status of the preview. - if (mode == InstantFieldTrial::INSTANT) + if (mode_ == INSTANT) return IsCurrent(); const TemplateURL* template_url = @@ -236,7 +211,7 @@ bool InstantController::PrepareForCommit() { // In the SUGGEST and HIDDEN modes, we must have sent an Update() by now, so // check if the loader failed to process it. - if ((mode == InstantFieldTrial::SUGGEST || mode == InstantFieldTrial::HIDDEN) + if ((mode_ == SUGGEST || mode_ == HIDDEN) && (!loader_->ready() || !loader_->http_status_ok())) { return false; } @@ -359,10 +334,8 @@ void InstantController::OnAutocompleteGotFocus( tab_contents_ = tab_contents; - if (!loader_.get()) { - loader_.reset(new InstantLoader(this, template_url->id(), - InstantFieldTrial::GetModeAsString(tab_contents->profile()))); - } + if (!loader_.get()) + loader_.reset(new InstantLoader(this, template_url->id(), std::string())); loader_->MaybeLoadInstantURL(tab_contents, template_url); } @@ -402,9 +375,7 @@ void InstantController::SetSuggestedTextFor( if (is_out_of_date_) return; - const InstantFieldTrial::Mode mode = - InstantFieldTrial::GetMode(tab_contents_->profile()); - if (mode == InstantFieldTrial::INSTANT || mode == InstantFieldTrial::SUGGEST) + if (mode_ == INSTANT || mode_ == SUGGEST) delegate_->SetSuggestedText(text, behavior); } @@ -449,24 +420,16 @@ void InstantController::InstantLoaderContentsFocused() { #if defined(USE_AURA) // On aura the omnibox only receives a focus lost if we initiate the focus // change. This does that. - if (InstantFieldTrial::GetMode(tab_contents_->profile()) == - InstantFieldTrial::INSTANT) { + if (mode_ == INSTANT) delegate_->InstantPreviewFocused(); - } #endif } void InstantController::UpdateIsDisplayable() { - if (!is_out_of_date_ && - InstantFieldTrial::GetMode(tab_contents_->profile()) != - InstantFieldTrial::INSTANT) { - return; - } - bool displayable = (!is_out_of_date_ && loader_.get() && loader_->ready() && loader_->http_status_ok()); - if (displayable == is_displayable_) + if (displayable == is_displayable_ || mode_ != INSTANT) return; is_displayable_ = displayable; @@ -488,15 +451,13 @@ void InstantController::UpdateLoader(const TemplateURL* template_url, bool verbatim, string16* suggested_text) { is_out_of_date_ = false; - const InstantFieldTrial::Mode mode = - InstantFieldTrial::GetMode(tab_contents_->profile()); - if (mode == InstantFieldTrial::INSTANT) + if (mode_ == INSTANT) loader_->SetOmniboxBounds(omnibox_bounds_); loader_->Update(tab_contents_, template_url, url, transition_type, user_text, verbatim, suggested_text); UpdateIsDisplayable(); - // For the HIDDEN and SILENT field trials, don't send back suggestions. - if (mode == InstantFieldTrial::HIDDEN || mode == InstantFieldTrial::SILENT) + // For the HIDDEN and SILENT modes, don't send back suggestions. + if (mode_ == HIDDEN || mode_ == SILENT) suggested_text->clear(); } diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index 97c4b06..3c461d1 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -48,7 +48,22 @@ class InstantController : public InstantLoaderDelegate { // Duration of the instant animation in which the colors change. static const int kAutoCommitFadeInTimeMS = 300; - InstantController(Profile* profile, InstantDelegate* delegate); + // InstantController may operate in one of these modes: + // INSTANT: The default search engine is preloaded when the omnibox gets + // focus. Queries are issued as the user types. Predicted queries are + // are inline autocompleted into the omnibox. Result previews are shown. + // SUGGEST: Same as INSTANT, without visible previews. + // HIDDEN: Same as SUGGEST, without the inline autocompletion. + // SILENT: Same as HIDDEN, without issuing queries as the user types. The + // query is sent only after the user presses <Enter>. + enum Mode { + INSTANT, + SUGGEST, + HIDDEN, + SILENT + }; + + InstantController(Profile* profile, InstantDelegate* delegate, Mode mode); virtual ~InstantController(); // Registers instant related preferences. @@ -57,7 +72,7 @@ class InstantController : public InstantLoaderDelegate { // Records instant metrics. static void RecordMetrics(Profile* profile); - // Returns true if instant is enabled. + // Returns true if instant is enabled in the given |profile|'s preferences. static bool IsEnabled(Profile* profile); // Enables instant. @@ -264,6 +279,9 @@ class InstantController : public InstantLoaderDelegate { // The most recent user_text passed to |Update|. string16 last_user_text_; + // See the enum description above. + const Mode mode_; + DISALLOW_COPY_AND_ASSIGN(InstantController); }; diff --git a/chrome/browser/instant/instant_field_trial.cc b/chrome/browser/instant/instant_field_trial.cc deleted file mode 100644 index 2540c1b..0000000 --- a/chrome/browser/instant/instant_field_trial.cc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/instant/instant_field_trial.h" - -#include "base/command_line.h" -#include "base/metrics/field_trial.h" -#include "chrome/browser/metrics/metrics_service.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/metrics/experiments_helper.h" -#include "chrome/common/metrics/variation_ids.h" -#include "chrome/common/pref_names.h" - -namespace { - -// IDs of the field trial groups. Though they are not literally "const", they -// are set only once, in Activate() below. -int g_instant = 0; -int g_suggest = 0; -int g_hidden = 0; -int g_silent = 0; -int g_control = 0; - -} - -// static -void InstantFieldTrial::Activate() { - scoped_refptr<base::FieldTrial> trial( - base::FieldTrialList::FactoryGetFieldTrial( - "Instant", 1000, "CONTROL", 2013, 7, 1, &g_control)); - - // Try to give the user a consistent experience, if possible. - if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) - trial->UseOneTimeRandomization(); - - // Though each group (including CONTROL) is nominally at 20%, GetMode() - // often returns SILENT. See below for details. - g_instant = trial->AppendGroup("INSTANT", 200); // 20% - g_suggest = trial->AppendGroup("SUGGEST", 200); // 20% - g_hidden = trial->AppendGroup("HIDDEN", 200); // 20% - g_silent = trial->AppendGroup("SILENT", 200); // 20% - - // Mark these groups in requests to Google. - experiments_helper::AssociateGoogleVariationID( - "Instant", "CONTROL", chrome_variations::kInstantIDControl); - experiments_helper::AssociateGoogleVariationID( - "Instant", "SILENT", chrome_variations::kInstantIDSilent); - experiments_helper::AssociateGoogleVariationID( - "Instant", "HIDDEN", chrome_variations::kInstantIDHidden); - experiments_helper::AssociateGoogleVariationID( - "Instant", "SUGGEST", chrome_variations::kInstantIDSuggest); - experiments_helper::AssociateGoogleVariationID( - "Instant", "INSTANT", chrome_variations::kInstantIDInstant); -} - -// static -InstantFieldTrial::Mode InstantFieldTrial::GetMode(Profile* profile) { - CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kInstantFieldTrial)) { - std::string switch_value = - command_line->GetSwitchValueASCII(switches::kInstantFieldTrial); - if (switch_value == switches::kInstantFieldTrialInstant) - return INSTANT; - if (switch_value == switches::kInstantFieldTrialSuggest) - return SUGGEST; - if (switch_value == switches::kInstantFieldTrialHidden) - return HIDDEN; - if (switch_value == switches::kInstantFieldTrialSilent) - return SILENT; - return CONTROL; - } - - // Instant explicitly enabled in chrome://settings. - const PrefService* prefs = profile ? profile->GetPrefs() : NULL; - if (prefs && prefs->GetBoolean(prefs::kInstantEnabled)) - return INSTANT; - - const int group = base::FieldTrialList::FindValue("Instant"); - if (group == base::FieldTrial::kNotFinalized || group == g_control) - return CONTROL; - - // HIDDEN, SUGGEST and INSTANT need non-incognito, suggest-enabled, UMA - // opted-in profiles. - if (prefs && !profile->IsOffTheRecord() && - prefs->GetBoolean(prefs::kSearchSuggestEnabled) && - MetricsServiceHelper::IsMetricsReportingEnabled()) { - if (group == g_hidden) - return HIDDEN; - if (group == g_suggest) - return SUGGEST; - - // INSTANT also requires no group policy override and no explicit opt-out. - if (!prefs->IsManagedPreference(prefs::kInstantEnabled) && - !prefs->GetBoolean(prefs::kInstantEnabledOnce)) { - if (group == g_instant) - return INSTANT; - } - } - - // Default is SILENT. This will be returned for most users (for example, even - // if a user falls into another group, but has suggest or UMA disabled). - return SILENT; -} - -// static -std::string InstantFieldTrial::GetModeAsString(Profile* profile) { - const Mode mode = GetMode(profile); - switch (mode) { - case INSTANT: return "_Instant"; - case SUGGEST: return "_Suggest"; - case HIDDEN: return "_Hidden"; - case SILENT: return "_Silent"; - case CONTROL: return std::string(); - } - - NOTREACHED(); - return std::string(); -} diff --git a/chrome/browser/instant/instant_field_trial.h b/chrome/browser/instant/instant_field_trial.h deleted file mode 100644 index 2dca72c..0000000 --- a/chrome/browser/instant/instant_field_trial.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_INSTANT_INSTANT_FIELD_TRIAL_H_ -#define CHROME_BROWSER_INSTANT_INSTANT_FIELD_TRIAL_H_ - -#include <string> - -#include "base/basictypes.h" - -class Profile; - -// This class manages the Instant field trial, which is in one of these modes: -// -// INSTANT: The default search engine is preloaded when the omnibox gets focus. -// Queries are issued as the user types. Predicted queries are inline -// autocompleted into the omnibox. Result previews are shown. -// -// SUGGEST: Same as INSTANT, without the previews. -// -// HIDDEN: Same as SUGGEST, without the inline autocompletion. -// -// SILENT: Same as HIDDEN, without issuing queries as the user types. The query -// is sent only after the user presses <Enter>. -// -// CONTROL: Instant is disabled. -class InstantFieldTrial { - public: - enum Mode { - INSTANT, - SUGGEST, - HIDDEN, - SILENT, - CONTROL - }; - - // Activate the field trial and choose a mode at random. Without this, most - // calls to GetMode() will return CONTROL. See GetMode() for more details. - // *** MUST NOT BE CALLED MORE THAN ONCE. *** - static void Activate(); - - // Return the field trial mode for this profile. This will usually be the - // mode selected by Activate(), but can sometimes be different, depending on - // the profile. See the implementation in the .cc file for specific details. - static Mode GetMode(Profile* profile); - - // Return a string describing the mode. Can be added to histogram names, to - // split histograms by modes. - static std::string GetModeAsString(Profile* profile); - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(InstantFieldTrial); -}; - -#endif // CHROME_BROWSER_INSTANT_INSTANT_FIELD_TRIAL_H_ |