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 15072354275786a973b37434af2bdbb4bcb36d1b..b5d16855a9a1f135e3976f6cae2d72781c9dafc7 100644 |
| --- a/chrome/browser/instant/instant_controller.cc |
| +++ b/chrome/browser/instant/instant_controller.cc |
| @@ -19,6 +19,7 @@ |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/search_engines/template_url_service.h" |
| #include "chrome/browser/search_engines/template_url_service_factory.h" |
| +#include "chrome/browser/ui/search/search.h" |
| #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/chrome_switches.h" |
| @@ -60,11 +61,12 @@ const int kStaleLoaderTimeoutMS = 3 * 3600 * 1000; |
| std::string ModeToString(InstantController::Mode mode) { |
| switch (mode) { |
| + case InstantController::EXTENDED: return "_Extended"; |
| case InstantController::INSTANT: return "_Instant"; |
| case InstantController::SUGGEST: return "_Suggest"; |
| case InstantController::HIDDEN: return "_Hidden"; |
| case InstantController::SILENT: return "_Silent"; |
| - case InstantController::EXTENDED: return "_Extended"; |
| + case InstantController::DISABLED: return "_Disabled"; |
| } |
| NOTREACHED(); |
| @@ -109,25 +111,49 @@ void AddSessionStorageHistogram(InstantController::Mode mode, |
| histogram->AddBoolean(is_session_storage_the_same); |
| } |
| -} // namespace |
| - |
| -InstantController::InstantController(InstantControllerDelegate* delegate, |
| - Mode mode) |
| - : delegate_(delegate), |
| - mode_(mode), |
| - last_active_tab_(NULL), |
| - last_verbatim_(false), |
| - last_transition_type_(content::PAGE_TRANSITION_LINK), |
| - is_showing_(false), |
| - loader_processed_last_update_(false) { |
| +InstantController::Mode GetModeForProfile(Profile* profile) { |
| + if (profile && !profile->IsOffTheRecord() && profile->GetPrefs() && |
| + profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)) { |
|
Peter Kasting
2012/08/31 01:51:19
Nit: If you reverse this conditional you can omit
sreeram
2012/09/04 17:42:16
Done.
|
| + if (chrome::search::IsInstantExtendedAPIEnabled(profile)) |
|
Peter Kasting
2012/08/31 01:51:19
Nit: Also could use ?:
sreeram
2012/09/04 17:42:16
Done.
|
| + return InstantController::EXTENDED; |
| + return InstantController::INSTANT; |
| + } |
| + return InstantController::DISABLED; |
| } |
| +} // namespace |
| + |
| InstantController::~InstantController() { |
| if (GetPreviewContents()) |
| AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); |
| } |
| // static |
| +InstantController* InstantController::CreateInstant( |
| + Profile* profile, |
| + InstantControllerDelegate* delegate) { |
| + const Mode mode = GetModeForProfile(profile); |
| + return mode == DISABLED ? NULL : new InstantController(delegate, mode); |
| +} |
| + |
| +// static |
| +bool InstantController::IsExtendedAPIEnabled(Profile* profile) { |
| + return GetModeForProfile(profile) == EXTENDED; |
| +} |
| + |
| +// static |
| +bool InstantController::IsInstantEnabled(Profile* profile) { |
| + const Mode mode = GetModeForProfile(profile); |
| + return mode == EXTENDED || mode == INSTANT; |
| +} |
| + |
| +// static |
| +bool InstantController::IsSuggestEnabled(Profile* profile) { |
| + const Mode mode = GetModeForProfile(profile); |
| + return mode == EXTENDED || mode == INSTANT || mode == SUGGEST; |
| +} |
| + |
| +// static |
| void InstantController::RegisterUserPrefs(PrefService* prefs) { |
| prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, |
| PrefService::SYNCABLE_PREF); |
| @@ -135,17 +161,10 @@ void InstantController::RegisterUserPrefs(PrefService* prefs) { |
| PrefService::SYNCABLE_PREF); |
| // TODO(jamescook): Move this to search controller. |
| - prefs->RegisterDoublePref(prefs::kInstantAnimationScaleFactor, |
| - 1.0, |
| + prefs->RegisterDoublePref(prefs::kInstantAnimationScaleFactor, 1.0, |
| PrefService::UNSYNCABLE_PREF); |
| } |
| -// static |
| -bool InstantController::IsEnabled(Profile* profile) { |
| - const PrefService* prefs = profile ? profile->GetPrefs() : NULL; |
| - return prefs && prefs->GetBoolean(prefs::kInstantEnabled); |
| -} |
| - |
| bool InstantController::Update(const AutocompleteMatch& match, |
| const string16& user_text, |
| const string16& full_text, |
| @@ -182,8 +201,8 @@ bool InstantController::Update(const AutocompleteMatch& match, |
| // In EXTENDED mode, we send only |user_text| as the query text. In all other |
| // modes, we use the entire |full_text|. |
| const string16& query_text = mode_ == EXTENDED ? user_text : full_text; |
| - string16 last_query_text = |
| - mode_ == EXTENDED ? last_user_text_ : last_full_text_; |
| + string16 last_query_text = mode_ == EXTENDED ? last_user_text_ : |
|
Peter Kasting
2012/08/31 01:51:19
Nit: Wrap after '?' instead
sreeram
2012/09/04 17:42:16
Done.
|
| + last_full_text_; |
| last_user_text_ = user_text; |
| last_full_text_ = full_text; |
| @@ -534,6 +553,17 @@ void InstantController::InstantLoaderContentsFocused(InstantLoader* loader) { |
| #endif |
| } |
| +InstantController::InstantController(InstantControllerDelegate* delegate, |
| + Mode mode) |
| + : delegate_(delegate), |
| + mode_(mode), |
| + last_active_tab_(NULL), |
| + last_verbatim_(false), |
| + last_transition_type_(content::PAGE_TRANSITION_LINK), |
| + is_showing_(false), |
| + loader_processed_last_update_(false) { |
| +} |
| + |
| void InstantController::ResetLoader(const std::string& instant_url, |
| const TabContents* active_tab) { |
| if (GetPreviewContents() && loader_->instant_url() != instant_url) |