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 kInstantExtendedEnabled still has a default value, and the | |
52 // intent is for it to have the same starting value as whatever | |
53 // kInstantEnabled has, then we set it to the value of | |
54 // kInstantEnabled. | |
55 if (search::GetInstantExtendedDefaultSetting() == | |
56 search::INSTANT_USE_EXISTING && | |
57 prefs->FindPref(prefs::kInstantExtendedEnabled)->IsDefaultValue()) { | |
58 prefs->SetBoolean(prefs::kInstantExtendedEnabled, | |
59 prefs->GetBoolean(prefs::kInstantEnabled)); | |
Mattias Nissler (ping if slow)
2013/02/22 17:07:56
After all the discussion, I don't think copying th
| |
60 } | |
61 | |
62 profile_pref_registrar_.Init(prefs); | |
50 profile_pref_registrar_.Add( | 63 profile_pref_registrar_.Add( |
51 GetInstantPrefName(profile()), | 64 GetInstantPrefName(profile()), |
52 base::Bind(&BrowserInstantController::ResetInstant, | 65 base::Bind(&BrowserInstantController::ResetInstant, |
53 base::Unretained(this))); | 66 base::Unretained(this))); |
54 profile_pref_registrar_.Add( | 67 profile_pref_registrar_.Add( |
55 prefs::kSearchSuggestEnabled, | 68 prefs::kSearchSuggestEnabled, |
56 base::Bind(&BrowserInstantController::ResetInstant, | 69 base::Bind(&BrowserInstantController::ResetInstant, |
57 base::Unretained(this))); | 70 base::Unretained(this))); |
58 ResetInstant(); | 71 ResetInstant(); |
59 browser_->search_model()->AddObserver(this); | 72 browser_->search_model()->AddObserver(this); |
60 | 73 |
61 #if defined(ENABLE_THEMES) | 74 #if defined(ENABLE_THEMES) |
62 // Listen for theme installation. | 75 // Listen for theme installation. |
63 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 76 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
64 content::Source<ThemeService>( | 77 content::Source<ThemeService>( |
65 ThemeServiceFactory::GetForProfile(profile()))); | 78 ThemeServiceFactory::GetForProfile(profile()))); |
66 #endif // defined(ENABLE_THEMES) | 79 #endif // defined(ENABLE_THEMES) |
67 } | 80 } |
68 | 81 |
69 BrowserInstantController::~BrowserInstantController() { | 82 BrowserInstantController::~BrowserInstantController() { |
70 browser_->search_model()->RemoveObserver(this); | 83 browser_->search_model()->RemoveObserver(this); |
71 } | 84 } |
72 | 85 |
73 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { | 86 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { |
74 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && | 87 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && |
75 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile)); | 88 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile)); |
76 } | 89 } |
77 | 90 |
78 void BrowserInstantController::RegisterUserPrefs( | 91 void BrowserInstantController::RegisterUserPrefs( |
79 PrefService* prefs, | |
80 PrefRegistrySyncable* registry) { | 92 PrefRegistrySyncable* registry) { |
81 // TODO(joi): Get rid of the need for PrefService param above. | |
82 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, | 93 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, |
83 PrefRegistrySyncable::SYNCABLE_PREF); | 94 PrefRegistrySyncable::SYNCABLE_PREF); |
84 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, | 95 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, |
85 PrefRegistrySyncable::SYNCABLE_PREF); | 96 PrefRegistrySyncable::SYNCABLE_PREF); |
86 | 97 |
87 bool instant_extended_default = true; | 98 bool instant_extended_default = true; |
88 switch (search::GetInstantExtendedDefaultSetting()) { | 99 switch (search::GetInstantExtendedDefaultSetting()) { |
89 case search::INSTANT_DEFAULT_ON: | 100 case search::INSTANT_DEFAULT_ON: |
90 instant_extended_default = true; | 101 instant_extended_default = true; |
91 break; | 102 break; |
103 // In the INSTANT_USE_EXISTING case, the kInstantExtendedEnabled | |
104 // preference, if it still has a default value, is set to the | |
105 // value of kInstantEnabled in the constructor of this class. | |
92 case search::INSTANT_USE_EXISTING: | 106 case search::INSTANT_USE_EXISTING: |
93 instant_extended_default = prefs->GetBoolean(prefs::kInstantEnabled); | |
94 break; | |
95 case search::INSTANT_DEFAULT_OFF: | 107 case search::INSTANT_DEFAULT_OFF: |
96 instant_extended_default = false; | 108 instant_extended_default = false; |
97 break; | 109 break; |
98 } | 110 } |
99 | 111 |
100 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, | 112 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, |
101 instant_extended_default, | 113 instant_extended_default, |
102 PrefRegistrySyncable::SYNCABLE_PREF); | 114 PrefRegistrySyncable::SYNCABLE_PREF); |
103 } | 115 } |
104 | 116 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 initialized_theme_info_ = true; | 352 initialized_theme_info_ = true; |
341 } | 353 } |
342 | 354 |
343 DCHECK(initialized_theme_info_); | 355 DCHECK(initialized_theme_info_); |
344 | 356 |
345 if (browser_->search_model()->mode().is_ntp()) | 357 if (browser_->search_model()->mode().is_ntp()) |
346 instant_.ThemeChanged(theme_info_); | 358 instant_.ThemeChanged(theme_info_); |
347 } | 359 } |
348 | 360 |
349 } // namespace chrome | 361 } // namespace chrome |
OLD | NEW |