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

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

Issue 174036: Get rid of the extension's "Current Version" file. (Closed)
Patch Set: merge conflicts Created 11 years, 4 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extensions_service.h" 5 #include "chrome/browser/extensions/extensions_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/crx_installer.h" 11 #include "chrome/browser/extensions/crx_installer.h"
12 #include "chrome/browser/extensions/extension_browser_event_router.h" 12 #include "chrome/browser/extensions/extension_browser_event_router.h"
13 #include "chrome/browser/extensions/extension_file_util.h" 13 #include "chrome/browser/extensions/extension_file_util.h"
14 #include "chrome/browser/extensions/extension_updater.h" 14 #include "chrome/browser/extensions/extension_updater.h"
15 #include "chrome/browser/extensions/external_extension_provider.h" 15 #include "chrome/browser/extensions/external_extension_provider.h"
16 #include "chrome/browser/extensions/external_pref_extension_provider.h" 16 #include "chrome/browser/extensions/external_pref_extension_provider.h"
17 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_error_reporter.h" 20 #include "chrome/common/extensions/extension_error_reporter.h"
21 #include "chrome/common/notification_service.h" 21 #include "chrome/common/notification_service.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/pref_service.h" 23 #include "chrome/common/pref_service.h"
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 25
26 #if defined(OS_WIN) 26 #if defined(OS_WIN)
27 #include "chrome/browser/extensions/external_registry_extension_provider_win.h" 27 #include "chrome/browser/extensions/external_registry_extension_provider_win.h"
28 #endif 28 #endif
29 29
30 namespace {
31
32 // Helper class to collect the IDs of every extension listed in the prefs.
33 class InstalledExtensionSet {
34 public:
35 InstalledExtensionSet(InstalledExtensions* installed) {
36 scoped_ptr<InstalledExtensions> cleanup(installed);
37 installed->VisitInstalledExtensions(
38 NewCallback(this, &InstalledExtensionSet::ExtensionVisited));
39 }
40
41 const std::set<std::string>& extensions() { return extensions_; }
42
43 private:
44 void ExtensionVisited(
45 DictionaryValue* manifest, const std::string& id,
46 const FilePath& path, Extension::Location location) {
47 extensions_.insert(id);
48 }
49
50 std::set<std::string> extensions_;
51 };
52
53 } // namespace
54
30 // ExtensionsService. 55 // ExtensionsService.
31 56
32 const char* ExtensionsService::kInstallDirectoryName = "Extensions"; 57 const char* ExtensionsService::kInstallDirectoryName = "Extensions";
33 const char* ExtensionsService::kCurrentVersionFileName = "Current Version"; 58 const char* ExtensionsService::kCurrentVersionFileName = "Current Version";
34 59
35 const char* ExtensionsService::kGalleryDownloadURLPrefix = 60 const char* ExtensionsService::kGalleryDownloadURLPrefix =
36 "https://dl-ssl.google.com/chrome/"; 61 "https://dl-ssl.google.com/chrome/";
37 const char* ExtensionsService::kGalleryURLPrefix = 62 const char* ExtensionsService::kGalleryURLPrefix =
38 "https://tools.google.com/chrome/"; 63 "https://tools.google.com/chrome/";
39 64
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // EXTENSION_UNLOADED since that implies that the extension has been disabled 300 // EXTENSION_UNLOADED since that implies that the extension has been disabled
276 // or uninstalled, and UnloadAll is just part of shutdown. 301 // or uninstalled, and UnloadAll is just part of shutdown.
277 } 302 }
278 303
279 void ExtensionsService::ReloadExtensions() { 304 void ExtensionsService::ReloadExtensions() {
280 UnloadAllExtensions(); 305 UnloadAllExtensions();
281 LoadAllExtensions(); 306 LoadAllExtensions();
282 } 307 }
283 308
284 void ExtensionsService::GarbageCollectExtensions() { 309 void ExtensionsService::GarbageCollectExtensions() {
310 InstalledExtensionSet installed(
311 new InstalledExtensions(extension_prefs_.get()));
285 backend_loop_->PostTask(FROM_HERE, NewRunnableFunction( 312 backend_loop_->PostTask(FROM_HERE, NewRunnableFunction(
286 &extension_file_util::GarbageCollectExtensions, install_directory_)); 313 &extension_file_util::GarbageCollectExtensions, install_directory_,
314 installed.extensions()));
287 } 315 }
288 316
289 void ExtensionsService::OnLoadedInstalledExtensions() { 317 void ExtensionsService::OnLoadedInstalledExtensions() {
290 ready_ = true; 318 ready_ = true;
291 if (updater_.get()) { 319 if (updater_.get()) {
292 updater_->Start(); 320 updater_->Start();
293 } 321 }
294 NotificationService::current()->Notify( 322 NotificationService::current()->Notify(
295 NotificationType::EXTENSIONS_READY, 323 NotificationType::EXTENSIONS_READY,
296 Source<ExtensionsService>(this), 324 Source<ExtensionsService>(this),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 367 }
340 } else { 368 } else {
341 // We already have the extension of the same or older version. 369 // We already have the extension of the same or older version.
342 LOG(WARNING) << "Duplicate extension load attempt: " << (*iter)->id(); 370 LOG(WARNING) << "Duplicate extension load attempt: " << (*iter)->id();
343 continue; 371 continue;
344 } 372 }
345 } 373 }
346 374
347 switch (extension_prefs_->GetExtensionState(extension->id())) { 375 switch (extension_prefs_->GetExtensionState(extension->id())) {
348 case Extension::ENABLED: 376 case Extension::ENABLED:
377 if (extension->location() != Extension::LOAD)
378 extension_prefs_->MigrateToPrefs(extension.get());
349 enabled_extensions.push_back(extension.get()); 379 enabled_extensions.push_back(extension.get());
350 extensions_.push_back(extension.release()); 380 extensions_.push_back(extension.release());
351 break; 381 break;
352 case Extension::DISABLED: 382 case Extension::DISABLED:
353 disabled_extensions.push_back(extension.get()); 383 disabled_extensions.push_back(extension.get());
354 disabled_extensions_.push_back(extension.release()); 384 disabled_extensions_.push_back(extension.release());
355 break; 385 break;
356 default: 386 default:
357 break; 387 break;
358 } 388 }
(...skipping 11 matching lines...) Expand all
370 NotificationService::current()->Notify( 400 NotificationService::current()->Notify(
371 NotificationType::THEME_INSTALLED, 401 NotificationType::THEME_INSTALLED,
372 Source<ExtensionsService>(this), 402 Source<ExtensionsService>(this),
373 Details<Extension>(*iter)); 403 Details<Extension>(*iter));
374 } 404 }
375 } 405 }
376 } 406 }
377 } 407 }
378 408
379 void ExtensionsService::OnExtensionInstalled(Extension* extension) { 409 void ExtensionsService::OnExtensionInstalled(Extension* extension) {
380 // Make sure we don't enable a disabled extension. 410 extension_prefs_->OnExtensionInstalled(extension);
381 if (extension_prefs_->GetExtensionState(extension->id()) !=
382 Extension::DISABLED) {
383 extension_prefs_->OnExtensionInstalled(extension);
384 }
385 411
386 // If the extension is a theme, tell the profile (and therefore ThemeProvider) 412 // If the extension is a theme, tell the profile (and therefore ThemeProvider)
387 // to apply it. 413 // to apply it.
388 if (extension->IsTheme()) { 414 if (extension->IsTheme()) {
389 NotificationService::current()->Notify( 415 NotificationService::current()->Notify(
390 NotificationType::THEME_INSTALLED, 416 NotificationType::THEME_INSTALLED,
391 Source<ExtensionsService>(this), 417 Source<ExtensionsService>(this),
392 Details<Extension>(extension)); 418 Details<Extension>(extension));
393 } else { 419 } else {
394 NotificationService::current()->Notify( 420 NotificationService::current()->Notify(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } 534 }
509 535
510 void ExtensionsServiceBackend::LoadInstalledExtensions( 536 void ExtensionsServiceBackend::LoadInstalledExtensions(
511 scoped_refptr<ExtensionsService> frontend, 537 scoped_refptr<ExtensionsService> frontend,
512 InstalledExtensions* installed) { 538 InstalledExtensions* installed) {
513 scoped_ptr<InstalledExtensions> cleanup(installed); 539 scoped_ptr<InstalledExtensions> cleanup(installed);
514 frontend_ = frontend; 540 frontend_ = frontend;
515 alert_on_error_ = false; 541 alert_on_error_ = false;
516 542
517 // Call LoadInstalledExtension for each extension |installed| knows about. 543 // Call LoadInstalledExtension for each extension |installed| knows about.
518 scoped_ptr<InstalledExtensions::Callback> callback( 544 installed->VisitInstalledExtensions(
519 NewCallback(this, &ExtensionsServiceBackend::LoadInstalledExtension)); 545 NewCallback(this, &ExtensionsServiceBackend::LoadInstalledExtension));
520 installed->VisitInstalledExtensions(callback.get());
521 546
522 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod( 547 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(
523 frontend_, &ExtensionsService::OnLoadedInstalledExtensions)); 548 frontend_, &ExtensionsService::OnLoadedInstalledExtensions));
524 } 549 }
525 550
526 void ExtensionsServiceBackend::LoadSingleExtension( 551 void ExtensionsServiceBackend::LoadSingleExtension(
527 const FilePath& path_in, scoped_refptr<ExtensionsService> frontend) { 552 const FilePath& path_in, scoped_refptr<ExtensionsService> frontend) {
528 frontend_ = frontend; 553 frontend_ = frontend;
529 554
530 // Explicit UI loads are always noisy. 555 // Explicit UI loads are always noisy.
(...skipping 16 matching lines...) Expand all
547 return; 572 return;
548 } 573 }
549 574
550 extension->set_location(Extension::LOAD); 575 extension->set_location(Extension::LOAD);
551 ExtensionList* extensions = new ExtensionList; 576 ExtensionList* extensions = new ExtensionList;
552 extensions->push_back(extension); 577 extensions->push_back(extension);
553 ReportExtensionsLoaded(extensions); 578 ReportExtensionsLoaded(extensions);
554 } 579 }
555 580
556 void ExtensionsServiceBackend::LoadInstalledExtension( 581 void ExtensionsServiceBackend::LoadInstalledExtension(
557 const std::string& id, const FilePath& path, Extension::Location location) { 582 DictionaryValue* manifest, const std::string& id,
583 const FilePath& path, Extension::Location location) {
558 if (CheckExternalUninstall(id, location)) { 584 if (CheckExternalUninstall(id, location)) {
559 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod( 585 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(
560 frontend_, 586 frontend_,
561 &ExtensionsService::UninstallExtension, 587 &ExtensionsService::UninstallExtension,
562 id, true)); 588 id, true));
563 589
564 // No error needs to be reported. The extension effectively doesn't exist. 590 // No error needs to be reported. The extension effectively doesn't exist.
565 return; 591 return;
566 } 592 }
567 593
568 std::string error; 594 std::string error;
569 Extension* extension = extension_file_util::LoadExtension( 595 Extension* extension = NULL;
570 path, 596 if (manifest) {
571 true, // Require id 597 scoped_ptr<Extension> tmp(new Extension(path));
572 &error); 598 if (tmp->InitFromValue(*manifest, true, &error) &&
599 extension_file_util::ValidateExtension(tmp.get(), &error)) {
600 extension = tmp.release();
601 }
602 } else {
603 // TODO(mpcomplete): obsolete. remove after migration period.
604 // http://code.google.com/p/chromium/issues/detail?id=19733
605 extension = extension_file_util::LoadExtension(path,
606 true, // Require id
607 &error);
608 }
573 609
574 if (!extension) { 610 if (!extension) {
575 ReportExtensionLoadError(path, error); 611 ReportExtensionLoadError(path, error);
576 return; 612 return;
577 } 613 }
578 614
579 // TODO(erikkay) now we only report a single extension loaded at a time. 615 // TODO(erikkay) now we only report a single extension loaded at a time.
580 // Perhaps we should change the notifications to remove ExtensionList. 616 // Perhaps we should change the notifications to remove ExtensionList.
581 extension->set_location(location); 617 extension->set_location(location);
582 ExtensionList* extensions = new ExtensionList; 618 ExtensionList* extensions = new ExtensionList;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 linked_ptr<ExternalExtensionProvider>(test_provider); 707 linked_ptr<ExternalExtensionProvider>(test_provider);
672 } 708 }
673 709
674 void ExtensionsServiceBackend::OnExternalExtensionFound( 710 void ExtensionsServiceBackend::OnExternalExtensionFound(
675 const std::string& id, const Version* version, const FilePath& path, 711 const std::string& id, const Version* version, const FilePath& path,
676 Extension::Location location) { 712 Extension::Location location) {
677 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(frontend_, 713 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(frontend_,
678 &ExtensionsService::OnExternalExtensionFound, id, version->GetString(), 714 &ExtensionsService::OnExternalExtensionFound, id, version->GetString(),
679 path, location)); 715 path, location));
680 } 716 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.h ('k') | chrome/browser/extensions/extensions_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698