Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4305)

Unified Diff: chrome/browser/ui/browser_instant_controller.cc

Issue 12328054: Fix prefs registration for BrowserInstantController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sketch of solution. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/browser_instant_controller.cc
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc
index 582ae88a9009ee2429c033d94ebfc861278d625f..b87b26d6017523534ed6c8a2845cf572399bb93e 100644
--- a/chrome/browser/ui/browser_instant_controller.cc
+++ b/chrome/browser/ui/browser_instant_controller.cc
@@ -28,13 +28,6 @@
#include "ui/gfx/color_utils.h"
#include "ui/gfx/sys_color_change_listener.h"
-namespace {
-const char* GetInstantPrefName(Profile* profile) {
- return chrome::search::IsInstantExtendedAPIEnabled(profile) ?
- prefs::kInstantExtendedEnabled : prefs::kInstantEnabled;
-}
-}
-
namespace chrome {
////////////////////////////////////////////////////////////////////////////////
@@ -46,15 +39,15 @@ BrowserInstantController::BrowserInstantController(Browser* browser)
chrome::search::IsInstantExtendedAPIEnabled(profile())),
instant_unload_handler_(browser),
initialized_theme_info_(false) {
- profile_pref_registrar_.Init(profile()->GetPrefs());
- profile_pref_registrar_.Add(
- GetInstantPrefName(profile()),
- base::Bind(&BrowserInstantController::ResetInstant,
- base::Unretained(this)));
- profile_pref_registrar_.Add(
- prefs::kSearchSuggestEnabled,
- base::Bind(&BrowserInstantController::ResetInstant,
- base::Unretained(this)));
+ PrefService* prefs = profile()->GetPrefs();
+
+ profile_pref_registrar_.Init(prefs);
+ base::Closure reset_instant = base::Bind(
+ &BrowserInstantController::ResetInstant,
+ base::Unretained(this));
+ profile_pref_registrar_.Add(prefs::kInstantEnabled, reset_instant);
+ profile_pref_registrar_.Add(prefs::kInstantExtendedEnabled, reset_instant);
+ profile_pref_registrar_.Add(prefs::kSearchSuggestEnabled, reset_instant);
ResetInstant();
browser_->search_model()->AddObserver(this);
@@ -71,14 +64,26 @@ BrowserInstantController::~BrowserInstantController() {
}
bool BrowserInstantController::IsInstantEnabled(Profile* profile) {
- return profile && !profile->IsOffTheRecord() && profile->GetPrefs() &&
- profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile));
+ if (!profile || profile->IsOffTheRecord())
+ return false;
+
+ PrefService* prefs = profile->GetPrefs();
+ if (!prefs)
+ return false;
+
+ if (!chrome::search::IsInstantExtendedAPIEnabled(profile) ||
+ (search::GetInstantExtendedDefaultSetting() ==
+ search::INSTANT_USE_EXISTING &&
+ prefs->FindPreference(
+ prefs::kInstantExtendedEnabled)->IsDefaultValue())) {
+ return prefs->GetBoolean(prefs::kInstantEnabled);
+ } else {
+ return prefs->GetBoolean(prefs::kInstantExtendedEnabled);
+ }
}
void BrowserInstantController::RegisterUserPrefs(
- PrefService* prefs,
PrefRegistrySyncable* registry) {
- // TODO(joi): Get rid of the need for PrefService param above.
registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false,
PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterBooleanPref(prefs::kInstantEnabled, false,
@@ -89,9 +94,10 @@ void BrowserInstantController::RegisterUserPrefs(
case search::INSTANT_DEFAULT_ON:
instant_extended_default = true;
break;
+ // In the INSTANT_USE_EXISTING case, the kInstantExtendedEnabled
+ // preference, if it still has a default value, is set to the
+ // value of kInstantEnabled in the constructor of this class.
case search::INSTANT_USE_EXISTING:
- instant_extended_default = prefs->GetBoolean(prefs::kInstantEnabled);
- break;
case search::INSTANT_DEFAULT_OFF:
instant_extended_default = false;
break;

Powered by Google App Engine
This is Rietveld 408576698