| Index: chrome/browser/chromeos/cros_settings.cc
|
| ===================================================================
|
| --- chrome/browser/chromeos/cros_settings.cc (revision 56142)
|
| +++ chrome/browser/chromeos/cros_settings.cc (working copy)
|
| @@ -9,6 +9,7 @@
|
| #include "base/values.h"
|
| #include "chrome/browser/chromeos/cros_settings_provider.h"
|
| #include "chrome/browser/chromeos/cros_settings_provider_user.h"
|
| +#include "chrome/common/notification_service.h"
|
|
|
| namespace chromeos {
|
|
|
| @@ -21,25 +22,47 @@
|
| return StartsWithASCII(path, kCrosSettingsPrefix, true);
|
| }
|
|
|
| +void CrosSettings::FireObservers(const char* path) {
|
| + DCHECK(CalledOnValidThread());
|
| + std::string path_str(path);
|
| + SettingsObserverMap::iterator observer_iterator =
|
| + settings_observers_.find(path_str);
|
| + if (observer_iterator == settings_observers_.end())
|
| + return;
|
| +
|
| + NotificationObserverList::Iterator it(*(observer_iterator->second));
|
| + NotificationObserver* observer;
|
| + while ((observer = it.GetNext()) != NULL) {
|
| + observer->Observe(NotificationType::SYSTEM_SETTING_CHANGED,
|
| + Source<CrosSettings>(this),
|
| + Details<std::string>(&path_str));
|
| + }
|
| +}
|
| +
|
| void CrosSettings::SetBoolean(const std::string& path, bool in_value) {
|
| + DCHECK(CalledOnValidThread());
|
| Set(path, Value::CreateBooleanValue(in_value));
|
| }
|
|
|
| void CrosSettings::SetInteger(const std::string& path, int in_value) {
|
| + DCHECK(CalledOnValidThread());
|
| Set(path, Value::CreateIntegerValue(in_value));
|
| }
|
|
|
| void CrosSettings::SetReal(const std::string& path, double in_value) {
|
| + DCHECK(CalledOnValidThread());
|
| Set(path, Value::CreateRealValue(in_value));
|
| }
|
|
|
| void CrosSettings::SetString(const std::string& path,
|
| const std::string& in_value) {
|
| + DCHECK(CalledOnValidThread());
|
| Set(path, Value::CreateStringValue(in_value));
|
| }
|
|
|
| bool CrosSettings::GetBoolean(const std::string& path,
|
| bool* bool_value) const {
|
| + DCHECK(CalledOnValidThread());
|
| Value* value;
|
| if (!Get(path, &value))
|
| return false;
|
| @@ -47,12 +70,14 @@
|
| return value->GetAsBoolean(bool_value);
|
| }
|
|
|
| -bool CrosSettings::AddProvider(CrosSettingsProvider* provider) {
|
| +bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) {
|
| + DCHECK(CalledOnValidThread());
|
| providers_.push_back(provider);
|
| return true;
|
| }
|
|
|
| -bool CrosSettings::RemoveProvider(CrosSettingsProvider* provider) {
|
| +bool CrosSettings::RemoveSettingsProvider(CrosSettingsProvider* provider) {
|
| + DCHECK(CalledOnValidThread());
|
| std::vector<CrosSettingsProvider*>::iterator it =
|
| std::find(providers_.begin(), providers_.end(), provider);
|
| if (it != providers_.end()) {
|
| @@ -62,6 +87,56 @@
|
| return false;
|
| }
|
|
|
| +void CrosSettings::AddSettingsObserver(const char* path,
|
| + NotificationObserver* obs) {
|
| + DCHECK(path);
|
| + DCHECK(obs);
|
| + DCHECK(CalledOnValidThread());
|
| +
|
| + if (!GetProvider(std::string(path))) {
|
| + NOTREACHED() << "Trying to add an observer for an unregistered setting: "
|
| + << path;
|
| + return;
|
| + }
|
| +
|
| + // Get the settings observer list associated with the path.
|
| + NotificationObserverList* observer_list = NULL;
|
| + SettingsObserverMap::iterator observer_iterator =
|
| + settings_observers_.find(path);
|
| + if (observer_iterator == settings_observers_.end()) {
|
| + observer_list = new NotificationObserverList;
|
| + settings_observers_[path] = observer_list;
|
| + } else {
|
| + observer_list = observer_iterator->second;
|
| + }
|
| +
|
| + // Verify that this observer doesn't already exist.
|
| + NotificationObserverList::Iterator it(*observer_list);
|
| + NotificationObserver* existing_obs;
|
| + while ((existing_obs = it.GetNext()) != NULL) {
|
| + DCHECK(existing_obs != obs) << path << " observer already registered";
|
| + if (existing_obs == obs)
|
| + return;
|
| + }
|
| +
|
| + // Ok, safe to add the pref observer.
|
| + observer_list->AddObserver(obs);
|
| +}
|
| +
|
| +void CrosSettings::RemoveSettingsObserver(const char* path,
|
| + NotificationObserver* obs) {
|
| + DCHECK(CalledOnValidThread());
|
| +
|
| + SettingsObserverMap::iterator observer_iterator =
|
| + settings_observers_.find(path);
|
| + if (observer_iterator == settings_observers_.end()) {
|
| + return;
|
| + }
|
| +
|
| + NotificationObserverList* observer_list = observer_iterator->second;
|
| + observer_list->RemoveObserver(obs);
|
| +}
|
| +
|
| CrosSettingsProvider* CrosSettings::GetProvider(
|
| const std::string& path) const {
|
| for (size_t i = 0; i < providers_.size(); ++i) {
|
| @@ -73,6 +148,7 @@
|
| }
|
|
|
| void CrosSettings::Set(const std::string& path, Value* in_value) {
|
| + DCHECK(CalledOnValidThread());
|
| CrosSettingsProvider* provider;
|
| provider = GetProvider(path);
|
| if (provider) {
|
| @@ -81,6 +157,7 @@
|
| }
|
|
|
| bool CrosSettings::Get(const std::string& path, Value** out_value) const {
|
| + DCHECK(CalledOnValidThread());
|
| CrosSettingsProvider* provider;
|
| provider = GetProvider(path);
|
| if (provider) {
|
| @@ -91,6 +168,7 @@
|
|
|
| bool CrosSettings::GetInteger(const std::string& path,
|
| int* out_value) const {
|
| + DCHECK(CalledOnValidThread());
|
| Value* value;
|
| if (!Get(path, &value))
|
| return false;
|
| @@ -100,6 +178,7 @@
|
|
|
| bool CrosSettings::GetReal(const std::string& path,
|
| double* out_value) const {
|
| + DCHECK(CalledOnValidThread());
|
| Value* value;
|
| if (!Get(path, &value))
|
| return false;
|
| @@ -109,6 +188,7 @@
|
|
|
| bool CrosSettings::GetString(const std::string& path,
|
| std::string* out_value) const {
|
| + DCHECK(CalledOnValidThread());
|
| Value* value;
|
| if (!Get(path, &value))
|
| return false;
|
| @@ -117,14 +197,10 @@
|
| }
|
|
|
| CrosSettings::CrosSettings() {
|
| - UserCrosSettingsProvider* user = new UserCrosSettingsProvider();
|
| - AddProvider(user);
|
| }
|
|
|
| CrosSettings::~CrosSettings() {
|
| - for (size_t i = 0; i < providers_.size(); ++i) {
|
| - delete providers_[i];
|
| - }
|
| + DCHECK(!providers_.size());
|
| }
|
|
|
| } // namespace chromeos
|
|
|