Chromium Code Reviews| Index: chrome/browser/instant/instant_controller.cc |
| diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc |
| index 151308c538ab07c28988c54d03ed55faabfb22a7..eb10fb00374978bab25567c288232ada7c7edadb 100644 |
| --- a/chrome/browser/instant/instant_controller.cc |
| +++ b/chrome/browser/instant/instant_controller.cc |
| @@ -5,10 +5,13 @@ |
| #include "chrome/browser/instant/instant_controller.h" |
| #include "base/command_line.h" |
| +#include "base/metrics/histogram.h" |
| +#include "base/rand_util.h" |
| #include "chrome/browser/autocomplete/autocomplete_match.h" |
| #include "chrome/browser/instant/instant_delegate.h" |
| #include "chrome/browser/instant/instant_loader.h" |
| #include "chrome/browser/instant/instant_loader_manager.h" |
| +#include "chrome/browser/instant/promo_counter.h" |
| #include "chrome/browser/platform_util.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/profile.h" |
| @@ -24,10 +27,61 @@ |
| // Number of ms to delay between loading urls. |
| static const int kUpdateDelayMS = 200; |
| +static InstantController::Type GetType(Profile* profile) { |
| + return InstantController::IsEnabled(profile, |
| + InstantController::PREDICTIVE_TYPE) ? |
| + InstantController::PREDICTIVE_TYPE : InstantController::VERBATIM_TYPE; |
| +} |
| + |
| +InstantController::InstantController(Profile* profile, |
| + InstantDelegate* delegate) |
| + : delegate_(delegate), |
| + tab_contents_(NULL), |
| + is_active_(false), |
| + commit_on_mouse_up_(false), |
| + last_transition_type_(PageTransition::LINK), |
| + type_(GetType(profile)) { |
| + PrefService* service = profile->GetPrefs(); |
| + if (service) { |
| + // kInstantWasEnabledOnce was added after instant, set it now to make sure |
|
Evan Stade
2010/11/15 19:59:23
nit: kInstantEnabledOnce
|
| + // it is correctly set. |
| + service->SetBoolean(prefs::kInstantEnabledOnce, true); |
| + } |
| +} |
| + |
| +InstantController::~InstantController() { |
| +} |
| + |
| // static |
| void InstantController::RegisterUserPrefs(PrefService* prefs) { |
| prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false); |
| prefs->RegisterBooleanPref(prefs::kInstantEnabled, false); |
| + prefs->RegisterBooleanPref(prefs::kInstantEnabledOnce, false); |
| + prefs->RegisterInt64Pref(prefs::kInstantEnabledTime, false); |
| + prefs->RegisterIntegerPref(prefs::kInstantType, 0); |
| + PromoCounter::RegisterUserPrefs(prefs, prefs::kInstantPromo); |
| +} |
| + |
| +// static |
| +void InstantController::RecordMetrics(Profile* profile) { |
| + if (!IsEnabled(profile)) |
| + return; |
| + |
| + PrefService* service = profile->GetPrefs(); |
| + if (service) { |
| + int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime); |
| + if (!enable_time) { |
| + service->SetInt64(prefs::kInstantEnabledTime, |
| + base::Time::Now().ToInternalValue()); |
| + } else { |
| + base::TimeDelta delta = |
| + base::Time::Now() - base::Time::FromInternalValue(enable_time); |
| + std::string name = IsEnabled(profile, PREDICTIVE_TYPE) ? |
| + "Instant.EnabledTime.Predictive" : "Instant.EnabledTime.Verbatim"; |
| + // Histogram from 1 hour to 30 days. |
| + UMA_HISTOGRAM_CUSTOM_COUNTS(name, delta.InHours(), 1, 30 * 24, 50); |
|
Evan Stade
2010/11/15 19:59:23
so the idea is we're tracking how long people leav
sky
2010/11/15 20:15:26
Yes.
|
| + } |
| + } |
| } |
| // static |
| @@ -38,34 +92,70 @@ bool InstantController::IsEnabled(Profile* profile) { |
| // static |
| bool InstantController::IsEnabled(Profile* profile, Type type) { |
| + // CommandLine takes precedence. |
| CommandLine* cl = CommandLine::ForCurrentProcess(); |
| - if (type == PREDICTIVE_TYPE) { |
| - return (cl->HasSwitch(switches::kEnablePredictiveInstant) || |
| - (profile->GetPrefs() && |
| - profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled))); |
| + if (type == PREDICTIVE_TYPE && |
| + cl->HasSwitch(switches::kEnablePredictiveInstant)) { |
| + return true; |
| + } |
| + if (type == VERBATIM_TYPE && |
| + cl->HasSwitch(switches::kEnableVerbatimInstant)) { |
| + return true; |
| } |
| - return cl->HasSwitch(switches::kEnableVerbatimInstant); |
| -} |
| -static InstantController::Type GetType(Profile* profile) { |
| - return InstantController::IsEnabled(profile, |
| - InstantController::PREDICTIVE_TYPE) ? |
| - InstantController::PREDICTIVE_TYPE : InstantController::VERBATIM_TYPE; |
| + // Then prefs. |
| + PrefService* prefs = profile->GetPrefs(); |
| + if (!prefs->GetBoolean(prefs::kInstantEnabled)) |
| + return false; |
| + |
| + Type pref_type = prefs->GetInteger(prefs::kInstantType) == |
| + static_cast<int>(PREDICTIVE_TYPE) ? PREDICTIVE_TYPE : VERBATIM_TYPE; |
| + return pref_type == type; |
| } |
| -InstantController::InstantController(Profile* profile, |
| - InstantDelegate* delegate) |
| - : delegate_(delegate), |
| - tab_contents_(NULL), |
| - is_active_(false), |
| - commit_on_mouse_up_(false), |
| - last_transition_type_(PageTransition::LINK), |
| - type_(GetType(profile)) { |
| +// static |
| +void InstantController::Enable(Profile* profile) { |
| + PromoCounter* promo_counter = profile->GetInstantPromoCounter(); |
| + if (promo_counter) |
| + promo_counter->Hide(); |
| + |
| + PrefService* service = profile->GetPrefs(); |
| + if (!service) |
| + return; |
| + |
| + service->SetBoolean(prefs::kInstantEnabled, true); |
| + service->SetBoolean(prefs::kInstantConfirmDialogShown, true); |
| + service->SetInt64(prefs::kInstantEnabledTime, |
| + base::Time::Now().ToInternalValue()); |
| + service->SetBoolean(prefs::kInstantEnabledOnce, true); |
| + // Randomly pick a type. We're doing this to get feedback as to which variant |
| + // folks prefer. |
| + service->SetInteger(prefs::kInstantType, |
| + base::RandInt(static_cast<int>(PREDICTIVE_TYPE), |
| + static_cast<int>(LAST_TYPE))); |
| } |
| -InstantController::~InstantController() { |
| +// static |
| +void InstantController::Disable(Profile* profile) { |
| + PrefService* service = profile->GetPrefs(); |
| + if (!service) |
| + return; |
| + |
| + service->SetBoolean(prefs::kInstantEnabled, false); |
| + |
| + int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime); |
| + if (!enable_time) |
| + return; |
| + |
| + base::TimeDelta delta = |
| + base::Time::Now() - base::Time::FromInternalValue(enable_time); |
| + std::string name = IsEnabled(profile, PREDICTIVE_TYPE) ? |
| + "Instant.TimeToDisable.Predictive" : "Instant.TimeToDisable.Verbatim"; |
| + // histogram from 1 minute to 10 days. |
| + UMA_HISTOGRAM_CUSTOM_COUNTS(name, delta.InMinutes(), 1, 60 * 24 * 10, 50); |
| } |
| + |
| void InstantController::Update(TabContents* tab_contents, |
| const AutocompleteMatch& match, |
| const string16& user_text, |