Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/browser_instant_controller.h" | 5 #include "chrome/browser/ui/browser_instant_controller.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/prefs/pref_registry_syncable.h" | 9 #include "chrome/browser/prefs/pref_registry_syncable.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
| 41 // BrowserInstantController, public: | 41 // BrowserInstantController, public: |
| 42 | 42 |
| 43 BrowserInstantController::BrowserInstantController(Browser* browser) | 43 BrowserInstantController::BrowserInstantController(Browser* browser) |
| 44 : browser_(browser), | 44 : browser_(browser), |
| 45 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 45 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
| 46 chrome::search::IsInstantExtendedAPIEnabled(profile())), | 46 chrome::search::IsInstantExtendedAPIEnabled(profile())), |
| 47 instant_unload_handler_(browser), | 47 instant_unload_handler_(browser), |
| 48 initialized_theme_info_(false) { | 48 initialized_theme_info_(false) { |
| 49 profile_pref_registrar_.Init(profile()->GetPrefs()); | 49 PrefService* prefs = profile()->GetPrefs(); |
| 50 | |
| 51 if (search::GetInstantExtendedDefaultSetting() == | |
| 52 search::INSTANT_USE_EXISTING) { | |
| 53 prefs->SetDefaultPrefValue(prefs::kInstantExtendedEnabled, | |
| 54 Value::CreateBooleanValue( | |
| 55 prefs->GetBoolean(prefs::kInstantEnabled))); | |
| 56 } | |
| 57 | |
| 58 profile_pref_registrar_.Init(prefs); | |
| 50 profile_pref_registrar_.Add( | 59 profile_pref_registrar_.Add( |
| 51 GetInstantPrefName(profile()), | 60 GetInstantPrefName(profile()), |
| 52 base::Bind(&BrowserInstantController::ResetInstant, | 61 base::Bind(&BrowserInstantController::ResetInstant, |
| 53 base::Unretained(this))); | 62 base::Unretained(this))); |
| 54 profile_pref_registrar_.Add( | 63 profile_pref_registrar_.Add( |
| 55 prefs::kSearchSuggestEnabled, | 64 prefs::kSearchSuggestEnabled, |
| 56 base::Bind(&BrowserInstantController::ResetInstant, | 65 base::Bind(&BrowserInstantController::ResetInstant, |
| 57 base::Unretained(this))); | 66 base::Unretained(this))); |
| 58 ResetInstant(); | 67 ResetInstant(); |
| 59 browser_->search_model()->AddObserver(this); | 68 browser_->search_model()->AddObserver(this); |
| 60 | 69 |
| 61 #if defined(ENABLE_THEMES) | 70 #if defined(ENABLE_THEMES) |
| 62 // Listen for theme installation. | 71 // Listen for theme installation. |
| 63 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 72 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 64 content::Source<ThemeService>( | 73 content::Source<ThemeService>( |
| 65 ThemeServiceFactory::GetForProfile(profile()))); | 74 ThemeServiceFactory::GetForProfile(profile()))); |
| 66 #endif // defined(ENABLE_THEMES) | 75 #endif // defined(ENABLE_THEMES) |
| 67 } | 76 } |
| 68 | 77 |
| 69 BrowserInstantController::~BrowserInstantController() { | 78 BrowserInstantController::~BrowserInstantController() { |
| 70 browser_->search_model()->RemoveObserver(this); | 79 browser_->search_model()->RemoveObserver(this); |
| 71 } | 80 } |
| 72 | 81 |
| 73 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { | 82 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { |
| 74 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && | 83 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && |
| 75 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile)); | 84 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile)); |
| 76 } | 85 } |
| 77 | 86 |
| 78 void BrowserInstantController::RegisterUserPrefs( | 87 void BrowserInstantController::RegisterUserPrefs( |
| 79 PrefService* prefs, | |
| 80 PrefRegistrySyncable* registry) { | 88 PrefRegistrySyncable* registry) { |
| 81 // TODO(joi): Get rid of the need for PrefService param above. | |
| 82 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, | 89 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, |
| 83 PrefRegistrySyncable::SYNCABLE_PREF); | 90 PrefRegistrySyncable::SYNCABLE_PREF); |
| 84 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, | 91 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, |
| 85 PrefRegistrySyncable::SYNCABLE_PREF); | 92 PrefRegistrySyncable::SYNCABLE_PREF); |
| 86 | 93 |
| 87 bool instant_extended_default = true; | 94 bool instant_extended_default = true; |
| 88 switch (search::GetInstantExtendedDefaultSetting()) { | 95 switch (search::GetInstantExtendedDefaultSetting()) { |
| 89 case search::INSTANT_DEFAULT_ON: | 96 case search::INSTANT_DEFAULT_ON: |
| 90 instant_extended_default = true; | 97 instant_extended_default = true; |
| 91 break; | 98 break; |
| 92 case search::INSTANT_USE_EXISTING: | 99 case search::INSTANT_USE_EXISTING: |
| 93 instant_extended_default = prefs->GetBoolean(prefs::kInstantEnabled); | 100 // Fall-through to false; the default gets reset in the |
| 94 break; | 101 // BrowserInstantController constructor in this case. |
|
Mattias Nissler (ping if slow)
2013/02/27 10:50:52
Maybe we can move all default setting to the ctor
Jói
2013/02/27 16:30:56
Done.
| |
| 95 case search::INSTANT_DEFAULT_OFF: | 102 case search::INSTANT_DEFAULT_OFF: |
| 96 instant_extended_default = false; | 103 instant_extended_default = false; |
| 97 break; | 104 break; |
| 98 } | 105 } |
| 99 | 106 |
| 100 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, | 107 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, |
| 101 instant_extended_default, | 108 instant_extended_default, |
| 102 PrefRegistrySyncable::SYNCABLE_PREF); | 109 PrefRegistrySyncable::SYNCABLE_PREF); |
| 103 } | 110 } |
| 104 | 111 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 initialized_theme_info_ = true; | 347 initialized_theme_info_ = true; |
| 341 } | 348 } |
| 342 | 349 |
| 343 DCHECK(initialized_theme_info_); | 350 DCHECK(initialized_theme_info_); |
| 344 | 351 |
| 345 if (browser_->search_model()->mode().is_ntp()) | 352 if (browser_->search_model()->mode().is_ntp()) |
| 346 instant_.ThemeChanged(theme_info_); | 353 instant_.ThemeChanged(theme_info_); |
| 347 } | 354 } |
| 348 | 355 |
| 349 } // namespace chrome | 356 } // namespace chrome |
| OLD | NEW |