| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/legacy/supervised_user_shared_settings_
service.h" | 5 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_
service.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 using syncer::SyncErrorFactory; | 35 using syncer::SyncErrorFactory; |
| 36 using syncer::SyncMergeResult; | 36 using syncer::SyncMergeResult; |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 const char kAcknowledged[] = "acknowledged"; | 40 const char kAcknowledged[] = "acknowledged"; |
| 41 const char kValue[] = "value"; | 41 const char kValue[] = "value"; |
| 42 | 42 |
| 43 DictionaryValue* FindOrCreateDictionary(DictionaryValue* parent, | 43 DictionaryValue* FindOrCreateDictionary(DictionaryValue* parent, |
| 44 const std::string& key) { | 44 const std::string& key) { |
| 45 DictionaryValue* dict = NULL; | 45 DictionaryValue* dict = nullptr; |
| 46 if (!parent->GetDictionaryWithoutPathExpansion(key, &dict)) { | 46 if (!parent->GetDictionaryWithoutPathExpansion(key, &dict)) { |
| 47 dict = new DictionaryValue; | 47 dict = new DictionaryValue; |
| 48 parent->SetWithoutPathExpansion(key, dict); | 48 parent->SetWithoutPathExpansion(key, dict); |
| 49 } | 49 } |
| 50 return dict; | 50 return dict; |
| 51 } | 51 } |
| 52 | 52 |
| 53 class ScopedSupervisedUserSharedSettingsUpdate { | 53 class ScopedSupervisedUserSharedSettingsUpdate { |
| 54 public: | 54 public: |
| 55 ScopedSupervisedUserSharedSettingsUpdate(PrefService* prefs, | 55 ScopedSupervisedUserSharedSettingsUpdate(PrefService* prefs, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 DictionaryPrefUpdate update_; | 70 DictionaryPrefUpdate update_; |
| 71 std::string su_id_; | 71 std::string su_id_; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 SyncData CreateSyncDataForValue( | 74 SyncData CreateSyncDataForValue( |
| 75 const std::string& su_id, | 75 const std::string& su_id, |
| 76 const std::string& key, | 76 const std::string& key, |
| 77 const Value& dict_value) { | 77 const Value& dict_value) { |
| 78 const DictionaryValue* dict = NULL; | 78 const DictionaryValue* dict = nullptr; |
| 79 if (!dict_value.GetAsDictionary(&dict)) | 79 if (!dict_value.GetAsDictionary(&dict)) |
| 80 return SyncData(); | 80 return SyncData(); |
| 81 | 81 |
| 82 const Value* value = NULL; | 82 const Value* value = nullptr; |
| 83 if (!dict->Get(kValue, &value)) | 83 if (!dict->Get(kValue, &value)) |
| 84 return SyncData(); | 84 return SyncData(); |
| 85 | 85 |
| 86 bool acknowledged = false; | 86 bool acknowledged = false; |
| 87 dict->GetBoolean(kAcknowledged, &acknowledged); | 87 dict->GetBoolean(kAcknowledged, &acknowledged); |
| 88 | 88 |
| 89 return SupervisedUserSharedSettingsService::CreateSyncDataForSetting( | 89 return SupervisedUserSharedSettingsService::CreateSyncDataForSetting( |
| 90 su_id, key, *value, acknowledged); | 90 su_id, key, *value, acknowledged); |
| 91 } | 91 } |
| 92 | 92 |
| 93 } // namespace | 93 } // namespace |
| 94 | 94 |
| 95 | 95 |
| 96 SupervisedUserSharedSettingsService::SupervisedUserSharedSettingsService( | 96 SupervisedUserSharedSettingsService::SupervisedUserSharedSettingsService( |
| 97 PrefService* prefs) | 97 PrefService* prefs) |
| 98 : prefs_(prefs) {} | 98 : prefs_(prefs) {} |
| 99 | 99 |
| 100 SupervisedUserSharedSettingsService::~SupervisedUserSharedSettingsService() {} | 100 SupervisedUserSharedSettingsService::~SupervisedUserSharedSettingsService() {} |
| 101 | 101 |
| 102 void SupervisedUserSharedSettingsService::SetValueInternal( | 102 void SupervisedUserSharedSettingsService::SetValueInternal( |
| 103 const std::string& su_id, | 103 const std::string& su_id, |
| 104 const std::string& key, | 104 const std::string& key, |
| 105 const Value& value, | 105 const Value& value, |
| 106 bool acknowledged) { | 106 bool acknowledged) { |
| 107 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); | 107 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); |
| 108 DictionaryValue* update_dict = update.Get(); | 108 DictionaryValue* update_dict = update.Get(); |
| 109 | 109 |
| 110 DictionaryValue* dict = NULL; | 110 DictionaryValue* dict = nullptr; |
| 111 bool has_key = update_dict->GetDictionaryWithoutPathExpansion(key, &dict); | 111 bool has_key = update_dict->GetDictionaryWithoutPathExpansion(key, &dict); |
| 112 if (!has_key) { | 112 if (!has_key) { |
| 113 dict = new DictionaryValue; | 113 dict = new DictionaryValue; |
| 114 update_dict->SetWithoutPathExpansion(key, dict); | 114 update_dict->SetWithoutPathExpansion(key, dict); |
| 115 } | 115 } |
| 116 dict->SetWithoutPathExpansion(kValue, value.DeepCopy()); | 116 dict->SetWithoutPathExpansion(kValue, value.DeepCopy()); |
| 117 dict->SetBooleanWithoutPathExpansion(kAcknowledged, acknowledged); | 117 dict->SetBooleanWithoutPathExpansion(kAcknowledged, acknowledged); |
| 118 | 118 |
| 119 if (!sync_processor_) | 119 if (!sync_processor_) |
| 120 return; | 120 return; |
| 121 | 121 |
| 122 SyncData data = CreateSyncDataForSetting(su_id, key, value, acknowledged); | 122 SyncData data = CreateSyncDataForSetting(su_id, key, value, acknowledged); |
| 123 SyncChange::SyncChangeType change_type = | 123 SyncChange::SyncChangeType change_type = |
| 124 has_key ? SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD; | 124 has_key ? SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD; |
| 125 SyncChangeList changes; | 125 SyncChangeList changes; |
| 126 changes.push_back(SyncChange(FROM_HERE, change_type, data)); | 126 changes.push_back(SyncChange(FROM_HERE, change_type, data)); |
| 127 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 127 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 128 DCHECK(!error.IsSet()) << error.ToString(); | 128 DCHECK(!error.IsSet()) << error.ToString(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 const Value* SupervisedUserSharedSettingsService::GetValue( | 131 const Value* SupervisedUserSharedSettingsService::GetValue( |
| 132 const std::string& su_id, | 132 const std::string& su_id, |
| 133 const std::string& key) { | 133 const std::string& key) { |
| 134 const DictionaryValue* data = | 134 const DictionaryValue* data = |
| 135 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); | 135 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); |
| 136 const DictionaryValue* dict = NULL; | 136 const DictionaryValue* dict = nullptr; |
| 137 if (!data->GetDictionaryWithoutPathExpansion(su_id, &dict)) | 137 if (!data->GetDictionaryWithoutPathExpansion(su_id, &dict)) |
| 138 return NULL; | 138 return nullptr; |
| 139 | 139 |
| 140 const DictionaryValue* settings = NULL; | 140 const DictionaryValue* settings = nullptr; |
| 141 if (!dict->GetDictionaryWithoutPathExpansion(key, &settings)) | 141 if (!dict->GetDictionaryWithoutPathExpansion(key, &settings)) |
| 142 return NULL; | 142 return nullptr; |
| 143 | 143 |
| 144 const Value* value = NULL; | 144 const Value* value = nullptr; |
| 145 if (!settings->GetWithoutPathExpansion(kValue, &value)) | 145 if (!settings->GetWithoutPathExpansion(kValue, &value)) |
| 146 return NULL; | 146 return nullptr; |
| 147 | 147 |
| 148 return value; | 148 return value; |
| 149 } | 149 } |
| 150 | 150 |
| 151 void SupervisedUserSharedSettingsService::SetValue( | 151 void SupervisedUserSharedSettingsService::SetValue( |
| 152 const std::string& su_id, | 152 const std::string& su_id, |
| 153 const std::string& key, | 153 const std::string& key, |
| 154 const Value& value) { | 154 const Value& value) { |
| 155 SetValueInternal(su_id, key, value, true); | 155 SetValueInternal(su_id, key, value, true); |
| 156 } | 156 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 syncer::SyncMergeResult | 191 syncer::SyncMergeResult |
| 192 SupervisedUserSharedSettingsService::MergeDataAndStartSyncing( | 192 SupervisedUserSharedSettingsService::MergeDataAndStartSyncing( |
| 193 syncer::ModelType type, | 193 syncer::ModelType type, |
| 194 const syncer::SyncDataList& initial_sync_data, | 194 const syncer::SyncDataList& initial_sync_data, |
| 195 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 195 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 196 scoped_ptr<syncer::SyncErrorFactory> error_handler) { | 196 scoped_ptr<syncer::SyncErrorFactory> error_handler) { |
| 197 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); | 197 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); |
| 198 sync_processor_ = std::move(sync_processor); | 198 sync_processor_ = std::move(sync_processor); |
| 199 error_handler_ = std::move(error_handler); | 199 error_handler_ = std::move(error_handler); |
| 200 | 200 |
| 201 int num_before_association = 0; |
| 202 std::map<std::string, std::set<std::string> > pref_seen_keys; |
| 203 const DictionaryValue* pref_dict = |
| 204 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); |
| 205 for (DictionaryValue::Iterator it(*pref_dict); !it.IsAtEnd(); it.Advance()) { |
| 206 const DictionaryValue* dict = nullptr; |
| 207 bool success = it.value().GetAsDictionary(&dict); |
| 208 DCHECK(success); |
| 209 num_before_association += dict->size(); |
| 210 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) |
| 211 pref_seen_keys[it.key()].insert(jt.key()); |
| 212 } |
| 213 |
| 201 // We keep a map from MU ID to the set of keys that we have seen in the | 214 // We keep a map from MU ID to the set of keys that we have seen in the |
| 202 // initial sync data. | 215 // initial sync data. |
| 203 std::map<std::string, std::set<std::string> > seen_keys; | 216 std::map<std::string, std::set<std::string> > sync_seen_keys; |
| 217 int num_added = 0; |
| 218 int num_modified = 0; |
| 204 | 219 |
| 205 // Iterate over all initial sync data, and update it locally. This means that | 220 // Iterate over all initial sync data, and update it locally. This means that |
| 206 // the value from the server always wins over a local value. | 221 // the value from the server always wins over a local value. |
| 207 for (const SyncData& sync_data : initial_sync_data) { | 222 for (const SyncData& sync_data : initial_sync_data) { |
| 208 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, sync_data.GetDataType()); | 223 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, sync_data.GetDataType()); |
| 209 const ::sync_pb::ManagedUserSharedSettingSpecifics& | 224 const ::sync_pb::ManagedUserSharedSettingSpecifics& |
| 210 supervised_user_shared_setting = | 225 supervised_user_shared_setting = |
| 211 sync_data.GetSpecifics().managed_user_shared_setting(); | 226 sync_data.GetSpecifics().managed_user_shared_setting(); |
| 212 scoped_ptr<Value> value = | 227 scoped_ptr<Value> value = |
| 213 base::JSONReader::Read(supervised_user_shared_setting.value()); | 228 base::JSONReader::Read(supervised_user_shared_setting.value()); |
| 214 const std::string& su_id = supervised_user_shared_setting.mu_id(); | 229 const std::string& su_id = supervised_user_shared_setting.mu_id(); |
| 215 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); | 230 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); |
| 216 const std::string& key = supervised_user_shared_setting.key(); | 231 const std::string& key = supervised_user_shared_setting.key(); |
| 217 DictionaryValue* dict = FindOrCreateDictionary(update.Get(), key); | 232 DictionaryValue* dict = FindOrCreateDictionary(update.Get(), key); |
| 218 dict->SetWithoutPathExpansion(kValue, value.release()); | 233 dict->SetWithoutPathExpansion(kValue, value.release()); |
| 219 | 234 |
| 220 // Every setting we get from the server should have the acknowledged flag | 235 // Every setting we get from the server should have the acknowledged flag |
| 221 // set. | 236 // set. |
| 222 DCHECK(supervised_user_shared_setting.acknowledged()); | 237 DCHECK(supervised_user_shared_setting.acknowledged()); |
| 223 dict->SetBooleanWithoutPathExpansion( | 238 dict->SetBooleanWithoutPathExpansion( |
| 224 kAcknowledged, supervised_user_shared_setting.acknowledged()); | 239 kAcknowledged, supervised_user_shared_setting.acknowledged()); |
| 225 callbacks_.Notify(su_id, key); | 240 callbacks_.Notify(su_id, key); |
| 226 | 241 |
| 227 seen_keys[su_id].insert(key); | 242 if (pref_seen_keys.find(su_id) == pref_seen_keys.end()) |
| 243 num_added++; |
| 244 else |
| 245 num_modified++; |
| 246 |
| 247 sync_seen_keys[su_id].insert(key); |
| 228 } | 248 } |
| 229 | 249 |
| 230 // Iterate over all settings that we have locally, which includes settings | 250 // Iterate over all settings that we have locally, which includes settings |
| 231 // that were just synced down. We filter those out using |seen_keys|. | 251 // that were just synced down. We filter those out using |sync_seen_keys|. |
| 232 SyncChangeList change_list; | 252 SyncChangeList change_list; |
| 253 int num_after_association = 0; |
| 233 const DictionaryValue* all_settings = | 254 const DictionaryValue* all_settings = |
| 234 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); | 255 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); |
| 235 for (DictionaryValue::Iterator it(*all_settings); !it.IsAtEnd(); | 256 for (DictionaryValue::Iterator it(*all_settings); !it.IsAtEnd(); |
| 236 it.Advance()) { | 257 it.Advance()) { |
| 237 const DictionaryValue* dict = NULL; | 258 const DictionaryValue* dict = nullptr; |
| 238 bool success = it.value().GetAsDictionary(&dict); | 259 bool success = it.value().GetAsDictionary(&dict); |
| 239 DCHECK(success); | 260 DCHECK(success); |
| 240 | 261 |
| 241 const std::set<std::string>& seen = seen_keys[it.key()]; | 262 const std::set<std::string>& seen = sync_seen_keys[it.key()]; |
| 263 num_after_association += dict->size(); |
| 242 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) { | 264 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) { |
| 243 // We only need to upload settings that we haven't seen in the initial | 265 // We only need to upload settings that we haven't seen in the initial |
| 244 // sync data (which means they were added locally). | 266 // sync data (which means they were added locally). |
| 245 if (seen.count(jt.key()) > 0) | 267 if (seen.count(jt.key()) > 0) |
| 246 continue; | 268 continue; |
| 247 | 269 |
| 248 SyncData data = CreateSyncDataForValue(it.key(), jt.key(), jt.value()); | 270 SyncData data = CreateSyncDataForValue(it.key(), jt.key(), jt.value()); |
| 249 DCHECK(data.IsValid()); | 271 DCHECK(data.IsValid()); |
| 250 change_list.push_back( | 272 change_list.push_back( |
| 251 SyncChange(FROM_HERE, SyncChange::ACTION_ADD, data)); | 273 SyncChange(FROM_HERE, SyncChange::ACTION_ADD, data)); |
| 252 } | 274 } |
| 253 } | 275 } |
| 254 | 276 |
| 255 SyncMergeResult result(SUPERVISED_USER_SHARED_SETTINGS); | 277 SyncMergeResult result(SUPERVISED_USER_SHARED_SETTINGS); |
| 256 // Process all the accumulated changes. | 278 // Process all the accumulated changes. |
| 257 if (change_list.size() > 0) { | 279 if (change_list.size() > 0) { |
| 258 result.set_error( | 280 result.set_error( |
| 259 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); | 281 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); |
| 260 } | 282 } |
| 261 | 283 |
| 262 // TODO(bauerb): Statistics? | 284 result.set_num_items_added(num_added); |
| 285 result.set_num_items_modified(num_modified); |
| 286 result.set_num_items_before_association(num_before_association); |
| 287 result.set_num_items_after_association(num_after_association); |
| 263 return result; | 288 return result; |
| 264 } | 289 } |
| 265 | 290 |
| 266 void SupervisedUserSharedSettingsService::StopSyncing(syncer::ModelType type) { | 291 void SupervisedUserSharedSettingsService::StopSyncing(syncer::ModelType type) { |
| 267 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); | 292 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); |
| 268 sync_processor_.reset(); | 293 sync_processor_.reset(); |
| 269 error_handler_.reset(); | 294 error_handler_.reset(); |
| 270 } | 295 } |
| 271 | 296 |
| 272 syncer::SyncDataList SupervisedUserSharedSettingsService::GetAllSyncData( | 297 syncer::SyncDataList SupervisedUserSharedSettingsService::GetAllSyncData( |
| 273 syncer::ModelType type) const { | 298 syncer::ModelType type) const { |
| 274 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); | 299 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); |
| 275 SyncDataList data; | 300 SyncDataList data; |
| 276 const DictionaryValue* all_settings = | 301 const DictionaryValue* all_settings = |
| 277 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); | 302 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); |
| 278 for (DictionaryValue::Iterator it(*all_settings); !it.IsAtEnd(); | 303 for (DictionaryValue::Iterator it(*all_settings); !it.IsAtEnd(); |
| 279 it.Advance()) { | 304 it.Advance()) { |
| 280 const DictionaryValue* dict = NULL; | 305 const DictionaryValue* dict = nullptr; |
| 281 bool success = it.value().GetAsDictionary(&dict); | 306 bool success = it.value().GetAsDictionary(&dict); |
| 282 DCHECK(success); | 307 DCHECK(success); |
| 283 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) { | 308 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) { |
| 284 data.push_back(CreateSyncDataForValue(it.key(), jt.key(), jt.value())); | 309 data.push_back(CreateSyncDataForValue(it.key(), jt.key(), jt.value())); |
| 285 } | 310 } |
| 286 } | 311 } |
| 287 return data; | 312 return data; |
| 288 } | 313 } |
| 289 | 314 |
| 290 syncer::SyncError SupervisedUserSharedSettingsService::ProcessSyncChanges( | 315 syncer::SyncError SupervisedUserSharedSettingsService::ProcessSyncChanges( |
| 291 const tracked_objects::Location& from_here, | 316 const tracked_objects::Location& from_here, |
| 292 const syncer::SyncChangeList& change_list) { | 317 const syncer::SyncChangeList& change_list) { |
| 293 for (const SyncChange& sync_change : change_list) { | 318 for (const SyncChange& sync_change : change_list) { |
| 294 SyncData data = sync_change.sync_data(); | 319 SyncData data = sync_change.sync_data(); |
| 295 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, data.GetDataType()); | 320 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, data.GetDataType()); |
| 296 const ::sync_pb::ManagedUserSharedSettingSpecifics& | 321 const ::sync_pb::ManagedUserSharedSettingSpecifics& |
| 297 supervised_user_shared_setting = | 322 supervised_user_shared_setting = |
| 298 data.GetSpecifics().managed_user_shared_setting(); | 323 data.GetSpecifics().managed_user_shared_setting(); |
| 299 const std::string& key = supervised_user_shared_setting.key(); | 324 const std::string& key = supervised_user_shared_setting.key(); |
| 300 const std::string& su_id = supervised_user_shared_setting.mu_id(); | 325 const std::string& su_id = supervised_user_shared_setting.mu_id(); |
| 301 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); | 326 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); |
| 302 DictionaryValue* update_dict = update.Get(); | 327 DictionaryValue* update_dict = update.Get(); |
| 303 DictionaryValue* dict = NULL; | 328 DictionaryValue* dict = nullptr; |
| 304 bool has_key = update_dict->GetDictionaryWithoutPathExpansion(key, &dict); | 329 bool has_key = update_dict->GetDictionaryWithoutPathExpansion(key, &dict); |
| 305 switch (sync_change.change_type()) { | 330 switch (sync_change.change_type()) { |
| 306 case SyncChange::ACTION_ADD: | 331 case SyncChange::ACTION_ADD: |
| 307 case SyncChange::ACTION_UPDATE: { | 332 case SyncChange::ACTION_UPDATE: { |
| 308 // Every setting we get from the server should have the acknowledged | 333 // Every setting we get from the server should have the acknowledged |
| 309 // flag set. | 334 // flag set. |
| 310 DCHECK(supervised_user_shared_setting.acknowledged()); | 335 DCHECK(supervised_user_shared_setting.acknowledged()); |
| 311 | 336 |
| 312 if (has_key) { | 337 if (has_key) { |
| 313 // If the supervised user already exists, it should be an update | 338 // If the supervised user already exists, it should be an update |
| 314 // action. | 339 // action. |
| 315 DCHECK_EQ(SyncChange::ACTION_UPDATE, sync_change.change_type()); | 340 DCHECK_EQ(SyncChange::ACTION_UPDATE, sync_change.change_type()); |
| 316 } else { | 341 } else { |
| 317 // Otherwise, it should be an add action. | 342 // Otherwise, it should be an add action. |
| 318 DCHECK_EQ(SyncChange::ACTION_ADD, sync_change.change_type()); | 343 DCHECK_EQ(SyncChange::ACTION_ADD, sync_change.change_type()); |
| 319 dict = new DictionaryValue; | 344 dict = new DictionaryValue; |
| 320 update_dict->SetWithoutPathExpansion(key, dict); | 345 update_dict->SetWithoutPathExpansion(key, dict); |
| 321 } | 346 } |
| 322 scoped_ptr<Value> value = | 347 scoped_ptr<Value> value = |
| 323 base::JSONReader::Read(supervised_user_shared_setting.value()); | 348 base::JSONReader::Read(supervised_user_shared_setting.value()); |
| 324 dict->SetWithoutPathExpansion(kValue, value.release()); | 349 dict->SetWithoutPathExpansion(kValue, value.release()); |
| 325 dict->SetBooleanWithoutPathExpansion( | 350 dict->SetBooleanWithoutPathExpansion( |
| 326 kAcknowledged, supervised_user_shared_setting.acknowledged()); | 351 kAcknowledged, supervised_user_shared_setting.acknowledged()); |
| 327 break; | 352 break; |
| 328 } | 353 } |
| 329 case SyncChange::ACTION_DELETE: { | 354 case SyncChange::ACTION_DELETE: { |
| 330 if (has_key) | 355 if (has_key) |
| 331 update_dict->RemoveWithoutPathExpansion(key, NULL); | 356 update_dict->RemoveWithoutPathExpansion(key, nullptr); |
| 332 else | 357 else |
| 333 NOTREACHED() << "Trying to delete nonexistent key " << key; | 358 NOTREACHED() << "Trying to delete nonexistent key " << key; |
| 334 break; | 359 break; |
| 335 } | 360 } |
| 336 case SyncChange::ACTION_INVALID: { | 361 case SyncChange::ACTION_INVALID: { |
| 337 NOTREACHED(); | 362 NOTREACHED(); |
| 338 break; | 363 break; |
| 339 } | 364 } |
| 340 } | 365 } |
| 341 callbacks_.Notify(su_id, key); | 366 callbacks_.Notify(su_id, key); |
| 342 } | 367 } |
| 343 | 368 |
| 344 SyncError error; | 369 SyncError error; |
| 345 return error; | 370 return error; |
| 346 } | 371 } |
| OLD | NEW |