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..1ce3360e62de7cdfa51be463aaa149d5047cbc77 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,22 +111,35 @@ void AddSessionStorageHistogram(InstantController::Mode mode, |
| histogram->AddBoolean(is_session_storage_the_same); |
| } |
| +InstantController::Mode GetModeForProfile(Profile* profile) { |
| + if (profile && !profile->IsOffTheRecord() && profile->GetPrefs() && |
| + profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)) { |
| + if (chrome::search::IsInstantExtendedAPIEnabled(profile)) |
| + return InstantController::EXTENDED; |
| + return InstantController::INSTANT; |
| + } |
| + return InstantController::DISABLED; |
| +} |
| + |
| + |
| } // 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) { |
| +// static |
| +bool InstantController::IsExtendedAPIEnabled(Profile* profile) { |
| + const Mode mode = GetModeForProfile(profile); |
|
sky
2012/08/30 22:33:13
nit: combine these two lines, eg return GetM... ==
sreeram
2012/08/30 23:23:51
Done.
|
| + return mode == EXTENDED; |
| } |
| -InstantController::~InstantController() { |
| - if (GetPreviewContents()) |
| - AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); |
| +// 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 |
| @@ -135,15 +150,21 @@ 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); |
| +InstantController* InstantController::GetInstance( |
| + Profile* profile, |
| + InstantControllerDelegate* delegate) { |
| + const Mode mode = GetModeForProfile(profile); |
| + return mode == DISABLED ? NULL : new InstantController(delegate, mode); |
| +} |
| + |
| +InstantController::~InstantController() { |
| + if (GetPreviewContents()) |
| + AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); |
| } |
| bool InstantController::Update(const AutocompleteMatch& match, |
| @@ -182,8 +203,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_ : |
| + last_full_text_; |
| last_user_text_ = user_text; |
| last_full_text_ = full_text; |
| @@ -534,6 +555,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) |