binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/extensions/extension_management_test_util.h" |
| 6 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 7 | #include <string> |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 8 | #include <utility> |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 9 | |
Takashi Toyoshima | 52f2467 | 2019-03-05 05:36:36 | [diff] [blame] | 10 | #include "base/run_loop.h" |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 11 | #include "components/crx_file/id_util.h" |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 12 | #include "components/policy/core/common/configuration_policy_provider.h" |
| 13 | #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 14 | #include "components/policy/core/common/policy_bundle.h" |
| 15 | #include "components/policy/core/common/policy_map.h" |
| 16 | #include "components/policy/core/common/policy_namespace.h" |
| 17 | #include "components/policy/core/common/policy_types.h" |
brettw | 39d6ba4 | 2016-08-24 16:56:38 | [diff] [blame] | 18 | #include "components/policy/policy_constants.h" |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 19 | |
| 20 | namespace extensions { |
| 21 | |
| 22 | namespace schema = schema_constants; |
| 23 | |
| 24 | namespace { |
| 25 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 26 | const char kInstallSourcesPath[] = "*.install_sources"; |
| 27 | const char kAllowedTypesPath[] = "*.allowed_types"; |
| 28 | |
ki.stfu | f38f931 | 2015-09-27 14:44:37 | [diff] [blame] | 29 | std::string make_path(const std::string& a, const std::string& b) { |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 30 | return a + "." + b; |
| 31 | } |
| 32 | |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 33 | } // namespace |
| 34 | |
| 35 | ExtensionManagementPrefUpdaterBase::ExtensionManagementPrefUpdaterBase() { |
| 36 | } |
| 37 | |
| 38 | ExtensionManagementPrefUpdaterBase::~ExtensionManagementPrefUpdaterBase() { |
Takashi Toyoshima | 52f2467 | 2019-03-05 05:36:36 | [diff] [blame] | 39 | // Make asynchronous calls finished to deliver all preference changes to the |
| 40 | // NetworkService and extension processes. |
| 41 | base::RunLoop().RunUntilIdle(); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 42 | } |
| 43 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 44 | // Helper functions for per extension settings --------------------------------- |
| 45 | |
binjin | 6a6eb15 | 2014-09-24 18:36:34 | [diff] [blame] | 46 | void ExtensionManagementPrefUpdaterBase::UnsetPerExtensionSettings( |
| 47 | const ExtensionId& id) { |
| 48 | DCHECK(crx_file::id_util::IdIsValid(id)); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 49 | pref_->RemoveWithoutPathExpansion(id, nullptr); |
binjin | 6a6eb15 | 2014-09-24 18:36:34 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void ExtensionManagementPrefUpdaterBase::ClearPerExtensionSettings( |
| 53 | const ExtensionId& id) { |
| 54 | DCHECK(crx_file::id_util::IdIsValid(id)); |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 55 | pref_->SetWithoutPathExpansion(id, std::make_unique<base::DictionaryValue>()); |
binjin | 6a6eb15 | 2014-09-24 18:36:34 | [diff] [blame] | 56 | } |
| 57 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 58 | // Helper functions for 'installation_mode' manipulation ----------------------- |
| 59 | |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 60 | void ExtensionManagementPrefUpdaterBase::SetBlacklistedByDefault(bool value) { |
| 61 | pref_->SetString(make_path(schema::kWildcard, schema::kInstallationMode), |
| 62 | value ? schema::kBlocked : schema::kAllowed); |
| 63 | } |
| 64 | |
| 65 | void ExtensionManagementPrefUpdaterBase:: |
| 66 | ClearInstallationModesForIndividualExtensions() { |
rdevlin.cronin | 165732a4 | 2016-07-18 22:25:08 | [diff] [blame] | 67 | for (base::DictionaryValue::Iterator it(*pref_); !it.IsAtEnd(); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 68 | it.Advance()) { |
jdoerrie | 1f536b2 | 2017-10-23 17:15:11 | [diff] [blame] | 69 | DCHECK(it.value().is_dict()); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 70 | if (it.key() != schema::kWildcard) { |
| 71 | DCHECK(crx_file::id_util::IdIsValid(it.key())); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 72 | pref_->Remove(make_path(it.key(), schema::kInstallationMode), nullptr); |
| 73 | pref_->Remove(make_path(it.key(), schema::kUpdateUrl), nullptr); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | ExtensionManagementPrefUpdaterBase::SetIndividualExtensionInstallationAllowed( |
| 80 | const ExtensionId& id, |
| 81 | bool allowed) { |
| 82 | DCHECK(crx_file::id_util::IdIsValid(id)); |
| 83 | pref_->SetString(make_path(id, schema::kInstallationMode), |
| 84 | allowed ? schema::kAllowed : schema::kBlocked); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 85 | pref_->Remove(make_path(id, schema::kUpdateUrl), nullptr); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void ExtensionManagementPrefUpdaterBase::SetIndividualExtensionAutoInstalled( |
| 89 | const ExtensionId& id, |
| 90 | const std::string& update_url, |
| 91 | bool forced) { |
| 92 | DCHECK(crx_file::id_util::IdIsValid(id)); |
| 93 | pref_->SetString(make_path(id, schema::kInstallationMode), |
| 94 | forced ? schema::kForceInstalled : schema::kNormalInstalled); |
| 95 | pref_->SetString(make_path(id, schema::kUpdateUrl), update_url); |
| 96 | } |
| 97 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 98 | // Helper functions for 'install_sources' manipulation ------------------------- |
| 99 | |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 100 | void ExtensionManagementPrefUpdaterBase::UnsetInstallSources() { |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 101 | pref_->Remove(kInstallSourcesPath, nullptr); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | void ExtensionManagementPrefUpdaterBase::ClearInstallSources() { |
| 105 | ClearList(kInstallSourcesPath); |
| 106 | } |
| 107 | |
| 108 | void ExtensionManagementPrefUpdaterBase::AddInstallSource( |
| 109 | const std::string& install_source) { |
| 110 | AddStringToList(kInstallSourcesPath, install_source); |
| 111 | } |
| 112 | |
| 113 | void ExtensionManagementPrefUpdaterBase::RemoveInstallSource( |
| 114 | const std::string& install_source) { |
| 115 | RemoveStringFromList(kInstallSourcesPath, install_source); |
| 116 | } |
| 117 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 118 | // Helper functions for 'allowed_types' manipulation --------------------------- |
| 119 | |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 120 | void ExtensionManagementPrefUpdaterBase::UnsetAllowedTypes() { |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 121 | pref_->Remove(kAllowedTypesPath, nullptr); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void ExtensionManagementPrefUpdaterBase::ClearAllowedTypes() { |
| 125 | ClearList(kAllowedTypesPath); |
| 126 | } |
| 127 | |
| 128 | void ExtensionManagementPrefUpdaterBase::AddAllowedType( |
| 129 | const std::string& allowed_type) { |
| 130 | AddStringToList(kAllowedTypesPath, allowed_type); |
| 131 | } |
| 132 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 133 | void ExtensionManagementPrefUpdaterBase::RemoveAllowedType( |
| 134 | const std::string& allowed_type) { |
| 135 | RemoveStringFromList(kAllowedTypesPath, allowed_type); |
| 136 | } |
| 137 | |
| 138 | // Helper functions for 'blocked_permissions' manipulation --------------------- |
| 139 | |
| 140 | void ExtensionManagementPrefUpdaterBase::UnsetBlockedPermissions( |
| 141 | const std::string& prefix) { |
| 142 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 143 | pref_->Remove(make_path(prefix, schema::kBlockedPermissions), nullptr); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void ExtensionManagementPrefUpdaterBase::ClearBlockedPermissions( |
| 147 | const std::string& prefix) { |
| 148 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
| 149 | ClearList(make_path(prefix, schema::kBlockedPermissions)); |
| 150 | } |
| 151 | |
| 152 | void ExtensionManagementPrefUpdaterBase::AddBlockedPermission( |
| 153 | const std::string& prefix, |
| 154 | const std::string& permission) { |
| 155 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
| 156 | AddStringToList(make_path(prefix, schema::kBlockedPermissions), permission); |
| 157 | } |
| 158 | |
| 159 | void ExtensionManagementPrefUpdaterBase::RemoveBlockedPermission( |
| 160 | const std::string& prefix, |
| 161 | const std::string& permission) { |
| 162 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
| 163 | RemoveStringFromList(make_path(prefix, schema::kBlockedPermissions), |
| 164 | permission); |
| 165 | } |
| 166 | |
nrpeter | 2362e7e | 2017-05-10 17:21:26 | [diff] [blame] | 167 | // Helper function for 'blocked_install_message' manipulation ----------------- |
| 168 | |
| 169 | void ExtensionManagementPrefUpdaterBase::SetBlockedInstallMessage( |
| 170 | const ExtensionId& id, |
| 171 | const std::string& blocked_install_message) { |
| 172 | DCHECK(id == schema::kWildcard || crx_file::id_util::IdIsValid(id)); |
| 173 | pref_->SetString(make_path(id, schema::kBlockedInstallMessage), |
| 174 | blocked_install_message); |
| 175 | } |
| 176 | |
nrpeter | 40e1638 | 2017-04-13 17:34:58 | [diff] [blame] | 177 | // Helper functions for 'runtime_blocked_hosts' manipulation ------------------ |
| 178 | |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 179 | void ExtensionManagementPrefUpdaterBase::UnsetPolicyBlockedHosts( |
nrpeter | 40e1638 | 2017-04-13 17:34:58 | [diff] [blame] | 180 | const std::string& prefix) { |
| 181 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 182 | pref_->Remove(make_path(prefix, schema::kPolicyBlockedHosts), nullptr); |
nrpeter | 40e1638 | 2017-04-13 17:34:58 | [diff] [blame] | 183 | } |
| 184 | |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 185 | void ExtensionManagementPrefUpdaterBase::ClearPolicyBlockedHosts( |
nrpeter | 40e1638 | 2017-04-13 17:34:58 | [diff] [blame] | 186 | const std::string& prefix) { |
| 187 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 188 | ClearList(make_path(prefix, schema::kPolicyBlockedHosts)); |
nrpeter | 40e1638 | 2017-04-13 17:34:58 | [diff] [blame] | 189 | } |
| 190 | |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 191 | void ExtensionManagementPrefUpdaterBase::AddPolicyBlockedHost( |
nrpeter | 40e1638 | 2017-04-13 17:34:58 | [diff] [blame] | 192 | const std::string& prefix, |
| 193 | const std::string& host) { |
| 194 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 195 | AddStringToList(make_path(prefix, schema::kPolicyBlockedHosts), host); |
nrpeter | 40e1638 | 2017-04-13 17:34:58 | [diff] [blame] | 196 | } |
| 197 | |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 198 | void ExtensionManagementPrefUpdaterBase::RemovePolicyBlockedHost( |
nrpeter | 40e1638 | 2017-04-13 17:34:58 | [diff] [blame] | 199 | const std::string& prefix, |
| 200 | const std::string& host) { |
| 201 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 202 | RemoveStringFromList(make_path(prefix, schema::kPolicyBlockedHosts), host); |
nrpeter | 40e1638 | 2017-04-13 17:34:58 | [diff] [blame] | 203 | } |
| 204 | |
Nick Peterson | 87ecb10 | 2018-10-16 04:55:01 | [diff] [blame] | 205 | // Helper functions for 'runtime_allowed_hosts' manipulation ------------------ |
| 206 | |
| 207 | void ExtensionManagementPrefUpdaterBase::UnsetPolicyAllowedHosts( |
| 208 | const std::string& prefix) { |
| 209 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
| 210 | pref_->Remove(make_path(prefix, schema::kPolicyAllowedHosts), nullptr); |
| 211 | } |
| 212 | |
| 213 | void ExtensionManagementPrefUpdaterBase::ClearPolicyAllowedHosts( |
| 214 | const std::string& prefix) { |
| 215 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
| 216 | ClearList(make_path(prefix, schema::kPolicyAllowedHosts)); |
| 217 | } |
| 218 | |
| 219 | void ExtensionManagementPrefUpdaterBase::AddPolicyAllowedHost( |
| 220 | const std::string& prefix, |
| 221 | const std::string& host) { |
| 222 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
| 223 | AddStringToList(make_path(prefix, schema::kPolicyAllowedHosts), host); |
| 224 | } |
| 225 | |
| 226 | void ExtensionManagementPrefUpdaterBase::RemovePolicyAllowedHost( |
| 227 | const std::string& prefix, |
| 228 | const std::string& host) { |
| 229 | DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
| 230 | RemoveStringFromList(make_path(prefix, schema::kPolicyAllowedHosts), host); |
| 231 | } |
| 232 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 233 | // Helper functions for 'allowed_permissions' manipulation --------------------- |
| 234 | |
| 235 | void ExtensionManagementPrefUpdaterBase::UnsetAllowedPermissions( |
| 236 | const std::string& id) { |
| 237 | DCHECK(crx_file::id_util::IdIsValid(id)); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 238 | pref_->Remove(make_path(id, schema::kAllowedPermissions), nullptr); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | void ExtensionManagementPrefUpdaterBase::ClearAllowedPermissions( |
| 242 | const std::string& id) { |
| 243 | DCHECK(crx_file::id_util::IdIsValid(id)); |
| 244 | ClearList(make_path(id, schema::kAllowedPermissions)); |
| 245 | } |
| 246 | |
| 247 | void ExtensionManagementPrefUpdaterBase::AddAllowedPermission( |
| 248 | const std::string& id, |
| 249 | const std::string& permission) { |
| 250 | DCHECK(crx_file::id_util::IdIsValid(id)); |
| 251 | AddStringToList(make_path(id, schema::kAllowedPermissions), permission); |
| 252 | } |
| 253 | |
| 254 | void ExtensionManagementPrefUpdaterBase::RemoveAllowedPermission( |
| 255 | const std::string& id, |
| 256 | const std::string& permission) { |
| 257 | DCHECK(crx_file::id_util::IdIsValid(id)); |
| 258 | RemoveStringFromList(make_path(id, schema::kAllowedPermissions), permission); |
| 259 | } |
| 260 | |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 261 | // Helper functions for 'minimum_version_required' manipulation ---------------- |
| 262 | |
| 263 | void ExtensionManagementPrefUpdaterBase::SetMinimumVersionRequired( |
| 264 | const std::string& id, |
| 265 | const std::string& version) { |
| 266 | DCHECK(crx_file::id_util::IdIsValid(id)); |
| 267 | pref_->SetString(make_path(id, schema::kMinimumVersionRequired), version); |
| 268 | } |
| 269 | |
| 270 | void ExtensionManagementPrefUpdaterBase::UnsetMinimumVersionRequired( |
| 271 | const std::string& id) { |
| 272 | DCHECK(crx_file::id_util::IdIsValid(id)); |
| 273 | pref_->Remove(make_path(id, schema::kMinimumVersionRequired), nullptr); |
| 274 | } |
| 275 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 276 | // Expose a read-only preference to user --------------------------------------- |
| 277 | |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 278 | const base::DictionaryValue* ExtensionManagementPrefUpdaterBase::GetPref() { |
| 279 | return pref_.get(); |
| 280 | } |
| 281 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 282 | // Private section functions --------------------------------------------------- |
| 283 | |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 284 | void ExtensionManagementPrefUpdaterBase::SetPref(base::DictionaryValue* pref) { |
| 285 | pref_.reset(pref); |
| 286 | } |
| 287 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 288 | std::unique_ptr<base::DictionaryValue> |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 289 | ExtensionManagementPrefUpdaterBase::TakePref() { |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 290 | return std::move(pref_); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 291 | } |
| 292 | |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 293 | void ExtensionManagementPrefUpdaterBase::ClearList(const std::string& path) { |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 294 | pref_->Set(path, std::make_unique<base::ListValue>()); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | void ExtensionManagementPrefUpdaterBase::AddStringToList( |
| 298 | const std::string& path, |
| 299 | const std::string& str) { |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 300 | base::ListValue* list_value_weak = nullptr; |
| 301 | if (!pref_->GetList(path, &list_value_weak)) { |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 302 | auto list_value = std::make_unique<base::ListValue>(); |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 303 | list_value_weak = list_value.get(); |
| 304 | pref_->Set(path, std::move(list_value)); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 305 | } |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 306 | CHECK( |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 307 | list_value_weak->AppendIfNotPresent(std::make_unique<base::Value>(str))); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void ExtensionManagementPrefUpdaterBase::RemoveStringFromList( |
| 311 | const std::string& path, |
| 312 | const std::string& str) { |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 313 | base::ListValue* list_value = nullptr; |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 314 | if (pref_->GetList(path, &list_value)) |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 315 | CHECK(list_value->Remove(base::Value(str), nullptr)); |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 316 | } |
| 317 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 318 | // ExtensionManagementPolicyUpdater -------------------------------------------- |
| 319 | |
| 320 | ExtensionManagementPolicyUpdater::ExtensionManagementPolicyUpdater( |
| 321 | policy::MockConfigurationPolicyProvider* policy_provider) |
| 322 | : provider_(policy_provider), policies_(new policy::PolicyBundle) { |
| 323 | policies_->CopyFrom(provider_->policies()); |
| 324 | const base::Value* policy_value = |
| 325 | policies_->Get(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
| 326 | std::string())) |
| 327 | .GetValue(policy::key::kExtensionSettings); |
| 328 | const base::DictionaryValue* dict_value = nullptr; |
| 329 | if (policy_value && policy_value->GetAsDictionary(&dict_value)) |
| 330 | SetPref(dict_value->DeepCopy()); |
| 331 | else |
| 332 | SetPref(new base::DictionaryValue); |
| 333 | } |
| 334 | |
| 335 | ExtensionManagementPolicyUpdater::~ExtensionManagementPolicyUpdater() { |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 336 | policies_ |
| 337 | ->Get( |
| 338 | policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())) |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 339 | .Set(policy::key::kExtensionSettings, policy::POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 340 | policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, TakePref(), |
| 341 | nullptr); |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 342 | provider_->UpdatePolicy(std::move(policies_)); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 343 | } |
| 344 | |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 345 | } // namespace extensions |