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

Side by Side Diff: chrome/browser/extensions/policy_handlers.cc

Issue 2144313002: Plumbing for login apps device policy to extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Devlin feedback Created 3 years, 9 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 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 filtered_list->AppendString(id); 93 filtered_list->AppendString(id);
94 } 94 }
95 95
96 if (extension_ids) 96 if (extension_ids)
97 *extension_ids = std::move(filtered_list); 97 *extension_ids = std::move(filtered_list);
98 98
99 return true; 99 return true;
100 } 100 }
101 101
102 // ExtensionInstallForcelistPolicyHandler implementation ----------------------- 102 // ExtensionInstallListPolicyHandler implementation ----------------------------
103 103
104 ExtensionInstallForcelistPolicyHandler::ExtensionInstallForcelistPolicyHandler() 104 ExtensionInstallListPolicyHandler::ExtensionInstallListPolicyHandler(
105 : policy::TypeCheckingPolicyHandler(policy::key::kExtensionInstallForcelist, 105 const char* policy_name,
106 base::Value::Type::LIST) {} 106 const char* pref_name)
107 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::Type::LIST),
108 pref_name_(pref_name) {}
107 109
108 ExtensionInstallForcelistPolicyHandler:: 110 bool ExtensionInstallListPolicyHandler::CheckPolicySettings(
109 ~ExtensionInstallForcelistPolicyHandler() {}
110
111 bool ExtensionInstallForcelistPolicyHandler::CheckPolicySettings(
112 const policy::PolicyMap& policies, 111 const policy::PolicyMap& policies,
113 policy::PolicyErrorMap* errors) { 112 policy::PolicyErrorMap* errors) {
114 const base::Value* value; 113 const base::Value* value;
115 return CheckAndGetValue(policies, errors, &value) && 114 return CheckAndGetValue(policies, errors, &value) &&
116 ParseList(value, NULL, errors); 115 ParseList(value, nullptr, errors);
117 } 116 }
118 117
119 void ExtensionInstallForcelistPolicyHandler::ApplyPolicySettings( 118 void ExtensionInstallListPolicyHandler::ApplyPolicySettings(
120 const policy::PolicyMap& policies, 119 const policy::PolicyMap& policies,
121 PrefValueMap* prefs) { 120 PrefValueMap* prefs) {
122 const base::Value* value = NULL; 121 const base::Value* value = nullptr;
123 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 122 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
124 if (CheckAndGetValue(policies, NULL, &value) && 123 if (CheckAndGetValue(policies, nullptr, &value) && value &&
125 value && 124 ParseList(value, dict.get(), nullptr)) {
126 ParseList(value, dict.get(), NULL)) { 125 prefs->SetValue(pref_name_, std::move(dict));
127 prefs->SetValue(pref_names::kInstallForceList, std::move(dict));
128 } 126 }
129 } 127 }
130 128
131 bool ExtensionInstallForcelistPolicyHandler::ParseList( 129 bool ExtensionInstallListPolicyHandler::ParseList(
132 const base::Value* policy_value, 130 const base::Value* policy_value,
133 base::DictionaryValue* extension_dict, 131 base::DictionaryValue* extension_dict,
134 policy::PolicyErrorMap* errors) { 132 policy::PolicyErrorMap* errors) {
135 if (!policy_value) 133 if (!policy_value)
136 return true; 134 return true;
137 135
138 const base::ListValue* policy_list_value = NULL; 136 const base::ListValue* policy_list_value = nullptr;
139 if (!policy_value->GetAsList(&policy_list_value)) { 137 if (!policy_value->GetAsList(&policy_list_value)) {
140 // This should have been caught in CheckPolicySettings. 138 // This should have been caught in CheckPolicySettings.
141 NOTREACHED(); 139 NOTREACHED();
142 return false; 140 return false;
143 } 141 }
144 142
145 for (base::ListValue::const_iterator entry(policy_list_value->begin()); 143 for (base::ListValue::const_iterator entry(policy_list_value->begin());
146 entry != policy_list_value->end(); ++entry) { 144 entry != policy_list_value->end(); ++entry) {
147 std::string entry_string; 145 std::string entry_string;
148 if (!(*entry)->GetAsString(&entry_string)) { 146 if (!(*entry)->GetAsString(&entry_string)) {
(...skipping 11 matching lines...) Expand all
160 size_t pos = entry_string.find(';'); 158 size_t pos = entry_string.find(';');
161 if (pos == std::string::npos) { 159 if (pos == std::string::npos) {
162 if (errors) { 160 if (errors) {
163 errors->AddError(policy_name(), 161 errors->AddError(policy_name(),
164 entry - policy_list_value->begin(), 162 entry - policy_list_value->begin(),
165 IDS_POLICY_VALUE_FORMAT_ERROR); 163 IDS_POLICY_VALUE_FORMAT_ERROR);
166 } 164 }
167 continue; 165 continue;
168 } 166 }
169 167
170 std::string extension_id = entry_string.substr(0, pos); 168 const std::string extension_id = entry_string.substr(0, pos);
171 std::string update_url = entry_string.substr(pos+1); 169 const std::string update_url = entry_string.substr(pos + 1);
172 if (!crx_file::id_util::IdIsValid(extension_id) || 170 if (!crx_file::id_util::IdIsValid(extension_id) ||
173 !GURL(update_url).is_valid()) { 171 !GURL(update_url).is_valid()) {
174 if (errors) { 172 if (errors) {
175 errors->AddError(policy_name(), 173 errors->AddError(policy_name(),
176 entry - policy_list_value->begin(), 174 entry - policy_list_value->begin(),
177 IDS_POLICY_VALUE_FORMAT_ERROR); 175 IDS_POLICY_VALUE_FORMAT_ERROR);
178 } 176 }
179 continue; 177 continue;
180 } 178 }
181 179
182 if (extension_dict) { 180 if (extension_dict) {
183 extensions::ExternalPolicyLoader::AddExtension( 181 ExternalPolicyLoader::AddExtension(extension_dict, extension_id,
184 extension_dict, extension_id, update_url); 182 update_url);
185 } 183 }
186 } 184 }
187 185
188 return true; 186 return true;
189 } 187 }
190 188
189 // ExtensionInstallForcelistPolicyHandler implementation -----------------------
190
191 ExtensionInstallForcelistPolicyHandler::ExtensionInstallForcelistPolicyHandler()
192 : ExtensionInstallListPolicyHandler(policy::key::kExtensionInstallForcelist,
193 pref_names::kInstallForceList) {}
194
195 // ExtensionInstallLoginScreenAppListPolicyHandler implementation --------------
196
197 ExtensionInstallLoginScreenAppListPolicyHandler::
198 ExtensionInstallLoginScreenAppListPolicyHandler()
199 : ExtensionInstallListPolicyHandler(
200 policy::key::kDeviceLoginScreenAppInstallList,
201 pref_names::kInstallLoginScreenAppList) {}
202
191 // ExtensionURLPatternListPolicyHandler implementation ------------------------- 203 // ExtensionURLPatternListPolicyHandler implementation -------------------------
192 204
193 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler( 205 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler(
194 const char* policy_name, 206 const char* policy_name,
195 const char* pref_path) 207 const char* pref_path)
196 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::Type::LIST), 208 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::Type::LIST),
197 pref_path_(pref_path) {} 209 pref_path_(pref_path) {}
198 210
199 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {} 211 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {}
200 212
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 void ExtensionSettingsPolicyHandler::ApplyPolicySettings( 329 void ExtensionSettingsPolicyHandler::ApplyPolicySettings(
318 const policy::PolicyMap& policies, 330 const policy::PolicyMap& policies,
319 PrefValueMap* prefs) { 331 PrefValueMap* prefs) {
320 std::unique_ptr<base::Value> policy_value; 332 std::unique_ptr<base::Value> policy_value;
321 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value) 333 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value)
322 return; 334 return;
323 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value)); 335 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value));
324 } 336 }
325 337
326 } // namespace extensions 338 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/policy_handlers.h ('k') | chrome/browser/extensions/standard_management_policy_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698