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

Side by Side Diff: chrome/browser/chromeos/policy/configuration_policy_handler_chromeos.cc

Issue 1870793002: Convert //chrome/browser/chromeos from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: iwyu fixes Created 4 years, 8 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
OLDNEW
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
9 #include <memory>
8 #include <string> 10 #include <string>
9 #include <utility> 11 #include <utility>
10 #include <vector> 12 #include <vector>
11 13
12 #include "base/callback.h" 14 #include "base/callback.h"
13 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
14 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
15 #include "base/logging.h" 17 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/values.h" 20 #include "base/values.h"
20 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 21 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "chromeos/dbus/power_policy_controller.h" 23 #include "chromeos/dbus/power_policy_controller.h"
23 #include "chromeos/network/onc/onc_signature.h" 24 #include "chromeos/network/onc/onc_signature.h"
24 #include "chromeos/network/onc/onc_utils.h" 25 #include "chromeos/network/onc/onc_utils.h"
25 #include "chromeos/network/onc/onc_validator.h" 26 #include "chromeos/network/onc/onc_validator.h"
26 #include "components/onc/onc_constants.h" 27 #include "components/onc/onc_constants.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 const char kIdleActionBattery[] = "Battery.IdleAction"; 79 const char kIdleActionBattery[] = "Battery.IdleAction";
79 80
80 const char kScreenLockDelayAC[] = "AC"; 81 const char kScreenLockDelayAC[] = "AC";
81 const char kScreenLockDelayBattery[] = "Battery"; 82 const char kScreenLockDelayBattery[] = "Battery";
82 83
83 const char kActionSuspend[] = "Suspend"; 84 const char kActionSuspend[] = "Suspend";
84 const char kActionLogout[] = "Logout"; 85 const char kActionLogout[] = "Logout";
85 const char kActionShutdown[] = "Shutdown"; 86 const char kActionShutdown[] = "Shutdown";
86 const char kActionDoNothing[] = "DoNothing"; 87 const char kActionDoNothing[] = "DoNothing";
87 88
88 scoped_ptr<base::Value> GetValue(const base::DictionaryValue* dict, 89 std::unique_ptr<base::Value> GetValue(const base::DictionaryValue* dict,
89 const char* key) { 90 const char* key) {
90 const base::Value* value = NULL; 91 const base::Value* value = NULL;
91 if (!dict->Get(key, &value)) 92 if (!dict->Get(key, &value))
92 return scoped_ptr<base::Value>(); 93 return std::unique_ptr<base::Value>();
93 return value->CreateDeepCopy(); 94 return value->CreateDeepCopy();
94 } 95 }
95 96
96 scoped_ptr<base::Value> GetAction(const base::DictionaryValue* dict, 97 std::unique_ptr<base::Value> GetAction(const base::DictionaryValue* dict,
97 const char* key) { 98 const char* key) {
98 scoped_ptr<base::Value> value = GetValue(dict, key); 99 std::unique_ptr<base::Value> value = GetValue(dict, key);
99 std::string action; 100 std::string action;
100 if (!value || !value->GetAsString(&action)) 101 if (!value || !value->GetAsString(&action))
101 return scoped_ptr<base::Value>(); 102 return std::unique_ptr<base::Value>();
102 if (action == kActionSuspend) { 103 if (action == kActionSuspend) {
103 return scoped_ptr<base::Value>(new base::FundamentalValue( 104 return std::unique_ptr<base::Value>(new base::FundamentalValue(
104 chromeos::PowerPolicyController::ACTION_SUSPEND)); 105 chromeos::PowerPolicyController::ACTION_SUSPEND));
105 } 106 }
106 if (action == kActionLogout) { 107 if (action == kActionLogout) {
107 return scoped_ptr<base::Value>(new base::FundamentalValue( 108 return std::unique_ptr<base::Value>(new base::FundamentalValue(
108 chromeos::PowerPolicyController::ACTION_STOP_SESSION)); 109 chromeos::PowerPolicyController::ACTION_STOP_SESSION));
109 } 110 }
110 if (action == kActionShutdown) { 111 if (action == kActionShutdown) {
111 return scoped_ptr<base::Value>(new base::FundamentalValue( 112 return std::unique_ptr<base::Value>(new base::FundamentalValue(
112 chromeos::PowerPolicyController::ACTION_SHUT_DOWN)); 113 chromeos::PowerPolicyController::ACTION_SHUT_DOWN));
113 } 114 }
114 if (action == kActionDoNothing) { 115 if (action == kActionDoNothing) {
115 return scoped_ptr<base::Value>(new base::FundamentalValue( 116 return std::unique_ptr<base::Value>(new base::FundamentalValue(
116 chromeos::PowerPolicyController::ACTION_DO_NOTHING)); 117 chromeos::PowerPolicyController::ACTION_DO_NOTHING));
117 } 118 }
118 return scoped_ptr<base::Value>(); 119 return std::unique_ptr<base::Value>();
119 } 120 }
120 121
121 } // namespace 122 } // namespace
122 123
123 ExternalDataPolicyHandler::ExternalDataPolicyHandler(const char* policy_name) 124 ExternalDataPolicyHandler::ExternalDataPolicyHandler(const char* policy_name)
124 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_DICTIONARY) { 125 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_DICTIONARY) {
125 } 126 }
126 127
127 ExternalDataPolicyHandler::~ExternalDataPolicyHandler() { 128 ExternalDataPolicyHandler::~ExternalDataPolicyHandler() {
128 } 129 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 bool NetworkConfigurationPolicyHandler::CheckPolicySettings( 194 bool NetworkConfigurationPolicyHandler::CheckPolicySettings(
194 const PolicyMap& policies, 195 const PolicyMap& policies,
195 PolicyErrorMap* errors) { 196 PolicyErrorMap* errors) {
196 const base::Value* value; 197 const base::Value* value;
197 if (!CheckAndGetValue(policies, errors, &value)) 198 if (!CheckAndGetValue(policies, errors, &value))
198 return false; 199 return false;
199 200
200 if (value) { 201 if (value) {
201 std::string onc_blob; 202 std::string onc_blob;
202 value->GetAsString(&onc_blob); 203 value->GetAsString(&onc_blob);
203 scoped_ptr<base::DictionaryValue> root_dict = 204 std::unique_ptr<base::DictionaryValue> root_dict =
204 chromeos::onc::ReadDictionaryFromJson(onc_blob); 205 chromeos::onc::ReadDictionaryFromJson(onc_blob);
205 if (root_dict.get() == NULL) { 206 if (root_dict.get() == NULL) {
206 errors->AddError(policy_name(), IDS_POLICY_NETWORK_CONFIG_PARSE_FAILED); 207 errors->AddError(policy_name(), IDS_POLICY_NETWORK_CONFIG_PARSE_FAILED);
207 return false; 208 return false;
208 } 209 }
209 210
210 // Validate the ONC dictionary. We are liberal and ignore unknown field 211 // Validate the ONC dictionary. We are liberal and ignore unknown field
211 // names and ignore invalid field names in kRecommended arrays. 212 // names and ignore invalid field names in kRecommended arrays.
212 chromeos::onc::Validator validator( 213 chromeos::onc::Validator validator(
213 false, // Ignore unknown fields. 214 false, // Ignore unknown fields.
(...skipping 22 matching lines...) Expand all
236 void NetworkConfigurationPolicyHandler::ApplyPolicySettings( 237 void NetworkConfigurationPolicyHandler::ApplyPolicySettings(
237 const PolicyMap& policies, 238 const PolicyMap& policies,
238 PrefValueMap* prefs) { 239 PrefValueMap* prefs) {
239 const base::Value* value = policies.GetValue(policy_name()); 240 const base::Value* value = policies.GetValue(policy_name());
240 if (!value) 241 if (!value)
241 return; 242 return;
242 243
243 std::string onc_blob; 244 std::string onc_blob;
244 value->GetAsString(&onc_blob); 245 value->GetAsString(&onc_blob);
245 246
246 scoped_ptr<base::ListValue> network_configs(new base::ListValue); 247 std::unique_ptr<base::ListValue> network_configs(new base::ListValue);
247 base::ListValue certificates; 248 base::ListValue certificates;
248 base::DictionaryValue global_network_config; 249 base::DictionaryValue global_network_config;
249 chromeos::onc::ParseAndValidateOncForImport(onc_blob, 250 chromeos::onc::ParseAndValidateOncForImport(onc_blob,
250 onc_source_, 251 onc_source_,
251 "", 252 "",
252 network_configs.get(), 253 network_configs.get(),
253 &global_network_config, 254 &global_network_config,
254 &certificates); 255 &certificates);
255 256
256 // Currently, only the per-network configuration is stored in a pref. Ignore 257 // Currently, only the per-network configuration is stored in a pref. Ignore
(...skipping 23 matching lines...) Expand all
280 pref_path_(pref_path) { 281 pref_path_(pref_path) {
281 } 282 }
282 283
283 // static 284 // static
284 base::Value* NetworkConfigurationPolicyHandler::SanitizeNetworkConfig( 285 base::Value* NetworkConfigurationPolicyHandler::SanitizeNetworkConfig(
285 const base::Value* config) { 286 const base::Value* config) {
286 std::string json_string; 287 std::string json_string;
287 if (!config->GetAsString(&json_string)) 288 if (!config->GetAsString(&json_string))
288 return NULL; 289 return NULL;
289 290
290 scoped_ptr<base::DictionaryValue> toplevel_dict = 291 std::unique_ptr<base::DictionaryValue> toplevel_dict =
291 chromeos::onc::ReadDictionaryFromJson(json_string); 292 chromeos::onc::ReadDictionaryFromJson(json_string);
292 if (!toplevel_dict) 293 if (!toplevel_dict)
293 return NULL; 294 return NULL;
294 295
295 // Placeholder to insert in place of the filtered setting. 296 // Placeholder to insert in place of the filtered setting.
296 const char kPlaceholder[] = "********"; 297 const char kPlaceholder[] = "********";
297 298
298 toplevel_dict = chromeos::onc::MaskCredentialsInOncObject( 299 toplevel_dict = chromeos::onc::MaskCredentialsInOncObject(
299 chromeos::onc::kToplevelConfigurationSignature, 300 chromeos::onc::kToplevelConfigurationSignature,
300 *toplevel_dict, 301 *toplevel_dict,
(...skipping 11 matching lines...) Expand all
312 313
313 PinnedLauncherAppsPolicyHandler::~PinnedLauncherAppsPolicyHandler() {} 314 PinnedLauncherAppsPolicyHandler::~PinnedLauncherAppsPolicyHandler() {}
314 315
315 void PinnedLauncherAppsPolicyHandler::ApplyPolicySettings( 316 void PinnedLauncherAppsPolicyHandler::ApplyPolicySettings(
316 const PolicyMap& policies, 317 const PolicyMap& policies,
317 PrefValueMap* prefs) { 318 PrefValueMap* prefs) {
318 PolicyErrorMap errors; 319 PolicyErrorMap errors;
319 const base::Value* policy_value = policies.GetValue(policy_name()); 320 const base::Value* policy_value = policies.GetValue(policy_name());
320 const base::ListValue* policy_list = NULL; 321 const base::ListValue* policy_list = NULL;
321 if (policy_value && policy_value->GetAsList(&policy_list) && policy_list) { 322 if (policy_value && policy_value->GetAsList(&policy_list) && policy_list) {
322 scoped_ptr<base::ListValue> pinned_apps_list(new base::ListValue()); 323 std::unique_ptr<base::ListValue> pinned_apps_list(new base::ListValue());
323 for (base::ListValue::const_iterator entry(policy_list->begin()); 324 for (base::ListValue::const_iterator entry(policy_list->begin());
324 entry != policy_list->end(); ++entry) { 325 entry != policy_list->end(); ++entry) {
325 std::string id; 326 std::string id;
326 if ((*entry)->GetAsString(&id)) { 327 if ((*entry)->GetAsString(&id)) {
327 base::DictionaryValue* app_dict = new base::DictionaryValue(); 328 base::DictionaryValue* app_dict = new base::DictionaryValue();
328 app_dict->SetString(ash::kPinnedAppsPrefAppIDPath, id); 329 app_dict->SetString(ash::kPinnedAppsPrefAppIDPath, id);
329 pinned_apps_list->Append(app_dict); 330 pinned_apps_list->Append(app_dict);
330 } 331 }
331 } 332 }
332 prefs->SetValue(pref_path(), std::move(pinned_apps_list)); 333 prefs->SetValue(pref_path(), std::move(pinned_apps_list));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 SCHEMA_ALLOW_UNKNOWN) { 399 SCHEMA_ALLOW_UNKNOWN) {
399 } 400 }
400 401
401 PowerManagementIdleSettingsPolicyHandler:: 402 PowerManagementIdleSettingsPolicyHandler::
402 ~PowerManagementIdleSettingsPolicyHandler() { 403 ~PowerManagementIdleSettingsPolicyHandler() {
403 } 404 }
404 405
405 void PowerManagementIdleSettingsPolicyHandler::ApplyPolicySettings( 406 void PowerManagementIdleSettingsPolicyHandler::ApplyPolicySettings(
406 const PolicyMap& policies, 407 const PolicyMap& policies,
407 PrefValueMap* prefs) { 408 PrefValueMap* prefs) {
408 scoped_ptr<base::Value> policy_value; 409 std::unique_ptr<base::Value> policy_value;
409 if (!CheckAndGetValue(policies, NULL, &policy_value)) 410 if (!CheckAndGetValue(policies, NULL, &policy_value))
410 return; 411 return;
411 const base::DictionaryValue* dict = NULL; 412 const base::DictionaryValue* dict = NULL;
412 if (!policy_value->GetAsDictionary(&dict)) { 413 if (!policy_value->GetAsDictionary(&dict)) {
413 NOTREACHED(); 414 NOTREACHED();
414 return; 415 return;
415 } 416 }
416 scoped_ptr<base::Value> value; 417 std::unique_ptr<base::Value> value;
417 418
418 value = GetValue(dict, kScreenDimDelayAC); 419 value = GetValue(dict, kScreenDimDelayAC);
419 if (value) 420 if (value)
420 prefs->SetValue(prefs::kPowerAcScreenDimDelayMs, std::move(value)); 421 prefs->SetValue(prefs::kPowerAcScreenDimDelayMs, std::move(value));
421 value = GetValue(dict, kScreenOffDelayAC); 422 value = GetValue(dict, kScreenOffDelayAC);
422 if (value) 423 if (value)
423 prefs->SetValue(prefs::kPowerAcScreenOffDelayMs, std::move(value)); 424 prefs->SetValue(prefs::kPowerAcScreenOffDelayMs, std::move(value));
424 value = GetValue(dict, kIdleWarningDelayAC); 425 value = GetValue(dict, kIdleWarningDelayAC);
425 if (value) 426 if (value)
426 prefs->SetValue(prefs::kPowerAcIdleWarningDelayMs, std::move(value)); 427 prefs->SetValue(prefs::kPowerAcIdleWarningDelayMs, std::move(value));
(...skipping 28 matching lines...) Expand all
455 chrome_schema.GetKnownProperty(key::kScreenLockDelays), 456 chrome_schema.GetKnownProperty(key::kScreenLockDelays),
456 SCHEMA_ALLOW_UNKNOWN) { 457 SCHEMA_ALLOW_UNKNOWN) {
457 } 458 }
458 459
459 ScreenLockDelayPolicyHandler::~ScreenLockDelayPolicyHandler() { 460 ScreenLockDelayPolicyHandler::~ScreenLockDelayPolicyHandler() {
460 } 461 }
461 462
462 void ScreenLockDelayPolicyHandler::ApplyPolicySettings( 463 void ScreenLockDelayPolicyHandler::ApplyPolicySettings(
463 const PolicyMap& policies, 464 const PolicyMap& policies,
464 PrefValueMap* prefs) { 465 PrefValueMap* prefs) {
465 scoped_ptr<base::Value> policy_value; 466 std::unique_ptr<base::Value> policy_value;
466 if (!CheckAndGetValue(policies, NULL, &policy_value)) 467 if (!CheckAndGetValue(policies, NULL, &policy_value))
467 return; 468 return;
468 const base::DictionaryValue* dict = NULL; 469 const base::DictionaryValue* dict = NULL;
469 if (!policy_value->GetAsDictionary(&dict)) { 470 if (!policy_value->GetAsDictionary(&dict)) {
470 NOTREACHED(); 471 NOTREACHED();
471 return; 472 return;
472 } 473 }
473 scoped_ptr<base::Value> value; 474 std::unique_ptr<base::Value> value;
474 475
475 value = GetValue(dict, kScreenLockDelayAC); 476 value = GetValue(dict, kScreenLockDelayAC);
476 if (value) 477 if (value)
477 prefs->SetValue(prefs::kPowerAcScreenLockDelayMs, std::move(value)); 478 prefs->SetValue(prefs::kPowerAcScreenLockDelayMs, std::move(value));
478 value = GetValue(dict, kScreenLockDelayBattery); 479 value = GetValue(dict, kScreenLockDelayBattery);
479 if (value) 480 if (value)
480 prefs->SetValue(prefs::kPowerBatteryScreenLockDelayMs, std::move(value)); 481 prefs->SetValue(prefs::kPowerBatteryScreenLockDelayMs, std::move(value));
481 } 482 }
482 483
483 } // namespace policy 484 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698