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

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

Issue 1495403002: Observe adding external extensions via windows registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add missing files Created 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_provider_impl.h" 5 #include "chrome/browser/extensions/external_provider_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) { 113 void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) {
114 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 114 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
115 115
116 // Check if the service is still alive. It is possible that it went 116 // Check if the service is still alive. It is possible that it went
117 // away while |loader_| was working on the FILE thread. 117 // away while |loader_| was working on the FILE thread.
118 if (!service_) return; 118 if (!service_) return;
119 119
120 prefs_.reset(prefs); 120 prefs_.reset(prefs);
121 ready_ = true; // Queries for extensions are allowed from this point. 121 ready_ = true; // Queries for extensions are allowed from this point.
122 122
123 ScopedVector<ExternalExtensionInstallInfoUpdateUrl>
124 external_update_url_extensions;
125 ScopedVector<ExternalExtensionInstallInfoFile> external_file_extensions;
126
127 RetrieveExtensionsFromPrefs(&external_update_url_extensions,
128 &external_file_extensions);
129 for (const auto& extension : external_update_url_extensions)
130 service_->OnExternalExtensionUpdateUrlFound(extension, true);
131
132 for (const auto& extension : external_file_extensions)
133 service_->OnExternalExtensionFileFound(extension);
134
135 service_->OnExternalProviderReady(this);
136 }
137
138 void ExternalProviderImpl::UpdatePrefs(base::DictionaryValue* prefs) {
139 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
140 // We only expect updates from windows registry.
141 CHECK(crx_location_ == Manifest::EXTERNAL_REGISTRY);
142
143 // Check if the service is still alive. It is possible that it went
144 // away while |loader_| was working on the FILE thread.
145 if (!service_)
146 return;
147
148 std::set<std::string> removed_extensions;
149 // Find extensions that were removed by this ExternalProvider.
150 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) {
151 const std::string& extension_id = i.key();
152 // Don't bother about invalid ids.
153 if (!crx_file::id_util::IdIsValid(extension_id))
154 continue;
155 if (!prefs->HasKey(extension_id))
156 removed_extensions.insert(extension_id);
157 }
158
159 prefs_.reset(prefs);
160
161 ScopedVector<ExternalExtensionInstallInfoUpdateUrl>
162 external_update_url_extensions;
163 ScopedVector<ExternalExtensionInstallInfoFile> external_file_extensions;
164 RetrieveExtensionsFromPrefs(&external_update_url_extensions,
165 &external_file_extensions);
166
167 // Notify ExtensionService about completion of finding incremental updates
168 // from this provider.
169 // Provide the list of added and removed extensions.
170 service_->OnExternalProviderUpdateComplete(
171 this, external_update_url_extensions, external_file_extensions,
172 removed_extensions);
173 }
174
175 void ExternalProviderImpl::RetrieveExtensionsFromPrefs(
176 ScopedVector<ExternalExtensionInstallInfoUpdateUrl>*
177 external_update_url_extensions,
178 ScopedVector<ExternalExtensionInstallInfoFile>* external_file_extensions) {
123 // Set of unsupported extensions that need to be deleted from prefs_. 179 // Set of unsupported extensions that need to be deleted from prefs_.
124 std::set<std::string> unsupported_extensions; 180 std::set<std::string> unsupported_extensions;
125 181
126 // Notify ExtensionService about all the extensions this provider has. 182 // Discover all the extensions this provider has.
127 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { 183 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) {
128 const std::string& extension_id = i.key(); 184 const std::string& extension_id = i.key();
129 const base::DictionaryValue* extension = NULL; 185 const base::DictionaryValue* extension = NULL;
130 186
131 if (!crx_file::id_util::IdIsValid(extension_id)) { 187 if (!crx_file::id_util::IdIsValid(extension_id)) {
132 LOG(WARNING) << "Malformed extension dictionary: key " 188 LOG(WARNING) << "Malformed extension dictionary: key "
133 << extension_id.c_str() << " is not a valid id."; 189 << extension_id.c_str() << " is not a valid id.";
134 continue; 190 continue;
135 } 191 }
136 192
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 if (!path.IsAbsolute()) { 338 if (!path.IsAbsolute()) {
283 base::FilePath base_path = loader_->GetBaseCrxFilePath(); 339 base::FilePath base_path = loader_->GetBaseCrxFilePath();
284 if (base_path.empty()) { 340 if (base_path.empty()) {
285 LOG(WARNING) << "File path " << external_crx.c_str() 341 LOG(WARNING) << "File path " << external_crx.c_str()
286 << " is relative. An absolute path is required."; 342 << " is relative. An absolute path is required.";
287 continue; 343 continue;
288 } 344 }
289 path = base_path.Append(external_crx); 345 path = base_path.Append(external_crx);
290 } 346 }
291 347
292 Version version(external_version); 348 scoped_ptr<Version> version(new Version(external_version));
293 if (!version.IsValid()) { 349 if (!version->IsValid()) {
294 LOG(WARNING) << "Malformed extension dictionary for extension: " 350 LOG(WARNING) << "Malformed extension dictionary for extension: "
295 << extension_id.c_str() << ". Invalid version string \"" 351 << extension_id.c_str() << ". Invalid version string \""
296 << external_version << "\"."; 352 << external_version << "\".";
297 continue; 353 continue;
298 } 354 }
299 service_->OnExternalExtensionFileFound(extension_id, &version, path, 355 external_file_extensions->push_back(new ExternalExtensionInstallInfoFile(
300 crx_location_, creation_flags, 356 extension_id, std::move(version), path, crx_location_, creation_flags,
301 auto_acknowledge_, 357 auto_acknowledge_, install_immediately_));
302 install_immediately_);
303 } else { // if (has_external_update_url) 358 } else { // if (has_external_update_url)
304 CHECK(has_external_update_url); // Checking of keys above ensures this. 359 CHECK(has_external_update_url); // Checking of keys above ensures this.
305 if (download_location_ == Manifest::INVALID_LOCATION) { 360 if (download_location_ == Manifest::INVALID_LOCATION) {
306 LOG(WARNING) << "This provider does not support installing external " 361 LOG(WARNING) << "This provider does not support installing external "
307 << "extensions from update URLs."; 362 << "extensions from update URLs.";
308 continue; 363 continue;
309 } 364 }
310 GURL update_url(external_update_url); 365 scoped_ptr<GURL> update_url(new GURL(external_update_url));
311 if (!update_url.is_valid()) { 366 if (!update_url->is_valid()) {
312 LOG(WARNING) << "Malformed extension dictionary for extension: " 367 LOG(WARNING) << "Malformed extension dictionary for extension: "
313 << extension_id.c_str() << ". Key " << kExternalUpdateUrl 368 << extension_id.c_str() << ". Key " << kExternalUpdateUrl
314 << " has value \"" << external_update_url 369 << " has value \"" << external_update_url
315 << "\", which is not a valid URL."; 370 << "\", which is not a valid URL.";
316 continue; 371 continue;
317 } 372 }
318 service_->OnExternalExtensionUpdateUrlFound(extension_id, 373 external_update_url_extensions->push_back(
319 install_parameter, 374 new ExternalExtensionInstallInfoUpdateUrl(
320 update_url, 375 extension_id, install_parameter, std::move(update_url),
321 download_location_, 376 download_location_, creation_flags, auto_acknowledge_));
322 creation_flags,
323 auto_acknowledge_);
324 } 377 }
325 } 378 }
326 379
327 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); 380 for (std::set<std::string>::iterator it = unsupported_extensions.begin();
328 it != unsupported_extensions.end(); ++it) { 381 it != unsupported_extensions.end(); ++it) {
329 // Remove extension for the list of know external extensions. The extension 382 // Remove extension for the list of know external extensions. The extension
330 // will be uninstalled later because provider doesn't provide it anymore. 383 // will be uninstalled later because provider doesn't provide it anymore.
331 prefs_->Remove(*it, NULL); 384 prefs_->Remove(*it, NULL);
332 } 385 }
333
334 service_->OnExternalProviderReady(this);
335 } 386 }
336 387
337 void ExternalProviderImpl::ServiceShutdown() { 388 void ExternalProviderImpl::ServiceShutdown() {
338 service_ = NULL; 389 service_ = NULL;
339 } 390 }
340 391
341 bool ExternalProviderImpl::IsReady() const { 392 bool ExternalProviderImpl::IsReady() const {
342 return ready_; 393 return ready_;
343 } 394 }
344 395
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 new ExternalProviderImpl( 742 new ExternalProviderImpl(
692 service, 743 service,
693 new ExternalComponentLoader(profile), 744 new ExternalComponentLoader(profile),
694 profile, 745 profile,
695 Manifest::INVALID_LOCATION, 746 Manifest::INVALID_LOCATION,
696 Manifest::EXTERNAL_COMPONENT, 747 Manifest::EXTERNAL_COMPONENT,
697 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT))); 748 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT)));
698 } 749 }
699 750
700 } // namespace extensions 751 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698