| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/policy_handlers.h" | 5 #include "chrome/browser/extensions/policy_handlers.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 bool ExtensionListPolicyHandler::CheckPolicySettings( | 37 bool ExtensionListPolicyHandler::CheckPolicySettings( |
| 38 const policy::PolicyMap& policies, | 38 const policy::PolicyMap& policies, |
| 39 policy::PolicyErrorMap* errors) { | 39 policy::PolicyErrorMap* errors) { |
| 40 return CheckAndGetList(policies, errors, NULL); | 40 return CheckAndGetList(policies, errors, NULL); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ExtensionListPolicyHandler::ApplyPolicySettings( | 43 void ExtensionListPolicyHandler::ApplyPolicySettings( |
| 44 const policy::PolicyMap& policies, | 44 const policy::PolicyMap& policies, |
| 45 PrefValueMap* prefs) { | 45 PrefValueMap* prefs) { |
| 46 scoped_ptr<base::ListValue> list; | 46 std::unique_ptr<base::ListValue> list; |
| 47 policy::PolicyErrorMap errors; | 47 policy::PolicyErrorMap errors; |
| 48 if (CheckAndGetList(policies, &errors, &list) && list) | 48 if (CheckAndGetList(policies, &errors, &list) && list) |
| 49 prefs->SetValue(pref_path(), std::move(list)); | 49 prefs->SetValue(pref_path(), std::move(list)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 const char* ExtensionListPolicyHandler::pref_path() const { | 52 const char* ExtensionListPolicyHandler::pref_path() const { |
| 53 return pref_path_; | 53 return pref_path_; |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool ExtensionListPolicyHandler::CheckAndGetList( | 56 bool ExtensionListPolicyHandler::CheckAndGetList( |
| 57 const policy::PolicyMap& policies, | 57 const policy::PolicyMap& policies, |
| 58 policy::PolicyErrorMap* errors, | 58 policy::PolicyErrorMap* errors, |
| 59 scoped_ptr<base::ListValue>* extension_ids) { | 59 std::unique_ptr<base::ListValue>* extension_ids) { |
| 60 if (extension_ids) | 60 if (extension_ids) |
| 61 extension_ids->reset(); | 61 extension_ids->reset(); |
| 62 | 62 |
| 63 const base::Value* value = NULL; | 63 const base::Value* value = NULL; |
| 64 if (!CheckAndGetValue(policies, errors, &value)) | 64 if (!CheckAndGetValue(policies, errors, &value)) |
| 65 return false; | 65 return false; |
| 66 | 66 |
| 67 if (!value) | 67 if (!value) |
| 68 return true; | 68 return true; |
| 69 | 69 |
| 70 const base::ListValue* list_value = NULL; | 70 const base::ListValue* list_value = NULL; |
| 71 if (!value->GetAsList(&list_value)) { | 71 if (!value->GetAsList(&list_value)) { |
| 72 NOTREACHED(); | 72 NOTREACHED(); |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Filter the list, rejecting any invalid extension IDs. | 76 // Filter the list, rejecting any invalid extension IDs. |
| 77 scoped_ptr<base::ListValue> filtered_list(new base::ListValue()); | 77 std::unique_ptr<base::ListValue> filtered_list(new base::ListValue()); |
| 78 for (base::ListValue::const_iterator entry(list_value->begin()); | 78 for (base::ListValue::const_iterator entry(list_value->begin()); |
| 79 entry != list_value->end(); ++entry) { | 79 entry != list_value->end(); ++entry) { |
| 80 std::string id; | 80 std::string id; |
| 81 if (!(*entry)->GetAsString(&id)) { | 81 if (!(*entry)->GetAsString(&id)) { |
| 82 errors->AddError(policy_name(), | 82 errors->AddError(policy_name(), |
| 83 entry - list_value->begin(), | 83 entry - list_value->begin(), |
| 84 IDS_POLICY_TYPE_ERROR, | 84 IDS_POLICY_TYPE_ERROR, |
| 85 ValueTypeToString(base::Value::TYPE_STRING)); | 85 ValueTypeToString(base::Value::TYPE_STRING)); |
| 86 continue; | 86 continue; |
| 87 } | 87 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 114 policy::PolicyErrorMap* errors) { | 114 policy::PolicyErrorMap* errors) { |
| 115 const base::Value* value; | 115 const base::Value* value; |
| 116 return CheckAndGetValue(policies, errors, &value) && | 116 return CheckAndGetValue(policies, errors, &value) && |
| 117 ParseList(value, NULL, errors); | 117 ParseList(value, NULL, errors); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void ExtensionInstallForcelistPolicyHandler::ApplyPolicySettings( | 120 void ExtensionInstallForcelistPolicyHandler::ApplyPolicySettings( |
| 121 const policy::PolicyMap& policies, | 121 const policy::PolicyMap& policies, |
| 122 PrefValueMap* prefs) { | 122 PrefValueMap* prefs) { |
| 123 const base::Value* value = NULL; | 123 const base::Value* value = NULL; |
| 124 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 124 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 125 if (CheckAndGetValue(policies, NULL, &value) && | 125 if (CheckAndGetValue(policies, NULL, &value) && |
| 126 value && | 126 value && |
| 127 ParseList(value, dict.get(), NULL)) { | 127 ParseList(value, dict.get(), NULL)) { |
| 128 prefs->SetValue(pref_names::kInstallForceList, std::move(dict)); | 128 prefs->SetValue(pref_names::kInstallForceList, std::move(dict)); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool ExtensionInstallForcelistPolicyHandler::ParseList( | 132 bool ExtensionInstallForcelistPolicyHandler::ParseList( |
| 133 const base::Value* policy_value, | 133 const base::Value* policy_value, |
| 134 base::DictionaryValue* extension_dict, | 134 base::DictionaryValue* extension_dict, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 chrome_schema.GetKnownProperty(policy::key::kExtensionSettings), | 259 chrome_schema.GetKnownProperty(policy::key::kExtensionSettings), |
| 260 policy::SCHEMA_ALLOW_UNKNOWN) { | 260 policy::SCHEMA_ALLOW_UNKNOWN) { |
| 261 } | 261 } |
| 262 | 262 |
| 263 ExtensionSettingsPolicyHandler::~ExtensionSettingsPolicyHandler() { | 263 ExtensionSettingsPolicyHandler::~ExtensionSettingsPolicyHandler() { |
| 264 } | 264 } |
| 265 | 265 |
| 266 bool ExtensionSettingsPolicyHandler::CheckPolicySettings( | 266 bool ExtensionSettingsPolicyHandler::CheckPolicySettings( |
| 267 const policy::PolicyMap& policies, | 267 const policy::PolicyMap& policies, |
| 268 policy::PolicyErrorMap* errors) { | 268 policy::PolicyErrorMap* errors) { |
| 269 scoped_ptr<base::Value> policy_value; | 269 std::unique_ptr<base::Value> policy_value; |
| 270 if (!CheckAndGetValue(policies, errors, &policy_value)) | 270 if (!CheckAndGetValue(policies, errors, &policy_value)) |
| 271 return false; | 271 return false; |
| 272 if (!policy_value) | 272 if (!policy_value) |
| 273 return true; | 273 return true; |
| 274 | 274 |
| 275 // |policy_value| is expected to conform to the defined schema. But it's | 275 // |policy_value| is expected to conform to the defined schema. But it's |
| 276 // not strictly valid since there are additional restrictions. | 276 // not strictly valid since there are additional restrictions. |
| 277 const base::DictionaryValue* dict_value = NULL; | 277 const base::DictionaryValue* dict_value = NULL; |
| 278 DCHECK(policy_value->IsType(base::Value::TYPE_DICTIONARY)); | 278 DCHECK(policy_value->IsType(base::Value::TYPE_DICTIONARY)); |
| 279 policy_value->GetAsDictionary(&dict_value); | 279 policy_value->GetAsDictionary(&dict_value); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 | 316 |
| 317 return true; | 317 return true; |
| 318 } | 318 } |
| 319 | 319 |
| 320 void ExtensionSettingsPolicyHandler::ApplyPolicySettings( | 320 void ExtensionSettingsPolicyHandler::ApplyPolicySettings( |
| 321 const policy::PolicyMap& policies, | 321 const policy::PolicyMap& policies, |
| 322 PrefValueMap* prefs) { | 322 PrefValueMap* prefs) { |
| 323 scoped_ptr<base::Value> policy_value; | 323 std::unique_ptr<base::Value> policy_value; |
| 324 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value) | 324 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value) |
| 325 return; | 325 return; |
| 326 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value)); | 326 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value)); |
| 327 } | 327 } |
| 328 | 328 |
| 329 } // namespace extensions | 329 } // namespace extensions |
| OLD | NEW |