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

Side by Side Diff: chrome/browser/managed_mode/managed_user_settings_service.cc

Issue 316863002: Rename "managed (mode|user)" to "supervised user" (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/managed_mode/managed_user_settings_service.h" 5 #include "chrome/browser/managed_mode/managed_user_settings_service.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/prefs/json_pref_store.h" 10 #include "base/prefs/json_pref_store.h"
11 #include "base/prefs/pref_filter.h" 11 #include "base/prefs/pref_filter.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" 14 #include "chrome/browser/managed_mode/managed_mode_url_filter.h"
15 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/user_metrics.h" 17 #include "content/public/browser/user_metrics.h"
18 #include "sync/api/sync_change.h" 18 #include "sync/api/sync_change.h"
19 #include "sync/api/sync_error_factory.h" 19 #include "sync/api/sync_error_factory.h"
20 #include "sync/protocol/sync.pb.h" 20 #include "sync/protocol/sync.pb.h"
21 21
22 using base::DictionaryValue; 22 using base::DictionaryValue;
23 using base::JSONReader; 23 using base::JSONReader;
24 using base::UserMetricsAction; 24 using base::UserMetricsAction;
25 using base::Value; 25 using base::Value;
26 using content::BrowserThread; 26 using content::BrowserThread;
27 using syncer::MANAGED_USER_SETTINGS; 27 using syncer::SUPERVISED_USER_SETTINGS;
28 using syncer::ModelType; 28 using syncer::ModelType;
29 using syncer::SyncChange; 29 using syncer::SyncChange;
30 using syncer::SyncChangeList; 30 using syncer::SyncChangeList;
31 using syncer::SyncChangeProcessor; 31 using syncer::SyncChangeProcessor;
32 using syncer::SyncData; 32 using syncer::SyncData;
33 using syncer::SyncDataList; 33 using syncer::SyncDataList;
34 using syncer::SyncError; 34 using syncer::SyncError;
35 using syncer::SyncErrorFactory; 35 using syncer::SyncErrorFactory;
36 using syncer::SyncMergeResult; 36 using syncer::SyncMergeResult;
37 37
(...skipping 14 matching lines...) Expand all
52 ManagedUserSettingsService::ManagedUserSettingsService() 52 ManagedUserSettingsService::ManagedUserSettingsService()
53 : active_(false), local_settings_(new base::DictionaryValue) {} 53 : active_(false), local_settings_(new base::DictionaryValue) {}
54 54
55 ManagedUserSettingsService::~ManagedUserSettingsService() {} 55 ManagedUserSettingsService::~ManagedUserSettingsService() {}
56 56
57 void ManagedUserSettingsService::Init( 57 void ManagedUserSettingsService::Init(
58 base::FilePath profile_path, 58 base::FilePath profile_path,
59 base::SequencedTaskRunner* sequenced_task_runner, 59 base::SequencedTaskRunner* sequenced_task_runner,
60 bool load_synchronously) { 60 bool load_synchronously) {
61 base::FilePath path = 61 base::FilePath path =
62 profile_path.Append(chrome::kManagedUserSettingsFilename); 62 profile_path.Append(chrome::kSupervisedUserSettingsFilename);
63 PersistentPrefStore* store = new JsonPrefStore( 63 PersistentPrefStore* store = new JsonPrefStore(
64 path, sequenced_task_runner, scoped_ptr<PrefFilter>()); 64 path, sequenced_task_runner, scoped_ptr<PrefFilter>());
65 Init(store); 65 Init(store);
66 if (load_synchronously) 66 if (load_synchronously)
67 store_->ReadPrefs(); 67 store_->ReadPrefs();
68 else 68 else
69 store_->ReadPrefsAsync(NULL); 69 store_->ReadPrefsAsync(NULL);
70 } 70 }
71 71
72 void ManagedUserSettingsService::Init( 72 void ManagedUserSettingsService::Init(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 void ManagedUserSettingsService::Shutdown() { 160 void ManagedUserSettingsService::Shutdown() {
161 store_->RemoveObserver(this); 161 store_->RemoveObserver(this);
162 } 162 }
163 163
164 SyncMergeResult ManagedUserSettingsService::MergeDataAndStartSyncing( 164 SyncMergeResult ManagedUserSettingsService::MergeDataAndStartSyncing(
165 ModelType type, 165 ModelType type,
166 const SyncDataList& initial_sync_data, 166 const SyncDataList& initial_sync_data,
167 scoped_ptr<SyncChangeProcessor> sync_processor, 167 scoped_ptr<SyncChangeProcessor> sync_processor,
168 scoped_ptr<SyncErrorFactory> error_handler) { 168 scoped_ptr<SyncErrorFactory> error_handler) {
169 DCHECK_EQ(MANAGED_USER_SETTINGS, type); 169 DCHECK_EQ(SUPERVISED_USER_SETTINGS, type);
170 sync_processor_ = sync_processor.Pass(); 170 sync_processor_ = sync_processor.Pass();
171 error_handler_ = error_handler.Pass(); 171 error_handler_ = error_handler.Pass();
172 172
173 // Clear all atomic and split settings, then recreate them from Sync data. 173 // Clear all atomic and split settings, then recreate them from Sync data.
174 Clear(); 174 Clear();
175 for (SyncDataList::const_iterator it = initial_sync_data.begin(); 175 for (SyncDataList::const_iterator it = initial_sync_data.begin();
176 it != initial_sync_data.end(); ++it) { 176 it != initial_sync_data.end(); ++it) {
177 DCHECK_EQ(MANAGED_USER_SETTINGS, it->GetDataType()); 177 DCHECK_EQ(SUPERVISED_USER_SETTINGS, it->GetDataType());
178 const ::sync_pb::ManagedUserSettingSpecifics& managed_user_setting = 178 const ::sync_pb::ManagedUserSettingSpecifics& managed_user_setting =
179 it->GetSpecifics().managed_user_setting(); 179 it->GetSpecifics().managed_user_setting();
180 scoped_ptr<base::Value> value( 180 scoped_ptr<base::Value> value(
181 JSONReader::Read(managed_user_setting.value())); 181 JSONReader::Read(managed_user_setting.value()));
182 std::string name_suffix = managed_user_setting.name(); 182 std::string name_suffix = managed_user_setting.name();
183 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix); 183 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix);
184 dict->SetWithoutPathExpansion(name_suffix, value.release()); 184 dict->SetWithoutPathExpansion(name_suffix, value.release());
185 } 185 }
186 store_->ReportValueChanged(kAtomicSettings); 186 store_->ReportValueChanged(kAtomicSettings);
187 store_->ReportValueChanged(kSplitSettings); 187 store_->ReportValueChanged(kSplitSettings);
188 InformSubscribers(); 188 InformSubscribers();
189 189
190 // Upload all the queued up items (either with an ADD or an UPDATE action, 190 // Upload all the queued up items (either with an ADD or an UPDATE action,
191 // depending on whether they already exist) and move them to split settings. 191 // depending on whether they already exist) and move them to split settings.
192 SyncChangeList change_list; 192 SyncChangeList change_list;
193 base::DictionaryValue* queued_items = GetQueuedItems(); 193 base::DictionaryValue* queued_items = GetQueuedItems();
194 for (base::DictionaryValue::Iterator it(*queued_items); !it.IsAtEnd(); 194 for (base::DictionaryValue::Iterator it(*queued_items); !it.IsAtEnd();
195 it.Advance()) { 195 it.Advance()) {
196 std::string key_suffix = it.key(); 196 std::string key_suffix = it.key();
197 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key_suffix); 197 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key_suffix);
198 SyncData data = CreateSyncDataForSetting(it.key(), it.value()); 198 SyncData data = CreateSyncDataForSetting(it.key(), it.value());
199 SyncChange::SyncChangeType change_type = 199 SyncChange::SyncChangeType change_type =
200 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE 200 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE
201 : SyncChange::ACTION_ADD; 201 : SyncChange::ACTION_ADD;
202 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); 202 change_list.push_back(SyncChange(FROM_HERE, change_type, data));
203 dict->SetWithoutPathExpansion(key_suffix, it.value().DeepCopy()); 203 dict->SetWithoutPathExpansion(key_suffix, it.value().DeepCopy());
204 } 204 }
205 queued_items->Clear(); 205 queued_items->Clear();
206 206
207 SyncMergeResult result(MANAGED_USER_SETTINGS); 207 SyncMergeResult result(SUPERVISED_USER_SETTINGS);
208 // Process all the accumulated changes from the queued items. 208 // Process all the accumulated changes from the queued items.
209 if (change_list.size() > 0) { 209 if (change_list.size() > 0) {
210 store_->ReportValueChanged(kQueuedItems); 210 store_->ReportValueChanged(kQueuedItems);
211 result.set_error( 211 result.set_error(
212 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); 212 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list));
213 } 213 }
214 214
215 // TODO(bauerb): Statistics? 215 // TODO(bauerb): Statistics?
216 return result; 216 return result;
217 } 217 }
218 218
219 void ManagedUserSettingsService::StopSyncing(ModelType type) { 219 void ManagedUserSettingsService::StopSyncing(ModelType type) {
220 DCHECK_EQ(syncer::MANAGED_USER_SETTINGS, type); 220 DCHECK_EQ(syncer::SUPERVISED_USER_SETTINGS, type);
221 sync_processor_.reset(); 221 sync_processor_.reset();
222 error_handler_.reset(); 222 error_handler_.reset();
223 } 223 }
224 224
225 SyncDataList ManagedUserSettingsService::GetAllSyncData( 225 SyncDataList ManagedUserSettingsService::GetAllSyncData(
226 ModelType type) const { 226 ModelType type) const {
227 DCHECK_EQ(syncer::MANAGED_USER_SETTINGS, type); 227 DCHECK_EQ(syncer::SUPERVISED_USER_SETTINGS, type);
228 SyncDataList data; 228 SyncDataList data;
229 for (base::DictionaryValue::Iterator it(*GetAtomicSettings()); !it.IsAtEnd(); 229 for (base::DictionaryValue::Iterator it(*GetAtomicSettings()); !it.IsAtEnd();
230 it.Advance()) { 230 it.Advance()) {
231 data.push_back(CreateSyncDataForSetting(it.key(), it.value())); 231 data.push_back(CreateSyncDataForSetting(it.key(), it.value()));
232 } 232 }
233 for (base::DictionaryValue::Iterator it(*GetSplitSettings()); !it.IsAtEnd(); 233 for (base::DictionaryValue::Iterator it(*GetSplitSettings()); !it.IsAtEnd();
234 it.Advance()) { 234 it.Advance()) {
235 const base::DictionaryValue* dict = NULL; 235 const base::DictionaryValue* dict = NULL;
236 it.value().GetAsDictionary(&dict); 236 it.value().GetAsDictionary(&dict);
237 for (base::DictionaryValue::Iterator jt(*dict); 237 for (base::DictionaryValue::Iterator jt(*dict);
238 !jt.IsAtEnd(); jt.Advance()) { 238 !jt.IsAtEnd(); jt.Advance()) {
239 data.push_back(CreateSyncDataForSetting( 239 data.push_back(CreateSyncDataForSetting(
240 MakeSplitSettingKey(it.key(), jt.key()), jt.value())); 240 MakeSplitSettingKey(it.key(), jt.key()), jt.value()));
241 } 241 }
242 } 242 }
243 DCHECK_EQ(0u, GetQueuedItems()->size()); 243 DCHECK_EQ(0u, GetQueuedItems()->size());
244 return data; 244 return data;
245 } 245 }
246 246
247 SyncError ManagedUserSettingsService::ProcessSyncChanges( 247 SyncError ManagedUserSettingsService::ProcessSyncChanges(
248 const tracked_objects::Location& from_here, 248 const tracked_objects::Location& from_here,
249 const SyncChangeList& change_list) { 249 const SyncChangeList& change_list) {
250 for (SyncChangeList::const_iterator it = change_list.begin(); 250 for (SyncChangeList::const_iterator it = change_list.begin();
251 it != change_list.end(); ++it) { 251 it != change_list.end(); ++it) {
252 SyncData data = it->sync_data(); 252 SyncData data = it->sync_data();
253 DCHECK_EQ(MANAGED_USER_SETTINGS, data.GetDataType()); 253 DCHECK_EQ(SUPERVISED_USER_SETTINGS, data.GetDataType());
254 const ::sync_pb::ManagedUserSettingSpecifics& managed_user_setting = 254 const ::sync_pb::ManagedUserSettingSpecifics& managed_user_setting =
255 data.GetSpecifics().managed_user_setting(); 255 data.GetSpecifics().managed_user_setting();
256 std::string key = managed_user_setting.name(); 256 std::string key = managed_user_setting.name();
257 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key); 257 base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key);
258 switch (it->change_type()) { 258 switch (it->change_type()) {
259 case SyncChange::ACTION_ADD: 259 case SyncChange::ACTION_ADD:
260 case SyncChange::ACTION_UPDATE: { 260 case SyncChange::ACTION_UPDATE: {
261 scoped_ptr<base::Value> value( 261 scoped_ptr<base::Value> value(
262 JSONReader::Read(managed_user_setting.value())); 262 JSONReader::Read(managed_user_setting.value()));
263 if (dict->HasKey(key)) { 263 if (dict->HasKey(key)) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 void ManagedUserSettingsService::InformSubscribers() { 374 void ManagedUserSettingsService::InformSubscribers() {
375 if (!IsReady()) 375 if (!IsReady())
376 return; 376 return;
377 377
378 scoped_ptr<base::DictionaryValue> settings = GetSettings(); 378 scoped_ptr<base::DictionaryValue> settings = GetSettings();
379 for (std::vector<SettingsCallback>::iterator it = subscribers_.begin(); 379 for (std::vector<SettingsCallback>::iterator it = subscribers_.begin();
380 it != subscribers_.end(); ++it) { 380 it != subscribers_.end(); ++it) {
381 it->Run(settings.get()); 381 it->Run(settings.get());
382 } 382 }
383 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698