| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/cros_settings.h" | 5 #include "chrome/browser/chromeos/cros_settings.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/cros_settings_provider.h" | |
| 12 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | 11 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
| 12 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
| 15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
| 17 | 17 |
| 18 namespace chromeos { | 18 namespace chromeos { |
| 19 | 19 |
| 20 static base::LazyInstance<CrosSettings> g_cros_settings = | 20 static base::LazyInstance<CrosSettings> g_cros_settings = |
| 21 LAZY_INSTANCE_INITIALIZER; | 21 LAZY_INSTANCE_INITIALIZER; |
| 22 | 22 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 return; | 139 return; |
| 140 } | 140 } |
| 141 | 141 |
| 142 NotificationObserverList* observer_list = observer_iterator->second; | 142 NotificationObserverList* observer_list = observer_iterator->second; |
| 143 observer_list->RemoveObserver(obs); | 143 observer_list->RemoveObserver(obs); |
| 144 } | 144 } |
| 145 | 145 |
| 146 CrosSettingsProvider* CrosSettings::GetProvider( | 146 CrosSettingsProvider* CrosSettings::GetProvider( |
| 147 const std::string& path) const { | 147 const std::string& path) const { |
| 148 for (size_t i = 0; i < providers_.size(); ++i) { | 148 for (size_t i = 0; i < providers_.size(); ++i) { |
| 149 if (providers_[i]->HandlesSetting(path)) { | 149 if (providers_[i]->HandlesSetting(path)) |
| 150 return providers_[i]; | 150 return providers_[i]; |
| 151 } | |
| 152 } | 151 } |
| 153 return NULL; | 152 return NULL; |
| 154 } | 153 } |
| 155 | 154 |
| 156 bool CrosSettings::Get(const std::string& path, Value** out_value) const { | 155 const base::Value* CrosSettings::GetPref(const std::string& path) const { |
| 157 DCHECK(CalledOnValidThread()); | 156 DCHECK(CalledOnValidThread()); |
| 158 CrosSettingsProvider* provider; | 157 CrosSettingsProvider* provider = GetProvider(path); |
| 159 provider = GetProvider(path); | 158 if (provider) |
| 160 if (provider) { | 159 return provider->Get(path); |
| 161 return provider->Get(path, out_value); | 160 NOTREACHED() << path << " preference was not found in the signed settings."; |
| 162 } | 161 return NULL; |
| 162 } |
| 163 |
| 164 bool CrosSettings::GetTrusted(const std::string& path, |
| 165 const base::Closure& callback) const { |
| 166 DCHECK(CalledOnValidThread()); |
| 167 CrosSettingsProvider* provider = GetProvider(path); |
| 168 if (provider) |
| 169 return provider->GetTrusted(path, callback); |
| 170 NOTREACHED() << "CrosSettings::GetTrusted called for unknown pref : " << path; |
| 163 return false; | 171 return false; |
| 164 } | 172 } |
| 165 | 173 |
| 166 bool CrosSettings::GetBoolean(const std::string& path, | 174 bool CrosSettings::GetBoolean(const std::string& path, |
| 167 bool* bool_value) const { | 175 bool* bool_value) const { |
| 168 DCHECK(CalledOnValidThread()); | 176 DCHECK(CalledOnValidThread()); |
| 169 Value* value; | 177 const base::Value* value = GetPref(path); |
| 170 if (!Get(path, &value)) | 178 if (value) |
| 171 return false; | 179 return value->GetAsBoolean(bool_value); |
| 172 | 180 return false; |
| 173 return value->GetAsBoolean(bool_value); | |
| 174 } | 181 } |
| 175 | 182 |
| 176 bool CrosSettings::GetInteger(const std::string& path, | 183 bool CrosSettings::GetInteger(const std::string& path, |
| 177 int* out_value) const { | 184 int* out_value) const { |
| 178 DCHECK(CalledOnValidThread()); | 185 DCHECK(CalledOnValidThread()); |
| 179 Value* value; | 186 const base::Value* value = GetPref(path); |
| 180 if (!Get(path, &value)) | 187 if (value) |
| 181 return false; | 188 return value->GetAsInteger(out_value); |
| 182 | 189 return false; |
| 183 return value->GetAsInteger(out_value); | |
| 184 } | 190 } |
| 185 | 191 |
| 186 bool CrosSettings::GetDouble(const std::string& path, | 192 bool CrosSettings::GetDouble(const std::string& path, |
| 187 double* out_value) const { | 193 double* out_value) const { |
| 188 DCHECK(CalledOnValidThread()); | 194 DCHECK(CalledOnValidThread()); |
| 189 Value* value; | 195 const base::Value* value = GetPref(path); |
| 190 if (!Get(path, &value)) | 196 if (value) |
| 191 return false; | 197 return value->GetAsDouble(out_value); |
| 192 | 198 return false; |
| 193 return value->GetAsDouble(out_value); | |
| 194 } | 199 } |
| 195 | 200 |
| 196 bool CrosSettings::GetString(const std::string& path, | 201 bool CrosSettings::GetString(const std::string& path, |
| 197 std::string* out_value) const { | 202 std::string* out_value) const { |
| 198 DCHECK(CalledOnValidThread()); | 203 DCHECK(CalledOnValidThread()); |
| 199 Value* value; | 204 const base::Value* value = GetPref(path); |
| 200 if (!Get(path, &value)) | 205 if (value) |
| 201 return false; | 206 return value->GetAsString(out_value); |
| 207 return false; |
| 208 } |
| 202 | 209 |
| 203 return value->GetAsString(out_value); | 210 bool CrosSettings::GetList(const std::string& path, |
| 211 const base::ListValue** out_value) const { |
| 212 DCHECK(CalledOnValidThread()); |
| 213 const base::Value* value = GetPref(path); |
| 214 if (value) |
| 215 return value->GetAsList(out_value); |
| 216 return false; |
| 204 } | 217 } |
| 205 | 218 |
| 206 CrosSettings::CrosSettings() { | 219 CrosSettings::CrosSettings() { |
| 220 AddSettingsProvider(new SystemSettingsProvider()); |
| 221 AddSettingsProvider(new UserCrosSettingsProvider()); |
| 207 } | 222 } |
| 208 | 223 |
| 209 CrosSettings::~CrosSettings() { | 224 CrosSettings::~CrosSettings() { |
| 210 DCHECK(providers_.empty()); | 225 STLDeleteElements(&providers_); |
| 211 STLDeleteValues(&settings_observers_); | 226 STLDeleteValues(&settings_observers_); |
| 212 } | 227 } |
| 213 | 228 |
| 214 } // namespace chromeos | 229 } // namespace chromeos |
| OLD | NEW |