| 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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 22 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 27 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
| 28 #include "ui/gfx/color_utils.h" | 28 #include "ui/gfx/color_utils.h" |
| 29 #include "ui/gfx/sys_color_change_listener.h" | 29 #include "ui/gfx/sys_color_change_listener.h" |
| 30 | 30 |
| 31 namespace { | |
| 32 const char* GetInstantPrefName(Profile* profile) { | |
| 33 return chrome::search::IsInstantExtendedAPIEnabled(profile) ? | |
| 34 prefs::kInstantExtendedEnabled : prefs::kInstantEnabled; | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 namespace chrome { | 31 namespace chrome { |
| 39 | 32 |
| 40 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| 41 // BrowserInstantController, public: | 34 // BrowserInstantController, public: |
| 42 | 35 |
| 43 BrowserInstantController::BrowserInstantController(Browser* browser) | 36 BrowserInstantController::BrowserInstantController(Browser* browser) |
| 44 : browser_(browser), | 37 : browser_(browser), |
| 45 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 38 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
| 46 chrome::search::IsInstantExtendedAPIEnabled(profile())), | 39 chrome::search::IsInstantExtendedAPIEnabled(profile())), |
| 47 instant_unload_handler_(browser), | 40 instant_unload_handler_(browser), |
| 48 initialized_theme_info_(false) { | 41 initialized_theme_info_(false) { |
| 49 profile_pref_registrar_.Init(profile()->GetPrefs()); | 42 PrefService* prefs = profile()->GetPrefs(); |
| 50 profile_pref_registrar_.Add( | 43 |
| 51 GetInstantPrefName(profile()), | 44 profile_pref_registrar_.Init(prefs); |
| 52 base::Bind(&BrowserInstantController::ResetInstant, | 45 base::Closure reset_instant = base::Bind( |
| 53 base::Unretained(this))); | 46 &BrowserInstantController::ResetInstant, |
| 54 profile_pref_registrar_.Add( | 47 base::Unretained(this)); |
| 55 prefs::kSearchSuggestEnabled, | 48 profile_pref_registrar_.Add(prefs::kInstantEnabled, reset_instant); |
| 56 base::Bind(&BrowserInstantController::ResetInstant, | 49 profile_pref_registrar_.Add(prefs::kInstantExtendedEnabled, reset_instant); |
| 57 base::Unretained(this))); | 50 profile_pref_registrar_.Add(prefs::kSearchSuggestEnabled, reset_instant); |
| 58 ResetInstant(); | 51 ResetInstant(); |
| 59 browser_->search_model()->AddObserver(this); | 52 browser_->search_model()->AddObserver(this); |
| 60 | 53 |
| 61 #if defined(ENABLE_THEMES) | 54 #if defined(ENABLE_THEMES) |
| 62 // Listen for theme installation. | 55 // Listen for theme installation. |
| 63 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 56 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 64 content::Source<ThemeService>( | 57 content::Source<ThemeService>( |
| 65 ThemeServiceFactory::GetForProfile(profile()))); | 58 ThemeServiceFactory::GetForProfile(profile()))); |
| 66 #endif // defined(ENABLE_THEMES) | 59 #endif // defined(ENABLE_THEMES) |
| 67 } | 60 } |
| 68 | 61 |
| 69 BrowserInstantController::~BrowserInstantController() { | 62 BrowserInstantController::~BrowserInstantController() { |
| 70 browser_->search_model()->RemoveObserver(this); | 63 browser_->search_model()->RemoveObserver(this); |
| 71 } | 64 } |
| 72 | 65 |
| 73 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { | 66 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { |
| 74 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && | 67 if (!profile || profile->IsOffTheRecord()) |
| 75 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile)); | 68 return false; |
| 69 |
| 70 PrefService* prefs = profile->GetPrefs(); |
| 71 if (!prefs) |
| 72 return false; |
| 73 |
| 74 if (!chrome::search::IsInstantExtendedAPIEnabled(profile) || |
| 75 (search::GetInstantExtendedDefaultSetting() == |
| 76 search::INSTANT_USE_EXISTING && |
| 77 prefs->FindPreference( |
| 78 prefs::kInstantExtendedEnabled)->IsDefaultValue())) { |
| 79 return prefs->GetBoolean(prefs::kInstantEnabled); |
| 80 } else { |
| 81 return prefs->GetBoolean(prefs::kInstantExtendedEnabled); |
| 82 } |
| 76 } | 83 } |
| 77 | 84 |
| 78 void BrowserInstantController::RegisterUserPrefs( | 85 void BrowserInstantController::RegisterUserPrefs( |
| 79 PrefService* prefs, | |
| 80 PrefRegistrySyncable* registry) { | 86 PrefRegistrySyncable* registry) { |
| 81 // TODO(joi): Get rid of the need for PrefService param above. | |
| 82 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, | 87 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, |
| 83 PrefRegistrySyncable::SYNCABLE_PREF); | 88 PrefRegistrySyncable::SYNCABLE_PREF); |
| 84 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, | 89 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, |
| 85 PrefRegistrySyncable::SYNCABLE_PREF); | 90 PrefRegistrySyncable::SYNCABLE_PREF); |
| 86 | 91 |
| 87 bool instant_extended_default = true; | 92 bool instant_extended_default = true; |
| 88 switch (search::GetInstantExtendedDefaultSetting()) { | 93 switch (search::GetInstantExtendedDefaultSetting()) { |
| 89 case search::INSTANT_DEFAULT_ON: | 94 case search::INSTANT_DEFAULT_ON: |
| 90 instant_extended_default = true; | 95 instant_extended_default = true; |
| 91 break; | 96 break; |
| 97 // In the INSTANT_USE_EXISTING case, the kInstantExtendedEnabled |
| 98 // preference, if it still has a default value, is set to the |
| 99 // value of kInstantEnabled in the constructor of this class. |
| 92 case search::INSTANT_USE_EXISTING: | 100 case search::INSTANT_USE_EXISTING: |
| 93 instant_extended_default = prefs->GetBoolean(prefs::kInstantEnabled); | |
| 94 break; | |
| 95 case search::INSTANT_DEFAULT_OFF: | 101 case search::INSTANT_DEFAULT_OFF: |
| 96 instant_extended_default = false; | 102 instant_extended_default = false; |
| 97 break; | 103 break; |
| 98 } | 104 } |
| 99 | 105 |
| 100 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, | 106 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, |
| 101 instant_extended_default, | 107 instant_extended_default, |
| 102 PrefRegistrySyncable::SYNCABLE_PREF); | 108 PrefRegistrySyncable::SYNCABLE_PREF); |
| 103 } | 109 } |
| 104 | 110 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 initialized_theme_info_ = true; | 346 initialized_theme_info_ = true; |
| 341 } | 347 } |
| 342 | 348 |
| 343 DCHECK(initialized_theme_info_); | 349 DCHECK(initialized_theme_info_); |
| 344 | 350 |
| 345 if (browser_->search_model()->mode().is_ntp()) | 351 if (browser_->search_model()->mode().is_ntp()) |
| 346 instant_.ThemeChanged(theme_info_); | 352 instant_.ThemeChanged(theme_info_); |
| 347 } | 353 } |
| 348 | 354 |
| 349 } // namespace chrome | 355 } // namespace chrome |
| OLD | NEW |