| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/chromeos/settings/cros_settings.h" | 5 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 const std::string& in_value) { | 143 const std::string& in_value) { |
| 144 DCHECK(CalledOnValidThread()); | 144 DCHECK(CalledOnValidThread()); |
| 145 base::StringValue value(in_value); | 145 base::StringValue value(in_value); |
| 146 Set(path, value); | 146 Set(path, value); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void CrosSettings::AppendToList(const std::string& path, | 149 void CrosSettings::AppendToList(const std::string& path, |
| 150 const base::Value* value) { | 150 const base::Value* value) { |
| 151 DCHECK(CalledOnValidThread()); | 151 DCHECK(CalledOnValidThread()); |
| 152 const base::Value* old_value = GetPref(path); | 152 const base::Value* old_value = GetPref(path); |
| 153 scoped_ptr<base::Value> new_value( | 153 std::unique_ptr<base::Value> new_value(old_value ? old_value->DeepCopy() |
| 154 old_value ? old_value->DeepCopy() : new base::ListValue()); | 154 : new base::ListValue()); |
| 155 static_cast<base::ListValue*>(new_value.get())->Append(value->DeepCopy()); | 155 static_cast<base::ListValue*>(new_value.get())->Append(value->DeepCopy()); |
| 156 Set(path, *new_value); | 156 Set(path, *new_value); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void CrosSettings::RemoveFromList(const std::string& path, | 159 void CrosSettings::RemoveFromList(const std::string& path, |
| 160 const base::Value* value) { | 160 const base::Value* value) { |
| 161 DCHECK(CalledOnValidThread()); | 161 DCHECK(CalledOnValidThread()); |
| 162 const base::Value* old_value = GetPref(path); | 162 const base::Value* old_value = GetPref(path); |
| 163 scoped_ptr<base::Value> new_value( | 163 std::unique_ptr<base::Value> new_value(old_value ? old_value->DeepCopy() |
| 164 old_value ? old_value->DeepCopy() : new base::ListValue()); | 164 : new base::ListValue()); |
| 165 static_cast<base::ListValue*>(new_value.get())->Remove(*value, NULL); | 165 static_cast<base::ListValue*>(new_value.get())->Remove(*value, NULL); |
| 166 Set(path, *new_value); | 166 Set(path, *new_value); |
| 167 } | 167 } |
| 168 | 168 |
| 169 bool CrosSettings::GetBoolean(const std::string& path, | 169 bool CrosSettings::GetBoolean(const std::string& path, |
| 170 bool* bool_value) const { | 170 bool* bool_value) const { |
| 171 DCHECK(CalledOnValidThread()); | 171 DCHECK(CalledOnValidThread()); |
| 172 const base::Value* value = GetPref(path); | 172 const base::Value* value = GetPref(path); |
| 173 if (value) | 173 if (value) |
| 174 return value->GetAsBoolean(bool_value); | 174 return value->GetAsBoolean(bool_value); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 DCHECK(CalledOnValidThread()); | 288 DCHECK(CalledOnValidThread()); |
| 289 std::vector<CrosSettingsProvider*>::iterator it = | 289 std::vector<CrosSettingsProvider*>::iterator it = |
| 290 std::find(providers_.begin(), providers_.end(), provider); | 290 std::find(providers_.begin(), providers_.end(), provider); |
| 291 if (it != providers_.end()) { | 291 if (it != providers_.end()) { |
| 292 providers_.erase(it); | 292 providers_.erase(it); |
| 293 return true; | 293 return true; |
| 294 } | 294 } |
| 295 return false; | 295 return false; |
| 296 } | 296 } |
| 297 | 297 |
| 298 scoped_ptr<CrosSettings::ObserverSubscription> | 298 std::unique_ptr<CrosSettings::ObserverSubscription> |
| 299 CrosSettings::AddSettingsObserver(const std::string& path, | 299 CrosSettings::AddSettingsObserver(const std::string& path, |
| 300 const base::Closure& callback) { | 300 const base::Closure& callback) { |
| 301 DCHECK(!path.empty()); | 301 DCHECK(!path.empty()); |
| 302 DCHECK(!callback.is_null()); | 302 DCHECK(!callback.is_null()); |
| 303 DCHECK(CalledOnValidThread()); | 303 DCHECK(CalledOnValidThread()); |
| 304 | 304 |
| 305 if (!GetProvider(path)) { | 305 if (!GetProvider(path)) { |
| 306 NOTREACHED() << "Trying to add an observer for an unregistered setting: " | 306 NOTREACHED() << "Trying to add an observer for an unregistered setting: " |
| 307 << path; | 307 << path; |
| 308 return scoped_ptr<CrosSettings::ObserverSubscription>(); | 308 return std::unique_ptr<CrosSettings::ObserverSubscription>(); |
| 309 } | 309 } |
| 310 | 310 |
| 311 // Get the callback registry associated with the path. | 311 // Get the callback registry associated with the path. |
| 312 base::CallbackList<void(void)>* registry = NULL; | 312 base::CallbackList<void(void)>* registry = NULL; |
| 313 SettingsObserverMap::iterator observer_iterator = | 313 SettingsObserverMap::iterator observer_iterator = |
| 314 settings_observers_.find(path); | 314 settings_observers_.find(path); |
| 315 if (observer_iterator == settings_observers_.end()) { | 315 if (observer_iterator == settings_observers_.end()) { |
| 316 registry = new base::CallbackList<void(void)>; | 316 registry = new base::CallbackList<void(void)>; |
| 317 settings_observers_[path] = registry; | 317 settings_observers_[path] = registry; |
| 318 } else { | 318 } else { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 343 | 343 |
| 344 ScopedTestCrosSettings::ScopedTestCrosSettings() { | 344 ScopedTestCrosSettings::ScopedTestCrosSettings() { |
| 345 CrosSettings::Initialize(); | 345 CrosSettings::Initialize(); |
| 346 } | 346 } |
| 347 | 347 |
| 348 ScopedTestCrosSettings::~ScopedTestCrosSettings() { | 348 ScopedTestCrosSettings::~ScopedTestCrosSettings() { |
| 349 CrosSettings::Shutdown(); | 349 CrosSettings::Shutdown(); |
| 350 } | 350 } |
| 351 | 351 |
| 352 } // namespace chromeos | 352 } // namespace chromeos |
| OLD | NEW |