Index: chrome/browser/supervised_user/supervised_user_settings_service.cc |
diff --git a/chrome/browser/supervised_user/supervised_user_settings_service.cc b/chrome/browser/supervised_user/supervised_user_settings_service.cc |
index db09106b4e5df4dd6792f75746f69d280395fa07..642205fb64edc0e6820d00770ef938f5ab0b8f85 100644 |
--- a/chrome/browser/supervised_user/supervised_user_settings_service.cc |
+++ b/chrome/browser/supervised_user/supervised_user_settings_service.cc |
@@ -193,8 +193,31 @@ SyncMergeResult SupervisedUserSettingsService::MergeDataAndStartSyncing( |
sync_processor_ = std::move(sync_processor); |
error_handler_ = std::move(error_handler); |
+ std::map<std::string, std::string> seen_keys; |
+ int num_before_association = GetAtomicSettings()->size(); |
+ for (base::DictionaryValue::Iterator it(*GetAtomicSettings()); !it.IsAtEnd(); |
+ it.Advance()) { |
+ std::string json_value; |
+ base::JSONWriter::Write(it.value(), &json_value); |
+ seen_keys[it.key()] = json_value; |
+ } |
+ for (base::DictionaryValue::Iterator it(*GetSplitSettings()); !it.IsAtEnd(); |
+ it.Advance()) { |
+ const base::DictionaryValue* dict = nullptr; |
+ it.value().GetAsDictionary(&dict); |
+ num_before_association += dict->size(); |
+ for (base::DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); |
+ jt.Advance()) { |
+ std::string json_value; |
+ base::JSONWriter::Write(jt.value(), &json_value); |
Bernhard Bauer
2016/01/08 16:04:46
You serialize the values and then compare them bel
Deepak
2016/01/11 10:38:36
Done.
|
+ seen_keys[MakeSplitSettingKey(it.key(), jt.key())] = json_value; |
+ } |
+ } |
+ |
// Clear all atomic and split settings, then recreate them from Sync data. |
Clear(); |
+ int num_added = 0; |
+ int num_modified = 0; |
for (const SyncData& sync_data : initial_sync_data) { |
DCHECK_EQ(SUPERVISED_USER_SETTINGS, sync_data.GetDataType()); |
const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting = |
@@ -202,9 +225,22 @@ SyncMergeResult SupervisedUserSettingsService::MergeDataAndStartSyncing( |
scoped_ptr<base::Value> value = |
JSONReader::Read(supervised_user_setting.value()); |
std::string name_suffix = supervised_user_setting.name(); |
+ std::string name_key = name_suffix; |
base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix); |
dict->SetWithoutPathExpansion(name_suffix, value.release()); |
+ |
+ if (seen_keys.find(name_key) == seen_keys.end()) { |
+ num_added++; |
+ } else { |
+ for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) { |
+ std::string json_value; |
Bernhard Bauer
2016/01/08 16:04:46
This is identical to supervised_user_setting.value
Deepak
2016/01/11 10:38:36
Done.
|
+ base::JSONWriter::Write(jt.value(), &json_value); |
+ if (seen_keys[name_key] != json_value) |
+ num_modified++; |
+ } |
+ } |
} |
+ |
store_->ReportValueChanged(kAtomicSettings, |
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
store_->ReportValueChanged(kSplitSettings, |
@@ -237,7 +273,11 @@ SyncMergeResult SupervisedUserSettingsService::MergeDataAndStartSyncing( |
sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); |
} |
- // TODO(bauerb): Statistics? |
+ result.set_num_items_added(num_added); |
+ result.set_num_items_modified(num_modified); |
+ result.set_num_items_deleted(num_before_association - num_modified); |
+ result.set_num_items_before_association(num_before_association); |
+ result.set_num_items_after_association(GetAllSyncData(type).size()); |
Bernhard Bauer
2016/01/08 16:04:46
This is clever, but I'm a bit wary that this does
Deepak
2016/01/11 10:38:36
Done.
|
return result; |
} |