Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: chrome/browser/supervised_user/supervised_user_settings_service.cc

Issue 1563833002: [Part-2]Add Statistics for SupervisedUserSettingService during merging and syncing data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 SyncMergeResult SupervisedUserSettingsService::MergeDataAndStartSyncing( 187 SyncMergeResult SupervisedUserSettingsService::MergeDataAndStartSyncing(
188 ModelType type, 188 ModelType type,
189 const SyncDataList& initial_sync_data, 189 const SyncDataList& initial_sync_data,
190 scoped_ptr<SyncChangeProcessor> sync_processor, 190 scoped_ptr<SyncChangeProcessor> sync_processor,
191 scoped_ptr<SyncErrorFactory> error_handler) { 191 scoped_ptr<SyncErrorFactory> error_handler) {
192 DCHECK_EQ(SUPERVISED_USER_SETTINGS, type); 192 DCHECK_EQ(SUPERVISED_USER_SETTINGS, type);
193 sync_processor_ = std::move(sync_processor); 193 sync_processor_ = std::move(sync_processor);
194 error_handler_ = std::move(error_handler); 194 error_handler_ = std::move(error_handler);
195 195
196 std::map<std::string, std::string> seen_keys;
197 int num_before_association = GetAtomicSettings()->size();
198 for (base::DictionaryValue::Iterator it(*GetAtomicSettings()); !it.IsAtEnd();
199 it.Advance()) {
200 std::string json_value;
201 base::JSONWriter::Write(it.value(), &json_value);
202 seen_keys[it.key()] = json_value;
203 }
204 for (base::DictionaryValue::Iterator it(*GetSplitSettings()); !it.IsAtEnd();
205 it.Advance()) {
206 const base::DictionaryValue* dict = nullptr;
207 it.value().GetAsDictionary(&dict);
208 num_before_association += dict->size();
209 for (base::DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd();
210 jt.Advance()) {
211 std::string json_value;
212 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.
213 seen_keys[MakeSplitSettingKey(it.key(), jt.key())] = json_value;
214 }
215 }
216
196 // Clear all atomic and split settings, then recreate them from Sync data. 217 // Clear all atomic and split settings, then recreate them from Sync data.
197 Clear(); 218 Clear();
219 int num_added = 0;
220 int num_modified = 0;
198 for (const SyncData& sync_data : initial_sync_data) { 221 for (const SyncData& sync_data : initial_sync_data) {
199 DCHECK_EQ(SUPERVISED_USER_SETTINGS, sync_data.GetDataType()); 222 DCHECK_EQ(SUPERVISED_USER_SETTINGS, sync_data.GetDataType());
200 const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting = 223 const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting =
201 sync_data.GetSpecifics().managed_user_setting(); 224 sync_data.GetSpecifics().managed_user_setting();
202 scoped_ptr<base::Value> value = 225 scoped_ptr<base::Value> value =
203 JSONReader::Read(supervised_user_setting.value()); 226 JSONReader::Read(supervised_user_setting.value());
204 std::string name_suffix = supervised_user_setting.name(); 227 std::string name_suffix = supervised_user_setting.name();
228 std::string name_key = name_suffix;
205 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix); 229 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix);
206 dict->SetWithoutPathExpansion(name_suffix, value.release()); 230 dict->SetWithoutPathExpansion(name_suffix, value.release());
231
232 if (seen_keys.find(name_key) == seen_keys.end()) {
233 num_added++;
234 } else {
235 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) {
236 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.
237 base::JSONWriter::Write(jt.value(), &json_value);
238 if (seen_keys[name_key] != json_value)
239 num_modified++;
240 }
241 }
207 } 242 }
243
208 store_->ReportValueChanged(kAtomicSettings, 244 store_->ReportValueChanged(kAtomicSettings,
209 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 245 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
210 store_->ReportValueChanged(kSplitSettings, 246 store_->ReportValueChanged(kSplitSettings,
211 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 247 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
212 InformSubscribers(); 248 InformSubscribers();
213 249
214 // Upload all the queued up items (either with an ADD or an UPDATE action, 250 // 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. 251 // depending on whether they already exist) and move them to split settings.
Bernhard Bauer 2016/01/08 16:04:46 As you mention in the CL message, you ignore queue
Deepak 2016/01/11 10:38:36 I thought that we should consider that things that
Bernhard Bauer 2016/01/18 17:56:56 That is the data from Sync. The number of items be
216 SyncChangeList change_list; 252 SyncChangeList change_list;
217 base::DictionaryValue* queued_items = GetQueuedItems(); 253 base::DictionaryValue* queued_items = GetQueuedItems();
218 for (base::DictionaryValue::Iterator it(*queued_items); !it.IsAtEnd(); 254 for (base::DictionaryValue::Iterator it(*queued_items); !it.IsAtEnd();
219 it.Advance()) { 255 it.Advance()) {
220 std::string key_suffix = it.key(); 256 std::string key_suffix = it.key();
221 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key_suffix); 257 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key_suffix);
222 SyncData data = CreateSyncDataForSetting(it.key(), it.value()); 258 SyncData data = CreateSyncDataForSetting(it.key(), it.value());
223 SyncChange::SyncChangeType change_type = 259 SyncChange::SyncChangeType change_type =
224 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE 260 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE
225 : SyncChange::ACTION_ADD; 261 : SyncChange::ACTION_ADD;
226 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); 262 change_list.push_back(SyncChange(FROM_HERE, change_type, data));
227 dict->SetWithoutPathExpansion(key_suffix, it.value().DeepCopy()); 263 dict->SetWithoutPathExpansion(key_suffix, it.value().DeepCopy());
228 } 264 }
229 queued_items->Clear(); 265 queued_items->Clear();
230 266
231 SyncMergeResult result(SUPERVISED_USER_SETTINGS); 267 SyncMergeResult result(SUPERVISED_USER_SETTINGS);
232 // Process all the accumulated changes from the queued items. 268 // Process all the accumulated changes from the queued items.
233 if (change_list.size() > 0) { 269 if (change_list.size() > 0) {
234 store_->ReportValueChanged(kQueuedItems, 270 store_->ReportValueChanged(kQueuedItems,
235 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 271 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
236 result.set_error( 272 result.set_error(
237 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); 273 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list));
238 } 274 }
239 275
240 // TODO(bauerb): Statistics? 276 result.set_num_items_added(num_added);
277 result.set_num_items_modified(num_modified);
278 result.set_num_items_deleted(num_before_association - num_modified);
279 result.set_num_items_before_association(num_before_association);
280 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.
241 return result; 281 return result;
242 } 282 }
243 283
244 void SupervisedUserSettingsService::StopSyncing(ModelType type) { 284 void SupervisedUserSettingsService::StopSyncing(ModelType type) {
245 DCHECK_EQ(syncer::SUPERVISED_USER_SETTINGS, type); 285 DCHECK_EQ(syncer::SUPERVISED_USER_SETTINGS, type);
246 sync_processor_.reset(); 286 sync_processor_.reset();
247 error_handler_.reset(); 287 error_handler_.reset();
248 } 288 }
249 289
250 SyncDataList SupervisedUserSettingsService::GetAllSyncData( 290 SyncDataList SupervisedUserSettingsService::GetAllSyncData(
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 return settings; 450 return settings;
411 } 451 }
412 452
413 void SupervisedUserSettingsService::InformSubscribers() { 453 void SupervisedUserSettingsService::InformSubscribers() {
414 if (!IsReady()) 454 if (!IsReady())
415 return; 455 return;
416 456
417 scoped_ptr<base::DictionaryValue> settings = GetSettings(); 457 scoped_ptr<base::DictionaryValue> settings = GetSettings();
418 callback_list_.Notify(settings.get()); 458 callback_list_.Notify(settings.get());
419 } 459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698