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

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

Issue 1878143002: Convert //chrome/browser/supervised_user from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
157 157
158 scoped_ptr< 158 std::unique_ptr<
159 SupervisedUserSharedSettingsService::ChangeCallbackList::Subscription> 159 SupervisedUserSharedSettingsService::ChangeCallbackList::Subscription>
160 SupervisedUserSharedSettingsService::Subscribe( 160 SupervisedUserSharedSettingsService::Subscribe(
161 const SupervisedUserSharedSettingsService::ChangeCallback& cb) { 161 const SupervisedUserSharedSettingsService::ChangeCallback& cb) {
162 return callbacks_.Add(cb); 162 return callbacks_.Add(cb);
163 } 163 }
164 164
165 // static 165 // static
166 void SupervisedUserSharedSettingsService::RegisterProfilePrefs( 166 void SupervisedUserSharedSettingsService::RegisterProfilePrefs(
167 user_prefs::PrefRegistrySyncable* registry) { 167 user_prefs::PrefRegistrySyncable* registry) {
168 registry->RegisterDictionaryPref(prefs::kSupervisedUserSharedSettings); 168 registry->RegisterDictionaryPref(prefs::kSupervisedUserSharedSettings);
(...skipping 16 matching lines...) Expand all
185 std::string title = su_id + ":" + key; 185 std::string title = su_id + ":" + key;
186 return SyncData::CreateLocalData(title, title, specifics); 186 return SyncData::CreateLocalData(title, title, specifics);
187 } 187 }
188 188
189 void SupervisedUserSharedSettingsService::Shutdown() {} 189 void SupervisedUserSharedSettingsService::Shutdown() {}
190 190
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 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor,
196 scoped_ptr<syncer::SyncErrorFactory> error_handler) { 196 std::unique_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; 201 int num_before_association = 0;
202 std::map<std::string, std::set<std::string> > pref_seen_keys; 202 std::map<std::string, std::set<std::string> > pref_seen_keys;
203 const DictionaryValue* pref_dict = 203 const DictionaryValue* pref_dict =
204 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings); 204 prefs_->GetDictionary(prefs::kSupervisedUserSharedSettings);
205 for (DictionaryValue::Iterator it(*pref_dict); !it.IsAtEnd(); it.Advance()) { 205 for (DictionaryValue::Iterator it(*pref_dict); !it.IsAtEnd(); it.Advance()) {
206 const DictionaryValue* dict = nullptr; 206 const DictionaryValue* dict = nullptr;
(...skipping 10 matching lines...) Expand all
217 int num_added = 0; 217 int num_added = 0;
218 int num_modified = 0; 218 int num_modified = 0;
219 219
220 // 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
221 // the value from the server always wins over a local value. 221 // the value from the server always wins over a local value.
222 for (const SyncData& sync_data : initial_sync_data) { 222 for (const SyncData& sync_data : initial_sync_data) {
223 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, sync_data.GetDataType()); 223 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, sync_data.GetDataType());
224 const ::sync_pb::ManagedUserSharedSettingSpecifics& 224 const ::sync_pb::ManagedUserSharedSettingSpecifics&
225 supervised_user_shared_setting = 225 supervised_user_shared_setting =
226 sync_data.GetSpecifics().managed_user_shared_setting(); 226 sync_data.GetSpecifics().managed_user_shared_setting();
227 scoped_ptr<Value> value = 227 std::unique_ptr<Value> value =
228 base::JSONReader::Read(supervised_user_shared_setting.value()); 228 base::JSONReader::Read(supervised_user_shared_setting.value());
229 const std::string& su_id = supervised_user_shared_setting.mu_id(); 229 const std::string& su_id = supervised_user_shared_setting.mu_id();
230 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); 230 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id);
231 const std::string& key = supervised_user_shared_setting.key(); 231 const std::string& key = supervised_user_shared_setting.key();
232 DictionaryValue* dict = FindOrCreateDictionary(update.Get(), key); 232 DictionaryValue* dict = FindOrCreateDictionary(update.Get(), key);
233 dict->SetWithoutPathExpansion(kValue, value.release()); 233 dict->SetWithoutPathExpansion(kValue, value.release());
234 234
235 // 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
236 // set. 236 // set.
237 DCHECK(supervised_user_shared_setting.acknowledged()); 237 DCHECK(supervised_user_shared_setting.acknowledged());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 if (has_key) { 337 if (has_key) {
338 // If the supervised user already exists, it should be an update 338 // If the supervised user already exists, it should be an update
339 // action. 339 // action.
340 DCHECK_EQ(SyncChange::ACTION_UPDATE, sync_change.change_type()); 340 DCHECK_EQ(SyncChange::ACTION_UPDATE, sync_change.change_type());
341 } else { 341 } else {
342 // Otherwise, it should be an add action. 342 // Otherwise, it should be an add action.
343 DCHECK_EQ(SyncChange::ACTION_ADD, sync_change.change_type()); 343 DCHECK_EQ(SyncChange::ACTION_ADD, sync_change.change_type());
344 dict = new DictionaryValue; 344 dict = new DictionaryValue;
345 update_dict->SetWithoutPathExpansion(key, dict); 345 update_dict->SetWithoutPathExpansion(key, dict);
346 } 346 }
347 scoped_ptr<Value> value = 347 std::unique_ptr<Value> value =
348 base::JSONReader::Read(supervised_user_shared_setting.value()); 348 base::JSONReader::Read(supervised_user_shared_setting.value());
349 dict->SetWithoutPathExpansion(kValue, value.release()); 349 dict->SetWithoutPathExpansion(kValue, value.release());
350 dict->SetBooleanWithoutPathExpansion( 350 dict->SetBooleanWithoutPathExpansion(
351 kAcknowledged, supervised_user_shared_setting.acknowledged()); 351 kAcknowledged, supervised_user_shared_setting.acknowledged());
352 break; 352 break;
353 } 353 }
354 case SyncChange::ACTION_DELETE: { 354 case SyncChange::ACTION_DELETE: {
355 if (has_key) 355 if (has_key)
356 update_dict->RemoveWithoutPathExpansion(key, nullptr); 356 update_dict->RemoveWithoutPathExpansion(key, nullptr);
357 else 357 else
358 NOTREACHED() << "Trying to delete nonexistent key " << key; 358 NOTREACHED() << "Trying to delete nonexistent key " << key;
359 break; 359 break;
360 } 360 }
361 case SyncChange::ACTION_INVALID: { 361 case SyncChange::ACTION_INVALID: {
362 NOTREACHED(); 362 NOTREACHED();
363 break; 363 break;
364 } 364 }
365 } 365 }
366 callbacks_.Notify(su_id, key); 366 callbacks_.Notify(su_id, key);
367 } 367 }
368 368
369 SyncError error; 369 SyncError error;
370 return error; 370 return error;
371 } 371 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698