OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_loader.h" | 5 #include "chrome/browser/extensions/external_policy_extension_loader.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/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
| 14 #include "chrome/common/chrome_notification_types.h" |
14 #include "content/common/notification_service.h" | 15 #include "content/common/notification_service.h" |
15 #include "content/common/notification_type.h" | |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Check an extension ID and an URL to be syntactically correct. | 20 // Check an extension ID and an URL to be syntactically correct. |
21 bool CheckExtension(const std::string& id, const std::string& update_url) { | 21 bool CheckExtension(const std::string& id, const std::string& update_url) { |
22 GURL url(update_url); | 22 GURL url(update_url); |
23 if (!url.is_valid()) { | 23 if (!url.is_valid()) { |
24 LOG(WARNING) << "Policy specifies invalid update URL for external " | 24 LOG(WARNING) << "Policy specifies invalid update URL for external " |
25 << "extension: " << update_url; | 25 << "extension: " << update_url; |
26 return false; | 26 return false; |
27 } | 27 } |
28 if (!Extension::IdIsValid(id)) { | 28 if (!Extension::IdIsValid(id)) { |
29 LOG(WARNING) << "Policy specifies invalid ID for external " | 29 LOG(WARNING) << "Policy specifies invalid ID for external " |
30 << "extension: " << id; | 30 << "extension: " << id; |
31 return false; | 31 return false; |
32 } | 32 } |
33 return true; | 33 return true; |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 ExternalPolicyExtensionLoader::ExternalPolicyExtensionLoader( | 38 ExternalPolicyExtensionLoader::ExternalPolicyExtensionLoader( |
39 Profile* profile) | 39 Profile* profile) |
40 : profile_(profile) { | 40 : profile_(profile) { |
41 pref_change_registrar_.Init(profile_->GetPrefs()); | 41 pref_change_registrar_.Init(profile_->GetPrefs()); |
42 pref_change_registrar_.Add(prefs::kExtensionInstallForceList, this); | 42 pref_change_registrar_.Add(prefs::kExtensionInstallForceList, this); |
43 notification_registrar_.Add(this, | 43 notification_registrar_.Add(this, |
44 NotificationType::PROFILE_DESTROYED, | 44 chrome::NOTIFICATION_PROFILE_DESTROYED, |
45 Source<Profile>(profile_)); | 45 Source<Profile>(profile_)); |
46 } | 46 } |
47 | 47 |
48 void ExternalPolicyExtensionLoader::StartLoading() { | 48 void ExternalPolicyExtensionLoader::StartLoading() { |
49 const ListValue* forcelist = | 49 const ListValue* forcelist = |
50 profile_->GetPrefs()->GetList(prefs::kExtensionInstallForceList); | 50 profile_->GetPrefs()->GetList(prefs::kExtensionInstallForceList); |
51 DictionaryValue* result = new DictionaryValue(); | 51 DictionaryValue* result = new DictionaryValue(); |
52 if (forcelist != NULL) { | 52 if (forcelist != NULL) { |
53 std::string extension_desc; | 53 std::string extension_desc; |
54 for (ListValue::const_iterator it = forcelist->begin(); | 54 for (ListValue::const_iterator it = forcelist->begin(); |
(...skipping 11 matching lines...) Expand all Loading... |
66 result->SetString(id + ".external_update_url", update_url); | 66 result->SetString(id + ".external_update_url", update_url); |
67 } | 67 } |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 prefs_.reset(result); | 71 prefs_.reset(result); |
72 LoadFinished(); | 72 LoadFinished(); |
73 } | 73 } |
74 | 74 |
75 void ExternalPolicyExtensionLoader::Observe( | 75 void ExternalPolicyExtensionLoader::Observe( |
76 NotificationType type, | 76 int type, |
77 const NotificationSource& source, | 77 const NotificationSource& source, |
78 const NotificationDetails& details) { | 78 const NotificationDetails& details) { |
79 if (profile_ == NULL) return; | 79 if (profile_ == NULL) return; |
80 switch (type.value) { | 80 switch (type) { |
81 case NotificationType::PREF_CHANGED: { | 81 case chrome::NOTIFICATION_PREF_CHANGED: { |
82 if (Source<PrefService>(source).ptr() == profile_->GetPrefs()) { | 82 if (Source<PrefService>(source).ptr() == profile_->GetPrefs()) { |
83 std::string* pref_name = Details<std::string>(details).ptr(); | 83 std::string* pref_name = Details<std::string>(details).ptr(); |
84 if (*pref_name == prefs::kExtensionInstallForceList) { | 84 if (*pref_name == prefs::kExtensionInstallForceList) { |
85 StartLoading(); | 85 StartLoading(); |
86 } else { | 86 } else { |
87 NOTREACHED() << "Unexpected preference name."; | 87 NOTREACHED() << "Unexpected preference name."; |
88 } | 88 } |
89 } | 89 } |
90 break; | 90 break; |
91 } | 91 } |
92 case NotificationType::PROFILE_DESTROYED: { | 92 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
93 if (Source<Profile>(source).ptr() == profile_) { | 93 if (Source<Profile>(source).ptr() == profile_) { |
94 notification_registrar_.RemoveAll(); | 94 notification_registrar_.RemoveAll(); |
95 pref_change_registrar_.RemoveAll(); | 95 pref_change_registrar_.RemoveAll(); |
96 profile_ = NULL; | 96 profile_ = NULL; |
97 } | 97 } |
98 break; | 98 break; |
99 } | 99 } |
100 default: | 100 default: |
101 NOTREACHED() << "Unexpected notification type."; | 101 NOTREACHED() << "Unexpected notification type."; |
102 } | 102 } |
103 } | 103 } |
OLD | NEW |