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

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

Issue 2845113002: Remove raw base::DictionaryValue::SetWithoutPathExpansion in //chrome (Closed)
Patch Set: Address comments Created 3 years, 7 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
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
15 #include "components/pref_registry/pref_registry_syncable.h" 16 #include "components/pref_registry/pref_registry_syncable.h"
16 #include "components/prefs/pref_service.h" 17 #include "components/prefs/pref_service.h"
17 #include "components/prefs/scoped_user_pref_update.h" 18 #include "components/prefs/scoped_user_pref_update.h"
18 #include "components/sync/model/sync_change.h" 19 #include "components/sync/model/sync_change.h"
19 #include "components/sync/model/sync_data.h" 20 #include "components/sync/model/sync_data.h"
20 #include "components/sync/model/sync_error.h" 21 #include "components/sync/model/sync_error.h"
21 #include "components/sync/model/sync_error_factory.h" 22 #include "components/sync/model/sync_error_factory.h"
22 #include "components/sync/model/sync_merge_result.h" 23 #include "components/sync/model/sync_merge_result.h"
(...skipping 14 matching lines...) Expand all
37 38
38 namespace { 39 namespace {
39 40
40 const char kAcknowledged[] = "acknowledged"; 41 const char kAcknowledged[] = "acknowledged";
41 const char kValue[] = "value"; 42 const char kValue[] = "value";
42 43
43 DictionaryValue* FindOrCreateDictionary(DictionaryValue* parent, 44 DictionaryValue* FindOrCreateDictionary(DictionaryValue* parent,
44 const std::string& key) { 45 const std::string& key) {
45 DictionaryValue* dict = nullptr; 46 DictionaryValue* dict = nullptr;
46 if (!parent->GetDictionaryWithoutPathExpansion(key, &dict)) { 47 if (!parent->GetDictionaryWithoutPathExpansion(key, &dict)) {
47 dict = new DictionaryValue; 48 dict = parent->SetDictionaryWithoutPathExpansion(
48 parent->SetWithoutPathExpansion(key, dict); 49 key, base::MakeUnique<base::DictionaryValue>());
49 } 50 }
50 return dict; 51 return dict;
51 } 52 }
52 53
53 class ScopedSupervisedUserSharedSettingsUpdate { 54 class ScopedSupervisedUserSharedSettingsUpdate {
54 public: 55 public:
55 ScopedSupervisedUserSharedSettingsUpdate(PrefService* prefs, 56 ScopedSupervisedUserSharedSettingsUpdate(PrefService* prefs,
56 const std::string& su_id) 57 const std::string& su_id)
57 : update_(prefs, prefs::kSupervisedUserSharedSettings), su_id_(su_id) { 58 : update_(prefs, prefs::kSupervisedUserSharedSettings), su_id_(su_id) {
58 DCHECK(!su_id.empty()); 59 DCHECK(!su_id.empty());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 const std::string& su_id, 104 const std::string& su_id,
104 const std::string& key, 105 const std::string& key,
105 const Value& value, 106 const Value& value,
106 bool acknowledged) { 107 bool acknowledged) {
107 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); 108 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id);
108 DictionaryValue* update_dict = update.Get(); 109 DictionaryValue* update_dict = update.Get();
109 110
110 DictionaryValue* dict = nullptr; 111 DictionaryValue* dict = nullptr;
111 bool has_key = update_dict->GetDictionaryWithoutPathExpansion(key, &dict); 112 bool has_key = update_dict->GetDictionaryWithoutPathExpansion(key, &dict);
112 if (!has_key) { 113 if (!has_key) {
113 dict = new DictionaryValue; 114 dict = update_dict->SetDictionaryWithoutPathExpansion(
114 update_dict->SetWithoutPathExpansion(key, dict); 115 key, base::MakeUnique<base::DictionaryValue>());
115 } 116 }
116 dict->SetWithoutPathExpansion(kValue, value.DeepCopy()); 117 dict->SetWithoutPathExpansion(kValue, base::MakeUnique<base::Value>(value));
117 dict->SetBooleanWithoutPathExpansion(kAcknowledged, acknowledged); 118 dict->SetBooleanWithoutPathExpansion(kAcknowledged, acknowledged);
118 119
119 if (!sync_processor_) 120 if (!sync_processor_)
120 return; 121 return;
121 122
122 SyncData data = CreateSyncDataForSetting(su_id, key, value, acknowledged); 123 SyncData data = CreateSyncDataForSetting(su_id, key, value, acknowledged);
123 SyncChange::SyncChangeType change_type = 124 SyncChange::SyncChangeType change_type =
124 has_key ? SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD; 125 has_key ? SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD;
125 SyncChangeList changes; 126 SyncChangeList changes;
126 changes.push_back(SyncChange(FROM_HERE, change_type, data)); 127 changes.push_back(SyncChange(FROM_HERE, change_type, data));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, sync_data.GetDataType()); 224 DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, sync_data.GetDataType());
224 const ::sync_pb::ManagedUserSharedSettingSpecifics& 225 const ::sync_pb::ManagedUserSharedSettingSpecifics&
225 supervised_user_shared_setting = 226 supervised_user_shared_setting =
226 sync_data.GetSpecifics().managed_user_shared_setting(); 227 sync_data.GetSpecifics().managed_user_shared_setting();
227 std::unique_ptr<Value> value = 228 std::unique_ptr<Value> value =
228 base::JSONReader::Read(supervised_user_shared_setting.value()); 229 base::JSONReader::Read(supervised_user_shared_setting.value());
229 const std::string& su_id = supervised_user_shared_setting.mu_id(); 230 const std::string& su_id = supervised_user_shared_setting.mu_id();
230 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id); 231 ScopedSupervisedUserSharedSettingsUpdate update(prefs_, su_id);
231 const std::string& key = supervised_user_shared_setting.key(); 232 const std::string& key = supervised_user_shared_setting.key();
232 DictionaryValue* dict = FindOrCreateDictionary(update.Get(), key); 233 DictionaryValue* dict = FindOrCreateDictionary(update.Get(), key);
233 dict->SetWithoutPathExpansion(kValue, value.release()); 234 dict->SetWithoutPathExpansion(kValue, std::move(value));
234 235
235 // Every setting we get from the server should have the acknowledged flag 236 // Every setting we get from the server should have the acknowledged flag
236 // set. 237 // set.
237 DCHECK(supervised_user_shared_setting.acknowledged()); 238 DCHECK(supervised_user_shared_setting.acknowledged());
238 dict->SetBooleanWithoutPathExpansion( 239 dict->SetBooleanWithoutPathExpansion(
239 kAcknowledged, supervised_user_shared_setting.acknowledged()); 240 kAcknowledged, supervised_user_shared_setting.acknowledged());
240 callbacks_.Notify(su_id, key); 241 callbacks_.Notify(su_id, key);
241 242
242 if (pref_seen_keys.find(su_id) == pref_seen_keys.end()) 243 if (pref_seen_keys.find(su_id) == pref_seen_keys.end())
243 num_added++; 244 num_added++;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // flag set. 335 // flag set.
335 DCHECK(supervised_user_shared_setting.acknowledged()); 336 DCHECK(supervised_user_shared_setting.acknowledged());
336 337
337 if (has_key) { 338 if (has_key) {
338 // If the supervised user already exists, it should be an update 339 // If the supervised user already exists, it should be an update
339 // action. 340 // action.
340 DCHECK_EQ(SyncChange::ACTION_UPDATE, sync_change.change_type()); 341 DCHECK_EQ(SyncChange::ACTION_UPDATE, sync_change.change_type());
341 } else { 342 } else {
342 // Otherwise, it should be an add action. 343 // Otherwise, it should be an add action.
343 DCHECK_EQ(SyncChange::ACTION_ADD, sync_change.change_type()); 344 DCHECK_EQ(SyncChange::ACTION_ADD, sync_change.change_type());
344 dict = new DictionaryValue; 345 dict = update_dict->SetDictionaryWithoutPathExpansion(
345 update_dict->SetWithoutPathExpansion(key, dict); 346 key, base::MakeUnique<base::DictionaryValue>());
346 } 347 }
347 std::unique_ptr<Value> value = 348 std::unique_ptr<Value> value =
348 base::JSONReader::Read(supervised_user_shared_setting.value()); 349 base::JSONReader::Read(supervised_user_shared_setting.value());
349 dict->SetWithoutPathExpansion(kValue, value.release()); 350 dict->SetWithoutPathExpansion(kValue, std::move(value));
350 dict->SetBooleanWithoutPathExpansion( 351 dict->SetBooleanWithoutPathExpansion(
351 kAcknowledged, supervised_user_shared_setting.acknowledged()); 352 kAcknowledged, supervised_user_shared_setting.acknowledged());
352 break; 353 break;
353 } 354 }
354 case SyncChange::ACTION_DELETE: { 355 case SyncChange::ACTION_DELETE: {
355 if (has_key) 356 if (has_key)
356 update_dict->RemoveWithoutPathExpansion(key, nullptr); 357 update_dict->RemoveWithoutPathExpansion(key, nullptr);
357 else 358 else
358 NOTREACHED() << "Trying to delete nonexistent key " << key; 359 NOTREACHED() << "Trying to delete nonexistent key " << key;
359 break; 360 break;
360 } 361 }
361 case SyncChange::ACTION_INVALID: { 362 case SyncChange::ACTION_INVALID: {
362 NOTREACHED(); 363 NOTREACHED();
363 break; 364 break;
364 } 365 }
365 } 366 }
366 callbacks_.Notify(su_id, key); 367 callbacks_.Notify(su_id, key);
367 } 368 }
368 369
369 SyncError error; 370 SyncError error;
370 return error; 371 return error;
371 } 372 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698