Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_loader.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/values.h" | |
| 9 #include "chrome/common/extensions/extension.h" | |
| 10 #include "chrome/common/pref_names.h" | |
| 11 #include "chrome/browser/browser_thread.h" | |
| 12 #include "chrome/browser/prefs/pref_service.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "googleurl/src/gurl.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 // Check an extension ID and an URL to be syntactically correct. | |
| 19 bool CheckExtension(std::string id, std::string update_url) { | |
| 20 GURL url(update_url); | |
| 21 if (!url.is_valid()) { | |
| 22 LOG(WARNING) << "Policy specifies invalid update URL for external " | |
| 23 << "extension: " << update_url; | |
| 24 return false; | |
| 25 } | |
| 26 if (!Extension::IdIsValid(id)) { | |
| 27 LOG(WARNING) << "Policy specifies invalid ID for external " | |
| 28 << "extension: " << id; | |
| 29 return false; | |
| 30 } | |
| 31 return true; | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 ExternalPolicyExtensionLoader::ExternalPolicyExtensionLoader( | |
| 37 Profile* profile) | |
| 38 : profile_(profile) { | |
|
jochen (gone - plz use gerrit)
2011/01/04 12:38:01
only indent 4 spaces
gfeher
2011/01/04 23:37:09
Done.
| |
| 39 pref_change_registrar_.Init(profile_->GetPrefs()); | |
| 40 pref_change_registrar_.Add(prefs::kExtensionInstallForceList, this); | |
| 41 notification_registrar_.Add(this, | |
| 42 NotificationType::PROFILE_DESTROYED, | |
| 43 Source<Profile>(profile_)); | |
| 44 } | |
| 45 | |
| 46 void ExternalPolicyExtensionLoader::Load() { | |
| 47 const ListValue* forcelist = | |
| 48 profile_->GetPrefs()->GetList(prefs::kExtensionInstallForceList); | |
| 49 DictionaryValue* result = new DictionaryValue(); | |
| 50 if (forcelist != NULL) { | |
| 51 std::string extension_desc; | |
| 52 for (ListValue::const_iterator it = forcelist->begin(); | |
| 53 it != forcelist->end(); ++it) { | |
| 54 if (!(*it)->GetAsString(&extension_desc)) { | |
| 55 LOG(WARNING) << "Failed to read forcelist string."; | |
| 56 } else { | |
| 57 // Each string item of the list has the following form: | |
| 58 // extension_id_code;extension_update_url | |
| 59 // The update URL might also contain semicolons. | |
| 60 size_t pos = extension_desc.find(';'); | |
| 61 std::string id = extension_desc.substr(0, pos); | |
| 62 std::string update_url = extension_desc.substr(pos+1); | |
| 63 if (CheckExtension(id, update_url)) { | |
| 64 result->SetString(id + ".external_update_url", update_url); | |
| 65 } | |
| 66 } | |
| 67 } | |
| 68 } | |
| 69 prefs_.reset(result); | |
| 70 LoadFinished(); | |
| 71 } | |
| 72 | |
| 73 void ExternalPolicyExtensionLoader::Observe( | |
| 74 NotificationType type, | |
| 75 const NotificationSource& source, | |
| 76 const NotificationDetails& details) { | |
| 77 if (profile_ == NULL) return; | |
| 78 switch (type.value) { | |
| 79 case NotificationType::PREF_CHANGED: { | |
| 80 if (Source<PrefService>(source).ptr() == profile_->GetPrefs()) { | |
| 81 std::string* pref_name = Details<std::string>(details).ptr(); | |
| 82 if (*pref_name == prefs::kExtensionInstallForceList) { | |
| 83 StartLoading(); | |
| 84 } else { | |
| 85 NOTREACHED() << "Unexpected preference name."; | |
| 86 } | |
| 87 } | |
| 88 break; | |
| 89 } | |
| 90 case NotificationType::PROFILE_DESTROYED: { | |
| 91 if (Source<Profile>(source).ptr() == profile_) { | |
| 92 notification_registrar_.RemoveAll(); | |
| 93 pref_change_registrar_.RemoveAll(); | |
| 94 profile_ = NULL; | |
| 95 } | |
| 96 break; | |
| 97 } | |
| 98 default: | |
| 99 NOTREACHED() << "Unexpected notification type."; | |
| 100 } | |
| 101 } | |
| OLD | NEW |