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/supervised_user_settings_service.h" | 5 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 store_->ReportValueChanged(kAtomicSettings, | 208 store_->ReportValueChanged(kAtomicSettings, |
209 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 209 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
210 store_->ReportValueChanged(kSplitSettings, | 210 store_->ReportValueChanged(kSplitSettings, |
211 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 211 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
212 InformSubscribers(); | 212 InformSubscribers(); |
213 | 213 |
214 // Upload all the queued up items (either with an ADD or an UPDATE action, | 214 // Upload all the queued up items (either with an ADD or an UPDATE action, |
215 // depending on whether they already exist) and move them to split settings. | 215 // depending on whether they already exist) and move them to split settings. |
216 SyncChangeList change_list; | 216 SyncChangeList change_list; |
217 base::DictionaryValue* queued_items = GetQueuedItems(); | 217 base::DictionaryValue* queued_items = GetQueuedItems(); |
218 int num_added = 0; | |
219 int num_modified = 0; | |
220 int num_before_association = queued_items->size(); | |
Bernhard Bauer
2016/01/05 09:37:30
This also doesn't seem quite right... This is only
Deepak
2016/01/05 13:29:19
I would like to do the changes of this file in sep
Bernhard Bauer
2016/01/05 14:10:54
Acknowledged.
| |
218 for (base::DictionaryValue::Iterator it(*queued_items); !it.IsAtEnd(); | 221 for (base::DictionaryValue::Iterator it(*queued_items); !it.IsAtEnd(); |
219 it.Advance()) { | 222 it.Advance()) { |
220 std::string key_suffix = it.key(); | 223 std::string key_suffix = it.key(); |
221 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key_suffix); | 224 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key_suffix); |
222 SyncData data = CreateSyncDataForSetting(it.key(), it.value()); | 225 SyncData data = CreateSyncDataForSetting(it.key(), it.value()); |
223 SyncChange::SyncChangeType change_type = | 226 SyncChange::SyncChangeType change_type = |
224 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE | 227 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE |
225 : SyncChange::ACTION_ADD; | 228 : SyncChange::ACTION_ADD; |
229 if (change_type == SyncChange::ACTION_ADD) | |
230 num_added++; | |
231 else | |
232 num_modified++; | |
226 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); | 233 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); |
227 dict->SetWithoutPathExpansion(key_suffix, it.value().DeepCopy()); | 234 dict->SetWithoutPathExpansion(key_suffix, it.value().DeepCopy()); |
228 } | 235 } |
229 queued_items->Clear(); | 236 queued_items->Clear(); |
230 | 237 |
231 SyncMergeResult result(SUPERVISED_USER_SETTINGS); | 238 SyncMergeResult result(SUPERVISED_USER_SETTINGS); |
232 // Process all the accumulated changes from the queued items. | 239 // Process all the accumulated changes from the queued items. |
233 if (change_list.size() > 0) { | 240 if (change_list.size() > 0) { |
234 store_->ReportValueChanged(kQueuedItems, | 241 store_->ReportValueChanged(kQueuedItems, |
235 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 242 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
236 result.set_error( | 243 result.set_error( |
237 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); | 244 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); |
238 } | 245 } |
239 | 246 |
240 // TODO(bauerb): Statistics? | 247 result.set_num_items_added(num_added); |
248 result.set_num_items_modified(num_modified); | |
249 result.set_num_items_before_association(num_before_association); | |
250 result.set_num_items_after_association(num_added + num_modified); | |
241 return result; | 251 return result; |
242 } | 252 } |
243 | 253 |
244 void SupervisedUserSettingsService::StopSyncing(ModelType type) { | 254 void SupervisedUserSettingsService::StopSyncing(ModelType type) { |
245 DCHECK_EQ(syncer::SUPERVISED_USER_SETTINGS, type); | 255 DCHECK_EQ(syncer::SUPERVISED_USER_SETTINGS, type); |
246 sync_processor_.reset(); | 256 sync_processor_.reset(); |
247 error_handler_.reset(); | 257 error_handler_.reset(); |
248 } | 258 } |
249 | 259 |
250 SyncDataList SupervisedUserSettingsService::GetAllSyncData( | 260 SyncDataList SupervisedUserSettingsService::GetAllSyncData( |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 return settings; | 420 return settings; |
411 } | 421 } |
412 | 422 |
413 void SupervisedUserSettingsService::InformSubscribers() { | 423 void SupervisedUserSettingsService::InformSubscribers() { |
414 if (!IsReady()) | 424 if (!IsReady()) |
415 return; | 425 return; |
416 | 426 |
417 scoped_ptr<base::DictionaryValue> settings = GetSettings(); | 427 scoped_ptr<base::DictionaryValue> settings = GetSettings(); |
418 callback_list_.Notify(settings.get()); | 428 callback_list_.Notify(settings.get()); |
419 } | 429 } |
OLD | NEW |