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

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

Issue 2004043002: Supervised Users Initiated Installs v2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kid_initiated_install
Patch Set: Response to code review by treib@ Created 4 years, 6 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 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 std::string SupervisedUserSettingsService::MakeSplitSettingKey( 128 std::string SupervisedUserSettingsService::MakeSplitSettingKey(
129 const std::string& prefix, 129 const std::string& prefix,
130 const std::string& key) { 130 const std::string& key) {
131 return prefix + kSplitSettingKeySeparator + key; 131 return prefix + kSplitSettingKeySeparator + key;
132 } 132 }
133 133
134 void SupervisedUserSettingsService::UploadItem( 134 void SupervisedUserSettingsService::UploadItem(
135 const std::string& key, 135 const std::string& key,
136 std::unique_ptr<base::Value> value) { 136 std::unique_ptr<base::Value> value) {
137 DCHECK(!SettingShouldApplyToPrefs(key)); 137 DCHECK(!SettingShouldApplyToPrefs(key));
138 PushItemToSync(key, std::move(value));
139 }
138 140
141 void SupervisedUserSettingsService::UpdateSetting(
142 const std::string& key,
143 std::unique_ptr<base::Value> value) {
144 PushItemToSync(key, std::move(value));
145 InformSubscribers();
146 }
147
148 void SupervisedUserSettingsService::PushItemToSync(
149 const std::string& key,
150 std::unique_ptr<base::Value> value) {
139 std::string key_suffix = key; 151 std::string key_suffix = key;
140 base::DictionaryValue* dict = nullptr; 152 base::DictionaryValue* dict = nullptr;
141 if (sync_processor_) { 153 if (sync_processor_) {
142 content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Syncing")); 154 content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Syncing"));
143 dict = GetDictionaryAndSplitKey(&key_suffix); 155 dict = GetDictionaryAndSplitKey(&key_suffix);
144 DCHECK(GetQueuedItems()->empty()); 156 DCHECK(GetQueuedItems()->empty());
145 SyncChangeList change_list; 157 SyncChangeList change_list;
146 SyncData data = CreateSyncDataForSetting(key, *value); 158 SyncData data = CreateSyncDataForSetting(key, *value);
147 SyncChange::SyncChangeType change_type = 159 SyncChange::SyncChangeType change_type =
148 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE 160 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE
149 : SyncChange::ACTION_ADD; 161 : SyncChange::ACTION_ADD;
150 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); 162 change_list.push_back(SyncChange(FROM_HERE, change_type, data));
151 SyncError error = 163 SyncError error =
152 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); 164 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list);
153 DCHECK(!error.IsSet()) << error.ToString(); 165 DCHECK(!error.IsSet()) << error.ToString();
154 } else { 166 } else {
155 // Queue the item up to be uploaded when we start syncing 167 // Queue the item up to be uploaded when we start syncing
156 // (in MergeDataAndStartSyncing()). 168 // (in MergeDataAndStartSyncing()).
157 content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Queued")); 169 content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Queued"));
158 dict = GetQueuedItems(); 170 dict = GetQueuedItems();
159 } 171 }
160 dict->SetWithoutPathExpansion(key_suffix, value.release()); 172 dict->SetWithoutPathExpansion(key_suffix, value.release());
Marc Treib 2016/06/08 12:08:25 Not your doing, but could you use std::move(value)
mamir 2016/06/09 14:04:39 Done.
161 } 173 }
162 174
163 void SupervisedUserSettingsService::SetLocalSetting( 175 void SupervisedUserSettingsService::SetLocalSetting(
164 const std::string& key, 176 const std::string& key,
165 std::unique_ptr<base::Value> value) { 177 std::unique_ptr<base::Value> value) {
166 if (value) 178 if (value)
167 local_settings_->SetWithoutPathExpansion(key, value.release()); 179 local_settings_->SetWithoutPathExpansion(key, value.release());
168 else 180 else
169 local_settings_->RemoveWithoutPathExpansion(key, nullptr); 181 local_settings_->RemoveWithoutPathExpansion(key, nullptr);
170 182
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 return settings; 486 return settings;
475 } 487 }
476 488
477 void SupervisedUserSettingsService::InformSubscribers() { 489 void SupervisedUserSettingsService::InformSubscribers() {
478 if (!IsReady()) 490 if (!IsReady())
479 return; 491 return;
480 492
481 std::unique_ptr<base::DictionaryValue> settings = GetSettings(); 493 std::unique_ptr<base::DictionaryValue> settings = GetSettings();
482 callback_list_.Notify(settings.get()); 494 callback_list_.Notify(settings.get());
483 } 495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698