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