Chromium Code Reviews| 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 "base/bind.h" | |
| 7 #include "base/callback.h" | 8 #include "base/callback.h" |
| 8 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 10 #include "base/prefs/json_pref_store.h" | 11 #include "base/prefs/json_pref_store.h" |
| 11 #include "base/prefs/pref_filter.h" | 12 #include "base/prefs/pref_filter.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
| 15 #include "chrome/browser/content_settings/content_settings_supervised_provider.h " | |
| 14 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" | 16 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
| 15 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
| 18 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 16 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/user_metrics.h" | 20 #include "content/public/browser/user_metrics.h" |
| 18 #include "sync/api/sync_change.h" | 21 #include "sync/api/sync_change.h" |
| 19 #include "sync/api/sync_error_factory.h" | 22 #include "sync/api/sync_error_factory.h" |
| 20 #include "sync/protocol/sync.pb.h" | 23 #include "sync/protocol/sync.pb.h" |
| 21 | 24 |
| 22 using base::DictionaryValue; | 25 using base::DictionaryValue; |
| 23 using base::JSONReader; | 26 using base::JSONReader; |
| 24 using base::UserMetricsAction; | 27 using base::UserMetricsAction; |
| 25 using base::Value; | 28 using base::Value; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 43 | 46 |
| 44 namespace { | 47 namespace { |
| 45 | 48 |
| 46 bool SettingShouldApplyToPrefs(const std::string& name) { | 49 bool SettingShouldApplyToPrefs(const std::string& name) { |
| 47 return !StartsWithASCII(name, kSupervisedUserInternalItemPrefix, false); | 50 return !StartsWithASCII(name, kSupervisedUserInternalItemPrefix, false); |
| 48 } | 51 } |
| 49 | 52 |
| 50 } // namespace | 53 } // namespace |
| 51 | 54 |
| 52 SupervisedUserSettingsService::SupervisedUserSettingsService() | 55 SupervisedUserSettingsService::SupervisedUserSettingsService() |
| 53 : active_(false), local_settings_(new base::DictionaryValue) {} | 56 : active_(false), local_settings_(new base::DictionaryValue) { |
|
Bernhard Bauer
2015/02/26 12:44:58
Personally, I'm okay with either keeping opening a
knn
2015/02/26 16:18:56
Sorry about that.
| |
| 57 } | |
| 54 | 58 |
| 55 SupervisedUserSettingsService::~SupervisedUserSettingsService() {} | 59 SupervisedUserSettingsService::~SupervisedUserSettingsService() {} |
| 56 | 60 |
| 57 void SupervisedUserSettingsService::Init( | 61 void SupervisedUserSettingsService::Init( |
| 58 base::FilePath profile_path, | 62 base::FilePath profile_path, |
| 59 base::SequencedTaskRunner* sequenced_task_runner, | 63 base::SequencedTaskRunner* sequenced_task_runner, |
| 60 bool load_synchronously) { | 64 bool load_synchronously) { |
| 61 base::FilePath path = | 65 base::FilePath path = |
| 62 profile_path.Append(chrome::kSupervisedUserSettingsFilename); | 66 profile_path.Append(chrome::kSupervisedUserSettingsFilename); |
| 63 PersistentPrefStore* store = new JsonPrefStore( | 67 PersistentPrefStore* store = new JsonPrefStore( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 84 void SupervisedUserSettingsService::Subscribe( | 88 void SupervisedUserSettingsService::Subscribe( |
| 85 const SettingsCallback& callback) { | 89 const SettingsCallback& callback) { |
| 86 if (IsReady()) { | 90 if (IsReady()) { |
| 87 scoped_ptr<base::DictionaryValue> settings = GetSettings(); | 91 scoped_ptr<base::DictionaryValue> settings = GetSettings(); |
| 88 callback.Run(settings.get()); | 92 callback.Run(settings.get()); |
| 89 } | 93 } |
| 90 | 94 |
| 91 subscribers_.push_back(callback); | 95 subscribers_.push_back(callback); |
| 92 } | 96 } |
| 93 | 97 |
| 98 void SupervisedUserSettingsService::RegisterContentSettings( | |
| 99 HostContentSettingsMap* host_content_settings_map) { | |
| 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 101 scoped_ptr<content_settings::SupervisedProvider> supervised_provider( | |
| 102 new content_settings::SupervisedProvider()); | |
| 103 Subscribe(base::Bind( | |
| 104 &content_settings::SupervisedProvider::OnSupervisedSettingsAvailable, | |
| 105 base::Unretained(supervised_provider.get()))); | |
| 106 host_content_settings_map->RegisterProvider( | |
| 107 HostContentSettingsMap::SUPERVISED_PROVIDER, supervised_provider.Pass()); | |
| 108 } | |
| 109 | |
| 94 void SupervisedUserSettingsService::SetActive(bool active) { | 110 void SupervisedUserSettingsService::SetActive(bool active) { |
| 95 active_ = active; | 111 active_ = active; |
| 96 InformSubscribers(); | 112 InformSubscribers(); |
| 97 } | 113 } |
| 98 | 114 |
| 99 bool SupervisedUserSettingsService::IsReady() { | 115 bool SupervisedUserSettingsService::IsReady() { |
| 116 if (!store_) return false; | |
|
Bernhard Bauer
2015/02/26 12:44:58
Return statement on new line.
Also, it's an error
knn
2015/02/26 16:18:56
Done.
| |
| 100 return store_->IsInitializationComplete(); | 117 return store_->IsInitializationComplete(); |
| 101 } | 118 } |
| 102 | 119 |
| 103 void SupervisedUserSettingsService::Clear() { | 120 void SupervisedUserSettingsService::Clear() { |
| 104 store_->RemoveValue(kAtomicSettings); | 121 store_->RemoveValue(kAtomicSettings); |
| 105 store_->RemoveValue(kSplitSettings); | 122 store_->RemoveValue(kSplitSettings); |
| 106 } | 123 } |
| 107 | 124 |
| 108 // static | 125 // static |
| 109 std::string SupervisedUserSettingsService::MakeSplitSettingKey( | 126 std::string SupervisedUserSettingsService::MakeSplitSettingKey( |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 } | 398 } |
| 382 | 399 |
| 383 void SupervisedUserSettingsService::InformSubscribers() { | 400 void SupervisedUserSettingsService::InformSubscribers() { |
| 384 if (!IsReady()) | 401 if (!IsReady()) |
| 385 return; | 402 return; |
| 386 | 403 |
| 387 scoped_ptr<base::DictionaryValue> settings = GetSettings(); | 404 scoped_ptr<base::DictionaryValue> settings = GetSettings(); |
| 388 for (const auto& callback : subscribers_) | 405 for (const auto& callback : subscribers_) |
| 389 callback.Run(settings.get()); | 406 callback.Run(settings.get()); |
| 390 } | 407 } |
| OLD | NEW |