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

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

Issue 2306143002: Plumbing for login apps device policy to extensions. (Closed)
Patch Set: Removed unnecessary logging Created 4 years, 1 month 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 ExtensionInstallListPolicyHandler::~ExtensionInstallListPolicyHandler() {}
109 ~ExtensionInstallForcelistPolicyHandler() {}
110 111
111 bool ExtensionInstallForcelistPolicyHandler::CheckPolicySettings( 112 bool ExtensionInstallListPolicyHandler::CheckPolicySettings(
112 const policy::PolicyMap& policies, 113 const policy::PolicyMap& policies,
113 policy::PolicyErrorMap* errors) { 114 policy::PolicyErrorMap* errors) {
114 const base::Value* value; 115 const base::Value* value;
115 return CheckAndGetValue(policies, errors, &value) && 116 return CheckAndGetValue(policies, errors, &value) &&
116 ParseList(value, NULL, errors); 117 ParseList(value, nullptr, errors);
117 } 118 }
118 119
119 void ExtensionInstallForcelistPolicyHandler::ApplyPolicySettings( 120 void ExtensionInstallListPolicyHandler::ApplyPolicySettings(
120 const policy::PolicyMap& policies, 121 const policy::PolicyMap& policies,
121 PrefValueMap* prefs) { 122 PrefValueMap* prefs) {
122 const base::Value* value = NULL; 123 const base::Value* value = nullptr;
123 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 124 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
124 if (CheckAndGetValue(policies, NULL, &value) && 125 if (CheckAndGetValue(policies, nullptr, &value) && value &&
125 value && 126 ParseList(value, dict.get(), nullptr)) {
126 ParseList(value, dict.get(), NULL)) { 127 prefs->SetValue(pref_name(), std::move(dict));
127 prefs->SetValue(pref_names::kInstallForceList, std::move(dict));
128 } 128 }
129 } 129 }
130 130
131 bool ExtensionInstallForcelistPolicyHandler::ParseList( 131 bool ExtensionInstallListPolicyHandler::ParseList(
132 const base::Value* policy_value, 132 const base::Value* policy_value,
133 base::DictionaryValue* extension_dict, 133 base::DictionaryValue* extension_dict,
134 policy::PolicyErrorMap* errors) { 134 policy::PolicyErrorMap* errors) {
135 if (!policy_value) 135 if (!policy_value)
136 return true; 136 return true;
137 137
138 const base::ListValue* policy_list_value = NULL; 138 const base::ListValue* policy_list_value = nullptr;
139 if (!policy_value->GetAsList(&policy_list_value)) { 139 if (!policy_value->GetAsList(&policy_list_value)) {
140 // This should have been caught in CheckPolicySettings. 140 // This should have been caught in CheckPolicySettings.
141 NOTREACHED(); 141 NOTREACHED();
142 return false; 142 return false;
143 } 143 }
144 144
145 for (base::ListValue::const_iterator entry(policy_list_value->begin()); 145 for (base::ListValue::const_iterator entry(policy_list_value->begin());
146 entry != policy_list_value->end(); ++entry) { 146 entry != policy_list_value->end(); ++entry) {
147 std::string entry_string; 147 std::string entry_string;
148 if (!(*entry)->GetAsString(&entry_string)) { 148 if (!(*entry)->GetAsString(&entry_string)) {
(...skipping 11 matching lines...) Expand all
160 size_t pos = entry_string.find(';'); 160 size_t pos = entry_string.find(';');
161 if (pos == std::string::npos) { 161 if (pos == std::string::npos) {
162 if (errors) { 162 if (errors) {
163 errors->AddError(policy_name(), 163 errors->AddError(policy_name(),
164 entry - policy_list_value->begin(), 164 entry - policy_list_value->begin(),
165 IDS_POLICY_VALUE_FORMAT_ERROR); 165 IDS_POLICY_VALUE_FORMAT_ERROR);
166 } 166 }
167 continue; 167 continue;
168 } 168 }
169 169
170 std::string extension_id = entry_string.substr(0, pos); 170 const std::string extension_id = entry_string.substr(0, pos);
171 std::string update_url = entry_string.substr(pos+1); 171 const std::string update_url = entry_string.substr(pos + 1);
172 if (!crx_file::id_util::IdIsValid(extension_id) || 172 if (!crx_file::id_util::IdIsValid(extension_id) ||
173 !GURL(update_url).is_valid()) { 173 !GURL(update_url).is_valid()) {
174 if (errors) { 174 if (errors) {
175 errors->AddError(policy_name(), 175 errors->AddError(policy_name(),
176 entry - policy_list_value->begin(), 176 entry - policy_list_value->begin(),
177 IDS_POLICY_VALUE_FORMAT_ERROR); 177 IDS_POLICY_VALUE_FORMAT_ERROR);
178 } 178 }
179 continue; 179 continue;
180 } 180 }
181 181
182 if (extension_dict) { 182 if (extension_dict) {
183 extensions::ExternalPolicyLoader::AddExtension( 183 ExternalPolicyLoader::AddExtension(extension_dict, extension_id,
184 extension_dict, extension_id, update_url); 184 update_url);
185 } 185 }
186 } 186 }
187 187
188 return true; 188 return true;
189 } 189 }
190 190
191 // ExtensionInstallForcelistPolicyHandler implementation -----------------------
192
193 ExtensionInstallForcelistPolicyHandler::ExtensionInstallForcelistPolicyHandler()
194 : ExtensionInstallListPolicyHandler(policy::key::kExtensionInstallForcelist,
195 pref_names::kInstallForceList) {}
196
197 ExtensionInstallForcelistPolicyHandler::
198 ~ExtensionInstallForcelistPolicyHandler() {}
199
200 // ExtensionInstallSigninlistPolicyHandler implementation
201 // -----------------------
Devlin 2017/03/01 16:15:00 nit: no need for a new line with this.
202
203 ExtensionInstallSigninListPolicyHandler::
204 ExtensionInstallSigninListPolicyHandler()
205 : ExtensionInstallListPolicyHandler(policy::key::kLoginApps,
206 pref_names::kInstallSigninList) {}
207
208 ExtensionInstallSigninListPolicyHandler::
209 ~ExtensionInstallSigninListPolicyHandler() {}
210
191 // ExtensionURLPatternListPolicyHandler implementation ------------------------- 211 // ExtensionURLPatternListPolicyHandler implementation -------------------------
192 212
193 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler( 213 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler(
194 const char* policy_name, 214 const char* policy_name,
195 const char* pref_path) 215 const char* pref_path)
196 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), 216 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST),
197 pref_path_(pref_path) {} 217 pref_path_(pref_path) {}
198 218
199 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {} 219 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {}
200 220
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 void ExtensionSettingsPolicyHandler::ApplyPolicySettings( 337 void ExtensionSettingsPolicyHandler::ApplyPolicySettings(
318 const policy::PolicyMap& policies, 338 const policy::PolicyMap& policies,
319 PrefValueMap* prefs) { 339 PrefValueMap* prefs) {
320 std::unique_ptr<base::Value> policy_value; 340 std::unique_ptr<base::Value> policy_value;
321 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value) 341 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value)
322 return; 342 return;
323 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value)); 343 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value));
324 } 344 }
325 345
326 } // namespace extensions 346 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698