| OLD | NEW |
| 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 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/user_metrics.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" | 18 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
| 18 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 19 #include "components/prefs/json_pref_store.h" | 20 #include "components/prefs/json_pref_store.h" |
| 20 #include "components/prefs/pref_filter.h" | 21 #include "components/prefs/pref_filter.h" |
| 21 #include "components/sync/model/sync_change.h" | 22 #include "components/sync/model/sync_change.h" |
| 22 #include "components/sync/model/sync_error_factory.h" | 23 #include "components/sync/model/sync_error_factory.h" |
| 23 #include "components/sync/protocol/sync.pb.h" | 24 #include "components/sync/protocol/sync.pb.h" |
| 24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/user_metrics.h" | |
| 26 | 26 |
| 27 using base::DictionaryValue; | 27 using base::DictionaryValue; |
| 28 using base::JSONReader; | 28 using base::JSONReader; |
| 29 using base::UserMetricsAction; | 29 using base::UserMetricsAction; |
| 30 using base::Value; | 30 using base::Value; |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using syncer::SUPERVISED_USER_SETTINGS; | 32 using syncer::SUPERVISED_USER_SETTINGS; |
| 33 using syncer::ModelType; | 33 using syncer::ModelType; |
| 34 using syncer::SyncChange; | 34 using syncer::SyncChange; |
| 35 using syncer::SyncChangeList; | 35 using syncer::SyncChangeList; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 PushItemToSync(key, std::move(value)); | 141 PushItemToSync(key, std::move(value)); |
| 142 InformSubscribers(); | 142 InformSubscribers(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void SupervisedUserSettingsService::PushItemToSync( | 145 void SupervisedUserSettingsService::PushItemToSync( |
| 146 const std::string& key, | 146 const std::string& key, |
| 147 std::unique_ptr<base::Value> value) { | 147 std::unique_ptr<base::Value> value) { |
| 148 std::string key_suffix = key; | 148 std::string key_suffix = key; |
| 149 base::DictionaryValue* dict = nullptr; | 149 base::DictionaryValue* dict = nullptr; |
| 150 if (sync_processor_) { | 150 if (sync_processor_) { |
| 151 content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Syncing")); | 151 base::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Syncing")); |
| 152 dict = GetDictionaryAndSplitKey(&key_suffix); | 152 dict = GetDictionaryAndSplitKey(&key_suffix); |
| 153 DCHECK(GetQueuedItems()->empty()); | 153 DCHECK(GetQueuedItems()->empty()); |
| 154 SyncChangeList change_list; | 154 SyncChangeList change_list; |
| 155 SyncData data = CreateSyncDataForSetting(key, *value); | 155 SyncData data = CreateSyncDataForSetting(key, *value); |
| 156 SyncChange::SyncChangeType change_type = | 156 SyncChange::SyncChangeType change_type = |
| 157 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE | 157 dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE |
| 158 : SyncChange::ACTION_ADD; | 158 : SyncChange::ACTION_ADD; |
| 159 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); | 159 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); |
| 160 SyncError error = | 160 SyncError error = |
| 161 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); | 161 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); |
| 162 DCHECK(!error.IsSet()) << error.ToString(); | 162 DCHECK(!error.IsSet()) << error.ToString(); |
| 163 } else { | 163 } else { |
| 164 // Queue the item up to be uploaded when we start syncing | 164 // Queue the item up to be uploaded when we start syncing |
| 165 // (in MergeDataAndStartSyncing()). | 165 // (in MergeDataAndStartSyncing()). |
| 166 content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Queued")); | 166 base::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Queued")); |
| 167 dict = GetQueuedItems(); | 167 dict = GetQueuedItems(); |
| 168 } | 168 } |
| 169 dict->SetWithoutPathExpansion(key_suffix, std::move(value)); | 169 dict->SetWithoutPathExpansion(key_suffix, std::move(value)); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void SupervisedUserSettingsService::SetLocalSetting( | 172 void SupervisedUserSettingsService::SetLocalSetting( |
| 173 const std::string& key, | 173 const std::string& key, |
| 174 std::unique_ptr<base::Value> value) { | 174 std::unique_ptr<base::Value> value) { |
| 175 if (value) | 175 if (value) |
| 176 local_settings_->SetWithoutPathExpansion(key, value.release()); | 176 local_settings_->SetWithoutPathExpansion(key, value.release()); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 return settings; | 489 return settings; |
| 490 } | 490 } |
| 491 | 491 |
| 492 void SupervisedUserSettingsService::InformSubscribers() { | 492 void SupervisedUserSettingsService::InformSubscribers() { |
| 493 if (!IsReady()) | 493 if (!IsReady()) |
| 494 return; | 494 return; |
| 495 | 495 |
| 496 std::unique_ptr<base::DictionaryValue> settings = GetSettings(); | 496 std::unique_ptr<base::DictionaryValue> settings = GetSettings(); |
| 497 callback_list_.Notify(settings.get()); | 497 callback_list_.Notify(settings.get()); |
| 498 } | 498 } |
| OLD | NEW |