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

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

Issue 5742008: Clean up threading model of external extension providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/external_policy_extension_provider.h"
6
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "chrome/common/pref_names.h"
10 #include "chrome/browser/browser_thread.h"
11 #include "chrome/browser/extensions/stateful_external_extension_provider.h"
12 #include "chrome/browser/prefs/pref_service.h"
13
14 namespace {
15
16 // Check an extension ID and an URL to be syntactically correct.
17 bool CheckExtension(std::string id, std::string update_url) {
18 GURL url(update_url);
19 if (!url.is_valid()) {
20 LOG(WARNING) << "Policy specifies invalid update URL for external "
21 << "extension: " << update_url;
22 return false;
23 }
24 if (!Extension::IdIsValid(id)) {
25 LOG(WARNING) << "Policy specifies invalid ID for external "
26 << "extension: " << id;
27 return false;
28 }
29 return true;
30 }
31
32 }
33
34 ExternalPolicyExtensionProvider::ExternalPolicyExtensionProvider(
35 const ListValue* forcelist)
36 : StatefulExternalExtensionProvider(
37 Extension::INVALID,
38 Extension::EXTERNAL_POLICY_DOWNLOAD) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 ProcessPreferences(forcelist);
41 }
42
43 ExternalPolicyExtensionProvider::~ExternalPolicyExtensionProvider() {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45 }
46
47 void ExternalPolicyExtensionProvider::SetPreferences(
48 const ListValue* forcelist) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
50 ProcessPreferences(forcelist);
51 }
52
53 void ExternalPolicyExtensionProvider::ProcessPreferences(
54 const ListValue* forcelist) {
55 DictionaryValue* result = new DictionaryValue();
56 if (forcelist != NULL) {
57 std::string extension_desc;
58 for (ListValue::const_iterator it = forcelist->begin();
59 it != forcelist->end(); ++it) {
60 if (!(*it)->GetAsString(&extension_desc)) {
61 LOG(WARNING) << "Failed to read forcelist string.";
62 } else {
63 // Each string item of the list has the following form:
64 // extension_id_code;extension_update_url
65 // The update URL might also contain semicolons.
66 size_t pos = extension_desc.find(';');
67 std::string id = extension_desc.substr(0, pos);
68 std::string update_url = extension_desc.substr(pos+1);
69 if (CheckExtension(id, update_url)) {
70 result->SetString(id + ".external_update_url", update_url);
71 }
72 }
73 }
74 }
75 set_prefs(result);
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698