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

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

Issue 5742008: Clean up threading model of external extension providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix breakage 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
1 // Copyright (c) 2010 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/stateful_external_extension_provider.h" 5 #include "chrome/browser/extensions/external_extension_provider_impl.h"
6 6
7 #include "app/app_paths.h" 7 #include "app/app_paths.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/linked_ptr.h"
10 #include "base/path_service.h" 11 #include "base/path_service.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "base/version.h" 13 #include "base/version.h"
13 #include "chrome/browser/browser_thread.h" 14 #include "chrome/browser/browser_thread.h"
15 #include "chrome/browser/extensions/external_extension_provider_interface.h"
16 #include "chrome/browser/extensions/external_policy_extension_loader.h"
17 #include "chrome/browser/extensions/external_pref_extension_loader.h"
18 #include "chrome/browser/profiles/profile.h"
14 19
15 namespace { 20 #if defined(OS_WIN)
21 #include "chrome/browser/extensions/external_registry_extension_loader_win.h"
22 #endif
16 23
17 // Constants for keeping track of extension preferences. 24 // Constants for keeping track of extension preferences in a dictionary.
18 const char kLocation[] = "location"; 25 const char ExternalExtensionProviderImpl::kLocation[] = "location";
19 const char kState[] = "state"; 26 const char ExternalExtensionProviderImpl::kState[] = "state";
20 const char kExternalCrx[] = "external_crx"; 27 const char ExternalExtensionProviderImpl::kExternalCrx[] = "external_crx";
21 const char kExternalVersion[] = "external_version"; 28 const char ExternalExtensionProviderImpl::kExternalVersion[] =
22 const char kExternalUpdateUrl[] = "external_update_url"; 29 "external_version";
30 const char ExternalExtensionProviderImpl::kExternalUpdateUrl[] =
31 "external_update_url";
23 32
24 } 33 ExternalExtensionProviderImpl::ExternalExtensionProviderImpl(
25 34 VisitorInterface* service,
26 StatefulExternalExtensionProvider::StatefulExternalExtensionProvider( 35 ExternalExtensionLoader* loader,
27 Extension::Location crx_location, 36 Extension::Location crx_location,
28 Extension::Location download_location) 37 Extension::Location download_location)
29 : crx_location_(crx_location), 38 : crx_location_(crx_location),
30 download_location_(download_location) { 39 download_location_(download_location),
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 40 service_(service),
41 prefs_(NULL),
42 ready_(false),
43 loader_(loader) {
44 loader_->Init(this);
32 } 45 }
33 46
34 StatefulExternalExtensionProvider::~StatefulExternalExtensionProvider() { 47 ExternalExtensionProviderImpl::~ExternalExtensionProviderImpl() {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49 loader_->OwnerShutdown();
36 } 50 }
37 51
38 void StatefulExternalExtensionProvider::VisitRegisteredExtension( 52 void ExternalExtensionProviderImpl::VisitRegisteredExtension() const {
39 Visitor* visitor) const { 53 loader_->StartLoading();
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 54 }
41 DCHECK(prefs_.get()); 55
56 void ExternalExtensionProviderImpl::SetPrefs(DictionaryValue* prefs) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
58
59 // Check if the service is still alive. It is possible that it had went
60 // away while |loader_| was working on the FILE thread.
61 if (!service_) return;
62
63 prefs_.reset(prefs);
64 ready_ = true; // Queries for extensions are allowed from this point.
65
66 // Notify ExtensionService about all the extensions this provider has.
42 for (DictionaryValue::key_iterator i = prefs_->begin_keys(); 67 for (DictionaryValue::key_iterator i = prefs_->begin_keys();
43 i != prefs_->end_keys(); ++i) { 68 i != prefs_->end_keys(); ++i) {
44 const std::string& extension_id = *i; 69 const std::string& extension_id = *i;
45 DictionaryValue* extension; 70 DictionaryValue* extension;
46 if (!prefs_->GetDictionaryWithoutPathExpansion(extension_id, &extension)) 71 if (!prefs_->GetDictionaryWithoutPathExpansion(extension_id, &extension))
47 continue; 72 continue;
48 73
49 FilePath::StringType external_crx; 74 FilePath::StringType external_crx;
50 std::string external_version; 75 std::string external_version;
51 std::string external_update_url; 76 std::string external_update_url;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 118 }
94 119
95 scoped_ptr<Version> version; 120 scoped_ptr<Version> version;
96 version.reset(Version::GetVersionFromString(external_version)); 121 version.reset(Version::GetVersionFromString(external_version));
97 if (!version.get()) { 122 if (!version.get()) {
98 LOG(WARNING) << "Malformed extension dictionary for extension: " 123 LOG(WARNING) << "Malformed extension dictionary for extension: "
99 << extension_id.c_str() << ". Invalid version string \"" 124 << extension_id.c_str() << ". Invalid version string \""
100 << external_version << "\"."; 125 << external_version << "\".";
101 continue; 126 continue;
102 } 127 }
103 visitor->OnExternalExtensionFileFound(extension_id, version.get(), path, 128 service_->OnExternalExtensionFileFound(extension_id, version.get(), path,
104 crx_location_); 129 crx_location_);
105 } else { // if (has_external_update_url) 130 } else { // if (has_external_update_url)
106 DCHECK(has_external_update_url); // Checking of keys above ensures this. 131 DCHECK(has_external_update_url); // Checking of keys above ensures this.
107 if (download_location_ == Extension::INVALID) { 132 if (download_location_ == Extension::INVALID) {
108 LOG(WARNING) << "This provider does not support installing external " 133 LOG(WARNING) << "This provider does not support installing external "
109 << "extensions from update URLs."; 134 << "extensions from update URLs.";
110 continue; 135 continue;
111 } 136 }
112 GURL update_url(external_update_url); 137 GURL update_url(external_update_url);
113 if (!update_url.is_valid()) { 138 if (!update_url.is_valid()) {
114 LOG(WARNING) << "Malformed extension dictionary for extension: " 139 LOG(WARNING) << "Malformed extension dictionary for extension: "
115 << extension_id.c_str() << ". " << kExternalUpdateUrl 140 << extension_id.c_str() << ". " << kExternalUpdateUrl
116 << " must be a valid URL. Saw \"" << external_update_url 141 << " must be a valid URL. Saw \"" << external_update_url
117 << "\"."; 142 << "\".";
118 continue; 143 continue;
119 } 144 }
120 visitor->OnExternalExtensionUpdateUrlFound( 145 service_->OnExternalExtensionUpdateUrlFound(
121 extension_id, update_url, download_location_); 146 extension_id, update_url, download_location_);
122 } 147 }
123 } 148 }
149
150 service_->OnExternalProviderReady();
124 } 151 }
125 152
126 bool StatefulExternalExtensionProvider::HasExtension( 153 void ExternalExtensionProviderImpl::ServiceShutdown() {
154 service_ = NULL;
155 }
156
157 bool ExternalExtensionProviderImpl::IsReady() {
158 return ready_;
159 }
160
161 bool ExternalExtensionProviderImpl::HasExtension(
127 const std::string& id) const { 162 const std::string& id) const {
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
129 DCHECK(prefs_.get()); 164 DCHECK(prefs_.get());
165 DCHECK(ready_);
130 return prefs_->HasKey(id); 166 return prefs_->HasKey(id);
131 } 167 }
132 168
133 bool StatefulExternalExtensionProvider::GetExtensionDetails( 169 bool ExternalExtensionProviderImpl::GetExtensionDetails(
134 const std::string& id, Extension::Location* location, 170 const std::string& id, Extension::Location* location,
135 scoped_ptr<Version>* version) const { 171 scoped_ptr<Version>* version) const {
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
137 DCHECK(prefs_.get()); 173 DCHECK(prefs_.get());
174 DCHECK(ready_);
138 DictionaryValue* extension = NULL; 175 DictionaryValue* extension = NULL;
139 if (!prefs_->GetDictionary(id, &extension)) 176 if (!prefs_->GetDictionary(id, &extension))
140 return false; 177 return false;
141 178
142 Extension::Location loc = Extension::INVALID; 179 Extension::Location loc = Extension::INVALID;
143 if (extension->HasKey(kExternalUpdateUrl)) { 180 if (extension->HasKey(kExternalUpdateUrl)) {
144 loc = download_location_; 181 loc = download_location_;
145 182
146 } else if (extension->HasKey(kExternalCrx)) { 183 } else if (extension->HasKey(kExternalCrx)) {
147 loc = crx_location_; 184 loc = crx_location_;
148 185
149 std::string external_version; 186 std::string external_version;
150 if (!extension->GetString(kExternalVersion, &external_version)) 187 if (!extension->GetString(kExternalVersion, &external_version))
151 return false; 188 return false;
152 189
153 if (version) 190 if (version)
154 version->reset(Version::GetVersionFromString(external_version)); 191 version->reset(Version::GetVersionFromString(external_version));
155 192
156 } else { 193 } else {
157 NOTREACHED(); // Chrome should not allow prefs to get into this state. 194 NOTREACHED(); // Chrome should not allow prefs to get into this state.
158 return false; 195 return false;
159 } 196 }
160 197
161 if (location) 198 if (location)
162 *location = loc; 199 *location = loc;
163 200
164 return true; 201 return true;
165 } 202 }
166 203
167 void StatefulExternalExtensionProvider::set_prefs(DictionaryValue* prefs) { 204 // static
168 prefs_.reset(prefs); 205 void ExternalExtensionProviderImpl::CreateExternalProviders(
206 VisitorInterface* service,
207 Profile* profile,
208 ProviderCollection* provider_list) {
209 provider_list->push_back(
210 linked_ptr<ExternalExtensionProviderInterface>(
211 new ExternalExtensionProviderImpl(
212 service,
213 new ExternalPrefExtensionLoader,
214 Extension::EXTERNAL_PREF,
215 Extension::EXTERNAL_PREF_DOWNLOAD)));
216 #if defined(OS_WIN)
217 provider_list->push_back(
218 linked_ptr<ExternalExtensionProviderInterface>(
219 new ExternalExtensionProviderImpl(
220 service,
221 new ExternalRegistryExtensionLoader,
222 Extension::EXTERNAL_REGISTRY,
223 Extension::INVALID)));
224 #endif
225 provider_list->push_back(
226 linked_ptr<ExternalExtensionProviderInterface>(
227 new ExternalExtensionProviderImpl(
228 service,
229 new ExternalPolicyExtensionLoader(profile),
230 Extension::INVALID,
231 Extension::EXTERNAL_POLICY_DOWNLOAD)));
169 } 232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698