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

Side by Side Diff: chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service.cc

Issue 1530763004: Add Statistics for SupervisedUserSettingService during merging and syncing data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. 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
« no previous file with comments | « no previous file | chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_added = 0;
202 int num_modified = 0;
203 int num_before_association = 0;
204 std::map<std::string, std::set<std::string> > pref_seen_keys;
205 const DictionaryValue* pref_dict =
206 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings);
207 for (DictionaryValue::Iterator it(*pref_dict); !it.IsAtEnd(); it.Advance()) {
208 const DictionaryValue* dict = NULL;
Bernhard Bauer 2016/01/07 10:04:29 Use nullptr instead of NULL.
Deepak 2016/01/07 10:40:07 Done.
209 bool success = it.value().GetAsDictionary(&dict);
210 DCHECK(success);
211 num_before_association += dict->size();
212 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance())
213 pref_seen_keys[it.key()].insert(jt.key());
214 }
215
201 // We keep a map from MU ID to the set of keys that we have seen in the 216 // We keep a map from MU ID to the set of keys that we have seen in the
202 // initial sync data. 217 // initial sync data.
203 std::map<std::string, std::set<std::string> > seen_keys; 218 std::map<std::string, std::set<std::string> > seen_keys;
Bernhard Bauer 2016/01/07 10:04:29 Rename this to |sync_seen_keys| to distinguish it
Deepak 2016/01/07 10:40:07 Done.
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
242 if (pref_seen_keys.find(su_id) == pref_seen_keys.end())
243 num_added++;
244 else
245 num_modified++;
246
227 seen_keys[su_id].insert(key); 247 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 |seen_keys|.
232 SyncChangeList change_list; 252 SyncChangeList change_list;
233 const DictionaryValue* all_settings = 253 const DictionaryValue* all_settings =
234 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); 254 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings);
235 for (DictionaryValue::Iterator it(*all_settings); !it.IsAtEnd(); 255 for (DictionaryValue::Iterator it(*all_settings); !it.IsAtEnd();
236 it.Advance()) { 256 it.Advance()) {
237 const DictionaryValue* dict = NULL; 257 const DictionaryValue* dict = NULL;
Bernhard Bauer 2016/01/07 10:04:29 Could you update this to nullptr as well? Thanks!
Deepak 2016/01/07 10:40:07 Done.
238 bool success = it.value().GetAsDictionary(&dict); 258 bool success = it.value().GetAsDictionary(&dict);
239 DCHECK(success); 259 DCHECK(success);
240 260
241 const std::set<std::string>& seen = seen_keys[it.key()]; 261 const std::set<std::string>& seen = seen_keys[it.key()];
242 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) { 262 for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) {
243 // We only need to upload settings that we haven't seen in the initial 263 // We only need to upload settings that we haven't seen in the initial
244 // sync data (which means they were added locally). 264 // sync data (which means they were added locally).
245 if (seen.count(jt.key()) > 0) 265 if (seen.count(jt.key()) > 0)
246 continue; 266 continue;
247 267
248 SyncData data = CreateSyncDataForValue(it.key(), jt.key(), jt.value()); 268 SyncData data = CreateSyncDataForValue(it.key(), jt.key(), jt.value());
249 DCHECK(data.IsValid()); 269 DCHECK(data.IsValid());
250 change_list.push_back( 270 change_list.push_back(
251 SyncChange(FROM_HERE, SyncChange::ACTION_ADD, data)); 271 SyncChange(FROM_HERE, SyncChange::ACTION_ADD, data));
252 } 272 }
253 } 273 }
254 274
255 SyncMergeResult result(SUPERVISED_USER_SHARED_SETTINGS); 275 SyncMergeResult result(SUPERVISED_USER_SHARED_SETTINGS);
256 // Process all the accumulated changes. 276 // Process all the accumulated changes.
257 if (change_list.size() > 0) { 277 if (change_list.size() > 0) {
258 result.set_error( 278 result.set_error(
259 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); 279 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list));
260 } 280 }
261 281
262 // TODO(bauerb): Statistics? 282 result.set_num_items_added(num_added);
283 result.set_num_items_modified(num_modified);
284 result.set_num_items_before_association(num_before_association);
285 result.set_num_items_after_association(num_before_association + num_added);
Bernhard Bauer 2016/01/07 10:04:29 Let's not do this, please. If we have a bug in the
Deepak 2016/01/07 10:40:07 I got your point. Thanks
263 return result; 286 return result;
264 } 287 }
265 288
266 void SupervisedUserSharedSettingsService::StopSyncing(syncer::ModelType type) { 289 void SupervisedUserSharedSettingsService::StopSyncing(syncer::ModelType type) {
267 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type); 290 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, type);
268 sync_processor_.reset(); 291 sync_processor_.reset();
269 error_handler_.reset(); 292 error_handler_.reset();
270 } 293 }
271 294
272 syncer::SyncDataList SupervisedUserSharedSettingsService::GetAllSyncData( 295 syncer::SyncDataList SupervisedUserSharedSettingsService::GetAllSyncData(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 NOTREACHED(); 360 NOTREACHED();
338 break; 361 break;
339 } 362 }
340 } 363 }
341 callbacks_.Notify(su_id, key); 364 callbacks_.Notify(su_id, key);
342 } 365 }
343 366
344 SyncError error; 367 SyncError error;
345 return error; 368 return error;
346 } 369 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698