OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/policy/configuration_policy_handler_chromeos.h
" | 5 #include "chrome/browser/chromeos/policy/configuration_policy_handler_chromeos.h
" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/ptr_util.h" |
18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
21 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 22 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chromeos/dbus/power_policy_controller.h" | 24 #include "chromeos/dbus/power_policy_controller.h" |
24 #include "chromeos/network/onc/onc_signature.h" | 25 #include "chromeos/network/onc/onc_signature.h" |
25 #include "chromeos/network/onc/onc_utils.h" | 26 #include "chromeos/network/onc/onc_utils.h" |
26 #include "chromeos/network/onc/onc_validator.h" | 27 #include "chromeos/network/onc/onc_validator.h" |
27 #include "components/onc/onc_constants.h" | 28 #include "components/onc/onc_constants.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 // Currently, only the per-network configuration is stored in a pref. Ignore | 258 // Currently, only the per-network configuration is stored in a pref. Ignore |
258 // |global_network_config| and |certificates|. | 259 // |global_network_config| and |certificates|. |
259 prefs->SetValue(pref_path_, std::move(network_configs)); | 260 prefs->SetValue(pref_path_, std::move(network_configs)); |
260 } | 261 } |
261 | 262 |
262 void NetworkConfigurationPolicyHandler::PrepareForDisplaying( | 263 void NetworkConfigurationPolicyHandler::PrepareForDisplaying( |
263 PolicyMap* policies) const { | 264 PolicyMap* policies) const { |
264 const PolicyMap::Entry* entry = policies->Get(policy_name()); | 265 const PolicyMap::Entry* entry = policies->Get(policy_name()); |
265 if (!entry) | 266 if (!entry) |
266 return; | 267 return; |
267 base::Value* sanitized_config = SanitizeNetworkConfig(entry->value); | 268 std::unique_ptr<base::Value> sanitized_config = |
| 269 SanitizeNetworkConfig(entry->value.get()); |
268 if (!sanitized_config) | 270 if (!sanitized_config) |
269 sanitized_config = base::Value::CreateNullValue().release(); | 271 sanitized_config = base::Value::CreateNullValue(); |
270 | 272 |
271 policies->Set(policy_name(), entry->level, entry->scope, | 273 policies->Set(policy_name(), entry->level, entry->scope, entry->source, |
272 entry->source, sanitized_config, nullptr); | 274 std::move(sanitized_config), nullptr); |
273 } | 275 } |
274 | 276 |
275 NetworkConfigurationPolicyHandler::NetworkConfigurationPolicyHandler( | 277 NetworkConfigurationPolicyHandler::NetworkConfigurationPolicyHandler( |
276 const char* policy_name, | 278 const char* policy_name, |
277 onc::ONCSource onc_source, | 279 onc::ONCSource onc_source, |
278 const char* pref_path) | 280 const char* pref_path) |
279 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_STRING), | 281 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_STRING), |
280 onc_source_(onc_source), | 282 onc_source_(onc_source), |
281 pref_path_(pref_path) { | 283 pref_path_(pref_path) { |
282 } | 284 } |
283 | 285 |
284 // static | 286 // static |
285 base::Value* NetworkConfigurationPolicyHandler::SanitizeNetworkConfig( | 287 std::unique_ptr<base::Value> |
| 288 NetworkConfigurationPolicyHandler::SanitizeNetworkConfig( |
286 const base::Value* config) { | 289 const base::Value* config) { |
287 std::string json_string; | 290 std::string json_string; |
288 if (!config->GetAsString(&json_string)) | 291 if (!config->GetAsString(&json_string)) |
289 return NULL; | 292 return NULL; |
290 | 293 |
291 std::unique_ptr<base::DictionaryValue> toplevel_dict = | 294 std::unique_ptr<base::DictionaryValue> toplevel_dict = |
292 chromeos::onc::ReadDictionaryFromJson(json_string); | 295 chromeos::onc::ReadDictionaryFromJson(json_string); |
293 if (!toplevel_dict) | 296 if (!toplevel_dict) |
294 return NULL; | 297 return NULL; |
295 | 298 |
296 // Placeholder to insert in place of the filtered setting. | 299 // Placeholder to insert in place of the filtered setting. |
297 const char kPlaceholder[] = "********"; | 300 const char kPlaceholder[] = "********"; |
298 | 301 |
299 toplevel_dict = chromeos::onc::MaskCredentialsInOncObject( | 302 toplevel_dict = chromeos::onc::MaskCredentialsInOncObject( |
300 chromeos::onc::kToplevelConfigurationSignature, | 303 chromeos::onc::kToplevelConfigurationSignature, |
301 *toplevel_dict, | 304 *toplevel_dict, |
302 kPlaceholder); | 305 kPlaceholder); |
303 | 306 |
304 base::JSONWriter::WriteWithOptions( | 307 base::JSONWriter::WriteWithOptions( |
305 *toplevel_dict, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json_string); | 308 *toplevel_dict, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json_string); |
306 return new base::StringValue(json_string); | 309 return base::WrapUnique(new base::StringValue(json_string)); |
307 } | 310 } |
308 | 311 |
309 PinnedLauncherAppsPolicyHandler::PinnedLauncherAppsPolicyHandler() | 312 PinnedLauncherAppsPolicyHandler::PinnedLauncherAppsPolicyHandler() |
310 : ExtensionListPolicyHandler(key::kPinnedLauncherApps, | 313 : ExtensionListPolicyHandler(key::kPinnedLauncherApps, |
311 prefs::kPolicyPinnedLauncherApps, | 314 prefs::kPolicyPinnedLauncherApps, |
312 false) {} | 315 false) {} |
313 | 316 |
314 PinnedLauncherAppsPolicyHandler::~PinnedLauncherAppsPolicyHandler() {} | 317 PinnedLauncherAppsPolicyHandler::~PinnedLauncherAppsPolicyHandler() {} |
315 | 318 |
316 void PinnedLauncherAppsPolicyHandler::ApplyPolicySettings( | 319 void PinnedLauncherAppsPolicyHandler::ApplyPolicySettings( |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 | 478 |
476 value = GetValue(dict, kScreenLockDelayAC); | 479 value = GetValue(dict, kScreenLockDelayAC); |
477 if (value) | 480 if (value) |
478 prefs->SetValue(prefs::kPowerAcScreenLockDelayMs, std::move(value)); | 481 prefs->SetValue(prefs::kPowerAcScreenLockDelayMs, std::move(value)); |
479 value = GetValue(dict, kScreenLockDelayBattery); | 482 value = GetValue(dict, kScreenLockDelayBattery); |
480 if (value) | 483 if (value) |
481 prefs->SetValue(prefs::kPowerBatteryScreenLockDelayMs, std::move(value)); | 484 prefs->SetValue(prefs::kPowerBatteryScreenLockDelayMs, std::move(value)); |
482 } | 485 } |
483 | 486 |
484 } // namespace policy | 487 } // namespace policy |
OLD | NEW |