| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/managed_mode/managed_user_settings_service.h" | 5 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/prefs/json_pref_store.h" | 10 #include "base/prefs/json_pref_store.h" |
| 11 #include "base/prefs/pref_filter.h" | 11 #include "base/prefs/pref_filter.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 14 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
| 15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/user_metrics.h" | 17 #include "content/public/browser/user_metrics.h" |
| 18 #include "sync/api/sync_change.h" | 18 #include "sync/api/sync_change.h" |
| 19 #include "sync/api/sync_error_factory.h" | 19 #include "sync/api/sync_error_factory.h" |
| 20 #include "sync/protocol/sync.pb.h" | 20 #include "sync/protocol/sync.pb.h" |
| 21 | 21 |
| 22 using base::DictionaryValue; | 22 using base::DictionaryValue; |
| 23 using base::JSONReader; | 23 using base::JSONReader; |
| 24 using base::UserMetricsAction; | 24 using base::UserMetricsAction; |
| 25 using base::Value; | 25 using base::Value; |
| 26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 using syncer::SUPERVISED_USER_SETTINGS; | 27 using syncer::SUPERVISED_USER_SETTINGS; |
| 28 using syncer::ModelType; | 28 using syncer::ModelType; |
| 29 using syncer::SyncChange; | 29 using syncer::SyncChange; |
| 30 using syncer::SyncChangeList; | 30 using syncer::SyncChangeList; |
| 31 using syncer::SyncChangeProcessor; | 31 using syncer::SyncChangeProcessor; |
| 32 using syncer::SyncData; | 32 using syncer::SyncData; |
| 33 using syncer::SyncDataList; | 33 using syncer::SyncDataList; |
| 34 using syncer::SyncError; | 34 using syncer::SyncError; |
| 35 using syncer::SyncErrorFactory; | 35 using syncer::SyncErrorFactory; |
| 36 using syncer::SyncMergeResult; | 36 using syncer::SyncMergeResult; |
| 37 | 37 |
| 38 const char kAtomicSettings[] = "atomic_settings"; | 38 const char kAtomicSettings[] = "atomic_settings"; |
| 39 const char kManagedUserInternalItemPrefix[] = "X-"; | 39 const char kSupervisedUserInternalItemPrefix[] = "X-"; |
| 40 const char kQueuedItems[] = "queued_items"; | 40 const char kQueuedItems[] = "queued_items"; |
| 41 const char kSplitSettingKeySeparator = ':'; | 41 const char kSplitSettingKeySeparator = ':'; |
| 42 const char kSplitSettings[] = "split_settings"; | 42 const char kSplitSettings[] = "split_settings"; |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 bool SettingShouldApplyToPrefs(const std::string& name) { | 46 bool SettingShouldApplyToPrefs(const std::string& name) { |
| 47 return !StartsWithASCII(name, kManagedUserInternalItemPrefix, false); | 47 return !StartsWithASCII(name, kSupervisedUserInternalItemPrefix, false); |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 ManagedUserSettingsService::ManagedUserSettingsService() | 52 SupervisedUserSettingsService::SupervisedUserSettingsService() |
| 53 : active_(false), local_settings_(new base::DictionaryValue) {} | 53 : active_(false), local_settings_(new base::DictionaryValue) {} |
| 54 | 54 |
| 55 ManagedUserSettingsService::~ManagedUserSettingsService() {} | 55 SupervisedUserSettingsService::~SupervisedUserSettingsService() {} |
| 56 | 56 |
| 57 void ManagedUserSettingsService::Init( | 57 void SupervisedUserSettingsService::Init( |
| 58 base::FilePath profile_path, | 58 base::FilePath profile_path, |
| 59 base::SequencedTaskRunner* sequenced_task_runner, | 59 base::SequencedTaskRunner* sequenced_task_runner, |
| 60 bool load_synchronously) { | 60 bool load_synchronously) { |
| 61 base::FilePath path = | 61 base::FilePath path = |
| 62 profile_path.Append(chrome::kSupervisedUserSettingsFilename); | 62 profile_path.Append(chrome::kSupervisedUserSettingsFilename); |
| 63 PersistentPrefStore* store = new JsonPrefStore( | 63 PersistentPrefStore* store = new JsonPrefStore( |
| 64 path, sequenced_task_runner, scoped_ptr<PrefFilter>()); | 64 path, sequenced_task_runner, scoped_ptr<PrefFilter>()); |
| 65 Init(store); | 65 Init(store); |
| 66 if (load_synchronously) | 66 if (load_synchronously) |
| 67 store_->ReadPrefs(); | 67 store_->ReadPrefs(); |
| 68 else | 68 else |
| 69 store_->ReadPrefsAsync(NULL); | 69 store_->ReadPrefsAsync(NULL); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ManagedUserSettingsService::Init( | 72 void SupervisedUserSettingsService::Init( |
| 73 scoped_refptr<PersistentPrefStore> store) { | 73 scoped_refptr<PersistentPrefStore> store) { |
| 74 DCHECK(!store_); | 74 DCHECK(!store_); |
| 75 store_ = store; | 75 store_ = store; |
| 76 store_->AddObserver(this); | 76 store_->AddObserver(this); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ManagedUserSettingsService::Subscribe(const SettingsCallback& callback) { | 79 void SupervisedUserSettingsService::Subscribe( |
| 80 const SettingsCallback& callback) { |
| 80 if (IsReady()) { | 81 if (IsReady()) { |
| 81 scoped_ptr<base::DictionaryValue> settings = GetSettings(); | 82 scoped_ptr<base::DictionaryValue> settings = GetSettings(); |
| 82 callback.Run(settings.get()); | 83 callback.Run(settings.get()); |
| 83 } | 84 } |
| 84 | 85 |
| 85 subscribers_.push_back(callback); | 86 subscribers_.push_back(callback); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void ManagedUserSettingsService::SetActive(bool active) { | 89 void SupervisedUserSettingsService::SetActive(bool active) { |
| 89 active_ = active; | 90 active_ = active; |
| 90 InformSubscribers(); | 91 InformSubscribers(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 bool ManagedUserSettingsService::IsReady() { | 94 bool SupervisedUserSettingsService::IsReady() { |
| 94 return store_->IsInitializationComplete(); | 95 return store_->IsInitializationComplete(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void ManagedUserSettingsService::Clear() { | 98 void SupervisedUserSettingsService::Clear() { |
| 98 store_->RemoveValue(kAtomicSettings); | 99 store_->RemoveValue(kAtomicSettings); |
| 99 store_->RemoveValue(kSplitSettings); | 100 store_->RemoveValue(kSplitSettings); |
| 100 } | 101 } |
| 101 | 102 |
| 102 // static | 103 // static |
| 103 std::string ManagedUserSettingsService::MakeSplitSettingKey( | 104 std::string SupervisedUserSettingsService::MakeSplitSettingKey( |
| 104 const std::string& prefix, | 105 const std::string& prefix, |
| 105 const std::string& key) { | 106 const std::string& key) { |
| 106 return prefix + kSplitSettingKeySeparator + key; | 107 return prefix + kSplitSettingKeySeparator + key; |
| 107 } | 108 } |
| 108 | 109 |
| 109 void ManagedUserSettingsService::UploadItem(const std::string& key, | 110 void SupervisedUserSettingsService::UploadItem(const std::string& key, |
| 110 scoped_ptr<base::Value> value) { | 111 scoped_ptr<base::Value> value) { |
| 111 DCHECK(!SettingShouldApplyToPrefs(key)); | 112 DCHECK(!SettingShouldApplyToPrefs(key)); |
| 112 | 113 |
| 113 std::string key_suffix = key; | 114 std::string key_suffix = key; |
| 114 base::DictionaryValue* dict = NULL; | 115 base::DictionaryValue* dict = NULL; |
| 115 if (sync_processor_) { | 116 if (sync_processor_) { |
| 116 content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Syncing")); | 117 content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Syncing")); |
| 117 dict = GetDictionaryAndSplitKey(&key_suffix); | 118 dict = GetDictionaryAndSplitKey(&key_suffix); |
| 118 DCHECK(GetQueuedItems()->empty()); | 119 DCHECK(GetQueuedItems()->empty()); |
| 119 SyncChangeList change_list; | 120 SyncChangeList change_list; |
| 120 SyncData data = CreateSyncDataForSetting(key, *value); | 121 SyncData data = CreateSyncDataForSetting(key, *value); |
| 121 SyncChange::SyncChangeType change_type = | 122 SyncChange::SyncChangeType change_type = |
| 122 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE | 123 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE |
| 123 : SyncChange::ACTION_ADD; | 124 : SyncChange::ACTION_ADD; |
| 124 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); | 125 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); |
| 125 SyncError error = | 126 SyncError error = |
| 126 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); | 127 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); |
| 127 DCHECK(!error.IsSet()) << error.ToString(); | 128 DCHECK(!error.IsSet()) << error.ToString(); |
| 128 } else { | 129 } else { |
| 129 // Queue the item up to be uploaded when we start syncing | 130 // Queue the item up to be uploaded when we start syncing |
| 130 // (in MergeDataAndStartSyncing()). | 131 // (in MergeDataAndStartSyncing()). |
| 131 content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Queued")); | 132 content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Queued")); |
| 132 dict = GetQueuedItems(); | 133 dict = GetQueuedItems(); |
| 133 } | 134 } |
| 134 dict->SetWithoutPathExpansion(key_suffix, value.release()); | 135 dict->SetWithoutPathExpansion(key_suffix, value.release()); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void ManagedUserSettingsService::SetLocalSettingForTesting( | 138 void SupervisedUserSettingsService::SetLocalSettingForTesting( |
| 138 const std::string& key, | 139 const std::string& key, |
| 139 scoped_ptr<base::Value> value) { | 140 scoped_ptr<base::Value> value) { |
| 140 if (value) | 141 if (value) |
| 141 local_settings_->SetWithoutPathExpansion(key, value.release()); | 142 local_settings_->SetWithoutPathExpansion(key, value.release()); |
| 142 else | 143 else |
| 143 local_settings_->RemoveWithoutPathExpansion(key, NULL); | 144 local_settings_->RemoveWithoutPathExpansion(key, NULL); |
| 144 | 145 |
| 145 InformSubscribers(); | 146 InformSubscribers(); |
| 146 } | 147 } |
| 147 | 148 |
| 148 // static | 149 // static |
| 149 SyncData ManagedUserSettingsService::CreateSyncDataForSetting( | 150 SyncData SupervisedUserSettingsService::CreateSyncDataForSetting( |
| 150 const std::string& name, | 151 const std::string& name, |
| 151 const base::Value& value) { | 152 const base::Value& value) { |
| 152 std::string json_value; | 153 std::string json_value; |
| 153 base::JSONWriter::Write(&value, &json_value); | 154 base::JSONWriter::Write(&value, &json_value); |
| 154 ::sync_pb::EntitySpecifics specifics; | 155 ::sync_pb::EntitySpecifics specifics; |
| 155 specifics.mutable_managed_user_setting()->set_name(name); | 156 specifics.mutable_managed_user_setting()->set_name(name); |
| 156 specifics.mutable_managed_user_setting()->set_value(json_value); | 157 specifics.mutable_managed_user_setting()->set_value(json_value); |
| 157 return SyncData::CreateLocalData(name, name, specifics); | 158 return SyncData::CreateLocalData(name, name, specifics); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void ManagedUserSettingsService::Shutdown() { | 161 void SupervisedUserSettingsService::Shutdown() { |
| 161 store_->RemoveObserver(this); | 162 store_->RemoveObserver(this); |
| 162 } | 163 } |
| 163 | 164 |
| 164 SyncMergeResult ManagedUserSettingsService::MergeDataAndStartSyncing( | 165 SyncMergeResult SupervisedUserSettingsService::MergeDataAndStartSyncing( |
| 165 ModelType type, | 166 ModelType type, |
| 166 const SyncDataList& initial_sync_data, | 167 const SyncDataList& initial_sync_data, |
| 167 scoped_ptr<SyncChangeProcessor> sync_processor, | 168 scoped_ptr<SyncChangeProcessor> sync_processor, |
| 168 scoped_ptr<SyncErrorFactory> error_handler) { | 169 scoped_ptr<SyncErrorFactory> error_handler) { |
| 169 DCHECK_EQ(SUPERVISED_USER_SETTINGS, type); | 170 DCHECK_EQ(SUPERVISED_USER_SETTINGS, type); |
| 170 sync_processor_ = sync_processor.Pass(); | 171 sync_processor_ = sync_processor.Pass(); |
| 171 error_handler_ = error_handler.Pass(); | 172 error_handler_ = error_handler.Pass(); |
| 172 | 173 |
| 173 // Clear all atomic and split settings, then recreate them from Sync data. | 174 // Clear all atomic and split settings, then recreate them from Sync data. |
| 174 Clear(); | 175 Clear(); |
| 175 for (SyncDataList::const_iterator it = initial_sync_data.begin(); | 176 for (SyncDataList::const_iterator it = initial_sync_data.begin(); |
| 176 it != initial_sync_data.end(); ++it) { | 177 it != initial_sync_data.end(); ++it) { |
| 177 DCHECK_EQ(SUPERVISED_USER_SETTINGS, it->GetDataType()); | 178 DCHECK_EQ(SUPERVISED_USER_SETTINGS, it->GetDataType()); |
| 178 const ::sync_pb::ManagedUserSettingSpecifics& managed_user_setting = | 179 const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting = |
| 179 it->GetSpecifics().managed_user_setting(); | 180 it->GetSpecifics().managed_user_setting(); |
| 180 scoped_ptr<base::Value> value( | 181 scoped_ptr<base::Value> value( |
| 181 JSONReader::Read(managed_user_setting.value())); | 182 JSONReader::Read(supervised_user_setting.value())); |
| 182 std::string name_suffix = managed_user_setting.name(); | 183 std::string name_suffix = supervised_user_setting.name(); |
| 183 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix); | 184 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix); |
| 184 dict->SetWithoutPathExpansion(name_suffix, value.release()); | 185 dict->SetWithoutPathExpansion(name_suffix, value.release()); |
| 185 } | 186 } |
| 186 store_->ReportValueChanged(kAtomicSettings); | 187 store_->ReportValueChanged(kAtomicSettings); |
| 187 store_->ReportValueChanged(kSplitSettings); | 188 store_->ReportValueChanged(kSplitSettings); |
| 188 InformSubscribers(); | 189 InformSubscribers(); |
| 189 | 190 |
| 190 // Upload all the queued up items (either with an ADD or an UPDATE action, | 191 // Upload all the queued up items (either with an ADD or an UPDATE action, |
| 191 // depending on whether they already exist) and move them to split settings. | 192 // depending on whether they already exist) and move them to split settings. |
| 192 SyncChangeList change_list; | 193 SyncChangeList change_list; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 209 if (change_list.size() > 0) { | 210 if (change_list.size() > 0) { |
| 210 store_->ReportValueChanged(kQueuedItems); | 211 store_->ReportValueChanged(kQueuedItems); |
| 211 result.set_error( | 212 result.set_error( |
| 212 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); | 213 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); |
| 213 } | 214 } |
| 214 | 215 |
| 215 // TODO(bauerb): Statistics? | 216 // TODO(bauerb): Statistics? |
| 216 return result; | 217 return result; |
| 217 } | 218 } |
| 218 | 219 |
| 219 void ManagedUserSettingsService::StopSyncing(ModelType type) { | 220 void SupervisedUserSettingsService::StopSyncing(ModelType type) { |
| 220 DCHECK_EQ(syncer::SUPERVISED_USER_SETTINGS, type); | 221 DCHECK_EQ(syncer::SUPERVISED_USER_SETTINGS, type); |
| 221 sync_processor_.reset(); | 222 sync_processor_.reset(); |
| 222 error_handler_.reset(); | 223 error_handler_.reset(); |
| 223 } | 224 } |
| 224 | 225 |
| 225 SyncDataList ManagedUserSettingsService::GetAllSyncData( | 226 SyncDataList SupervisedUserSettingsService::GetAllSyncData( |
| 226 ModelType type) const { | 227 ModelType type) const { |
| 227 DCHECK_EQ(syncer::SUPERVISED_USER_SETTINGS, type); | 228 DCHECK_EQ(syncer::SUPERVISED_USER_SETTINGS, type); |
| 228 SyncDataList data; | 229 SyncDataList data; |
| 229 for (base::DictionaryValue::Iterator it(*GetAtomicSettings()); !it.IsAtEnd(); | 230 for (base::DictionaryValue::Iterator it(*GetAtomicSettings()); !it.IsAtEnd(); |
| 230 it.Advance()) { | 231 it.Advance()) { |
| 231 data.push_back(CreateSyncDataForSetting(it.key(), it.value())); | 232 data.push_back(CreateSyncDataForSetting(it.key(), it.value())); |
| 232 } | 233 } |
| 233 for (base::DictionaryValue::Iterator it(*GetSplitSettings()); !it.IsAtEnd(); | 234 for (base::DictionaryValue::Iterator it(*GetSplitSettings()); !it.IsAtEnd(); |
| 234 it.Advance()) { | 235 it.Advance()) { |
| 235 const base::DictionaryValue* dict = NULL; | 236 const base::DictionaryValue* dict = NULL; |
| 236 it.value().GetAsDictionary(&dict); | 237 it.value().GetAsDictionary(&dict); |
| 237 for (base::DictionaryValue::Iterator jt(*dict); | 238 for (base::DictionaryValue::Iterator jt(*dict); |
| 238 !jt.IsAtEnd(); jt.Advance()) { | 239 !jt.IsAtEnd(); jt.Advance()) { |
| 239 data.push_back(CreateSyncDataForSetting( | 240 data.push_back(CreateSyncDataForSetting( |
| 240 MakeSplitSettingKey(it.key(), jt.key()), jt.value())); | 241 MakeSplitSettingKey(it.key(), jt.key()), jt.value())); |
| 241 } | 242 } |
| 242 } | 243 } |
| 243 DCHECK_EQ(0u, GetQueuedItems()->size()); | 244 DCHECK_EQ(0u, GetQueuedItems()->size()); |
| 244 return data; | 245 return data; |
| 245 } | 246 } |
| 246 | 247 |
| 247 SyncError ManagedUserSettingsService::ProcessSyncChanges( | 248 SyncError SupervisedUserSettingsService::ProcessSyncChanges( |
| 248 const tracked_objects::Location& from_here, | 249 const tracked_objects::Location& from_here, |
| 249 const SyncChangeList& change_list) { | 250 const SyncChangeList& change_list) { |
| 250 for (SyncChangeList::const_iterator it = change_list.begin(); | 251 for (SyncChangeList::const_iterator it = change_list.begin(); |
| 251 it != change_list.end(); ++it) { | 252 it != change_list.end(); ++it) { |
| 252 SyncData data = it->sync_data(); | 253 SyncData data = it->sync_data(); |
| 253 DCHECK_EQ(SUPERVISED_USER_SETTINGS, data.GetDataType()); | 254 DCHECK_EQ(SUPERVISED_USER_SETTINGS, data.GetDataType()); |
| 254 const ::sync_pb::ManagedUserSettingSpecifics& managed_user_setting = | 255 const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting = |
| 255 data.GetSpecifics().managed_user_setting(); | 256 data.GetSpecifics().managed_user_setting(); |
| 256 std::string key = managed_user_setting.name(); | 257 std::string key = supervised_user_setting.name(); |
| 257 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key); | 258 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key); |
| 258 switch (it->change_type()) { | 259 switch (it->change_type()) { |
| 259 case SyncChange::ACTION_ADD: | 260 case SyncChange::ACTION_ADD: |
| 260 case SyncChange::ACTION_UPDATE: { | 261 case SyncChange::ACTION_UPDATE: { |
| 261 scoped_ptr<base::Value> value( | 262 scoped_ptr<base::Value> value( |
| 262 JSONReader::Read(managed_user_setting.value())); | 263 JSONReader::Read(supervised_user_setting.value())); |
| 263 if (dict->HasKey(key)) { | 264 if (dict->HasKey(key)) { |
| 264 DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_ADD) | 265 DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_ADD) |
| 265 << "Value for key " << key << " already exists"; | 266 << "Value for key " << key << " already exists"; |
| 266 } else { | 267 } else { |
| 267 DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_UPDATE) | 268 DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_UPDATE) |
| 268 << "Value for key " << key << " doesn't exist yet"; | 269 << "Value for key " << key << " doesn't exist yet"; |
| 269 } | 270 } |
| 270 dict->SetWithoutPathExpansion(key, value.release()); | 271 dict->SetWithoutPathExpansion(key, value.release()); |
| 271 break; | 272 break; |
| 272 } | 273 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 283 } | 284 } |
| 284 } | 285 } |
| 285 store_->ReportValueChanged(kAtomicSettings); | 286 store_->ReportValueChanged(kAtomicSettings); |
| 286 store_->ReportValueChanged(kSplitSettings); | 287 store_->ReportValueChanged(kSplitSettings); |
| 287 InformSubscribers(); | 288 InformSubscribers(); |
| 288 | 289 |
| 289 SyncError error; | 290 SyncError error; |
| 290 return error; | 291 return error; |
| 291 } | 292 } |
| 292 | 293 |
| 293 void ManagedUserSettingsService::OnPrefValueChanged(const std::string& key) {} | 294 void SupervisedUserSettingsService::OnPrefValueChanged(const std::string& key) { |
| 295 } |
| 294 | 296 |
| 295 void ManagedUserSettingsService::OnInitializationCompleted(bool success) { | 297 void SupervisedUserSettingsService::OnInitializationCompleted(bool success) { |
| 296 DCHECK(success); | 298 DCHECK(success); |
| 297 DCHECK(IsReady()); | 299 DCHECK(IsReady()); |
| 298 InformSubscribers(); | 300 InformSubscribers(); |
| 299 } | 301 } |
| 300 | 302 |
| 301 base::DictionaryValue* ManagedUserSettingsService::GetOrCreateDictionary( | 303 base::DictionaryValue* SupervisedUserSettingsService::GetOrCreateDictionary( |
| 302 const std::string& key) const { | 304 const std::string& key) const { |
| 303 base::Value* value = NULL; | 305 base::Value* value = NULL; |
| 304 base::DictionaryValue* dict = NULL; | 306 base::DictionaryValue* dict = NULL; |
| 305 if (store_->GetMutableValue(key, &value)) { | 307 if (store_->GetMutableValue(key, &value)) { |
| 306 bool success = value->GetAsDictionary(&dict); | 308 bool success = value->GetAsDictionary(&dict); |
| 307 DCHECK(success); | 309 DCHECK(success); |
| 308 } else { | 310 } else { |
| 309 dict = new base::DictionaryValue; | 311 dict = new base::DictionaryValue; |
| 310 store_->SetValue(key, dict); | 312 store_->SetValue(key, dict); |
| 311 } | 313 } |
| 312 | 314 |
| 313 return dict; | 315 return dict; |
| 314 } | 316 } |
| 315 | 317 |
| 316 base::DictionaryValue* ManagedUserSettingsService::GetAtomicSettings() const { | 318 base::DictionaryValue* |
| 319 SupervisedUserSettingsService::GetAtomicSettings() const { |
| 317 return GetOrCreateDictionary(kAtomicSettings); | 320 return GetOrCreateDictionary(kAtomicSettings); |
| 318 } | 321 } |
| 319 | 322 |
| 320 base::DictionaryValue* ManagedUserSettingsService::GetSplitSettings() const { | 323 base::DictionaryValue* SupervisedUserSettingsService::GetSplitSettings() const { |
| 321 return GetOrCreateDictionary(kSplitSettings); | 324 return GetOrCreateDictionary(kSplitSettings); |
| 322 } | 325 } |
| 323 | 326 |
| 324 base::DictionaryValue* ManagedUserSettingsService::GetQueuedItems() const { | 327 base::DictionaryValue* SupervisedUserSettingsService::GetQueuedItems() const { |
| 325 return GetOrCreateDictionary(kQueuedItems); | 328 return GetOrCreateDictionary(kQueuedItems); |
| 326 } | 329 } |
| 327 | 330 |
| 328 base::DictionaryValue* ManagedUserSettingsService::GetDictionaryAndSplitKey( | 331 base::DictionaryValue* SupervisedUserSettingsService::GetDictionaryAndSplitKey( |
| 329 std::string* key) const { | 332 std::string* key) const { |
| 330 size_t pos = key->find_first_of(kSplitSettingKeySeparator); | 333 size_t pos = key->find_first_of(kSplitSettingKeySeparator); |
| 331 if (pos == std::string::npos) | 334 if (pos == std::string::npos) |
| 332 return GetAtomicSettings(); | 335 return GetAtomicSettings(); |
| 333 | 336 |
| 334 base::DictionaryValue* split_settings = GetSplitSettings(); | 337 base::DictionaryValue* split_settings = GetSplitSettings(); |
| 335 std::string prefix = key->substr(0, pos); | 338 std::string prefix = key->substr(0, pos); |
| 336 base::DictionaryValue* dict = NULL; | 339 base::DictionaryValue* dict = NULL; |
| 337 if (!split_settings->GetDictionary(prefix, &dict)) { | 340 if (!split_settings->GetDictionary(prefix, &dict)) { |
| 338 dict = new base::DictionaryValue; | 341 dict = new base::DictionaryValue; |
| 339 DCHECK(!split_settings->HasKey(prefix)); | 342 DCHECK(!split_settings->HasKey(prefix)); |
| 340 split_settings->Set(prefix, dict); | 343 split_settings->Set(prefix, dict); |
| 341 } | 344 } |
| 342 key->erase(0, pos + 1); | 345 key->erase(0, pos + 1); |
| 343 return dict; | 346 return dict; |
| 344 } | 347 } |
| 345 | 348 |
| 346 scoped_ptr<base::DictionaryValue> ManagedUserSettingsService::GetSettings() { | 349 scoped_ptr<base::DictionaryValue> SupervisedUserSettingsService::GetSettings() { |
| 347 DCHECK(IsReady()); | 350 DCHECK(IsReady()); |
| 348 if (!active_) | 351 if (!active_) |
| 349 return scoped_ptr<base::DictionaryValue>(); | 352 return scoped_ptr<base::DictionaryValue>(); |
| 350 | 353 |
| 351 scoped_ptr<base::DictionaryValue> settings(local_settings_->DeepCopy()); | 354 scoped_ptr<base::DictionaryValue> settings(local_settings_->DeepCopy()); |
| 352 | 355 |
| 353 base::DictionaryValue* atomic_settings = GetAtomicSettings(); | 356 base::DictionaryValue* atomic_settings = GetAtomicSettings(); |
| 354 for (base::DictionaryValue::Iterator it(*atomic_settings); !it.IsAtEnd(); | 357 for (base::DictionaryValue::Iterator it(*atomic_settings); !it.IsAtEnd(); |
| 355 it.Advance()) { | 358 it.Advance()) { |
| 356 if (!SettingShouldApplyToPrefs(it.key())) | 359 if (!SettingShouldApplyToPrefs(it.key())) |
| 357 continue; | 360 continue; |
| 358 | 361 |
| 359 settings->Set(it.key(), it.value().DeepCopy()); | 362 settings->Set(it.key(), it.value().DeepCopy()); |
| 360 } | 363 } |
| 361 | 364 |
| 362 base::DictionaryValue* split_settings = GetSplitSettings(); | 365 base::DictionaryValue* split_settings = GetSplitSettings(); |
| 363 for (base::DictionaryValue::Iterator it(*split_settings); !it.IsAtEnd(); | 366 for (base::DictionaryValue::Iterator it(*split_settings); !it.IsAtEnd(); |
| 364 it.Advance()) { | 367 it.Advance()) { |
| 365 if (!SettingShouldApplyToPrefs(it.key())) | 368 if (!SettingShouldApplyToPrefs(it.key())) |
| 366 continue; | 369 continue; |
| 367 | 370 |
| 368 settings->Set(it.key(), it.value().DeepCopy()); | 371 settings->Set(it.key(), it.value().DeepCopy()); |
| 369 } | 372 } |
| 370 | 373 |
| 371 return settings.Pass(); | 374 return settings.Pass(); |
| 372 } | 375 } |
| 373 | 376 |
| 374 void ManagedUserSettingsService::InformSubscribers() { | 377 void SupervisedUserSettingsService::InformSubscribers() { |
| 375 if (!IsReady()) | 378 if (!IsReady()) |
| 376 return; | 379 return; |
| 377 | 380 |
| 378 scoped_ptr<base::DictionaryValue> settings = GetSettings(); | 381 scoped_ptr<base::DictionaryValue> settings = GetSettings(); |
| 379 for (std::vector<SettingsCallback>::iterator it = subscribers_.begin(); | 382 for (std::vector<SettingsCallback>::iterator it = subscribers_.begin(); |
| 380 it != subscribers_.end(); ++it) { | 383 it != subscribers_.end(); ++it) { |
| 381 it->Run(settings.get()); | 384 it->Run(settings.get()); |
| 382 } | 385 } |
| 383 } | 386 } |
| OLD | NEW |