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 // kInstantExtendedEnabled takes the value of kInstantEnabled in this case. | |
52 if (search::GetInstantExtendedDefaultSetting() == | |
53 search::INSTANT_USE_EXISTING) { | |
54 prefs->SetBoolean(prefs::kInstantExtendedEnabled, | |
55 prefs->GetBoolean(prefs::kInstantEnabled)); | |
Mattias Nissler (ping if slow)
2013/02/22 13:06:16
Note this is a change in semantics, not sure wheth
| |
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: // Initialized in constructor. |
robertshield
2013/02/22 13:36:55
It took me a few minutes to convince myself that t
| |
93 instant_extended_default = prefs->GetBoolean(prefs::kInstantEnabled); | |
94 break; | |
95 case search::INSTANT_DEFAULT_OFF: | 100 case search::INSTANT_DEFAULT_OFF: |
96 instant_extended_default = false; | 101 instant_extended_default = false; |
97 break; | 102 break; |
98 } | 103 } |
99 | 104 |
100 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, | 105 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, |
101 instant_extended_default, | 106 instant_extended_default, |
102 PrefRegistrySyncable::SYNCABLE_PREF); | 107 PrefRegistrySyncable::SYNCABLE_PREF); |
103 } | 108 } |
104 | 109 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 initialized_theme_info_ = true; | 345 initialized_theme_info_ = true; |
341 } | 346 } |
342 | 347 |
343 DCHECK(initialized_theme_info_); | 348 DCHECK(initialized_theme_info_); |
344 | 349 |
345 if (browser_->search_model()->mode().is_ntp()) | 350 if (browser_->search_model()->mode().is_ntp()) |
346 instant_.ThemeChanged(theme_info_); | 351 instant_.ThemeChanged(theme_info_); |
347 } | 352 } |
348 | 353 |
349 } // namespace chrome | 354 } // namespace chrome |
OLD | NEW |