OLD | NEW |
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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 class CommandLine; | 44 class CommandLine; |
45 class SequencedTaskRunner; | 45 class SequencedTaskRunner; |
46 class Version; | 46 class Version; |
47 } | 47 } |
48 | 48 |
49 namespace extensions { | 49 namespace extensions { |
50 class BrowserEventRouter; | 50 class BrowserEventRouter; |
51 class ComponentLoader; | 51 class ComponentLoader; |
52 class CrxInstaller; | 52 class CrxInstaller; |
53 class ExtensionActionStorageManager; | 53 class ExtensionActionStorageManager; |
| 54 class ExtensionGarbageCollector; |
54 class ExtensionRegistry; | 55 class ExtensionRegistry; |
55 class ExtensionSystem; | 56 class ExtensionSystem; |
56 class ExtensionToolbarModel; | 57 class ExtensionToolbarModel; |
57 class ExtensionUpdater; | 58 class ExtensionUpdater; |
58 class PendingExtensionManager; | 59 class PendingExtensionManager; |
59 class RendererStartupHelper; | 60 class RendererStartupHelper; |
60 class UpdateObserver; | 61 class UpdateObserver; |
61 } // namespace extensions | 62 } // namespace extensions |
62 | 63 |
63 using extensions::ExtensionIdSet; | 64 using extensions::ExtensionIdSet; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // Remove the specified component extension. | 265 // Remove the specified component extension. |
265 virtual void RemoveComponentExtension(const std::string& extension_id) | 266 virtual void RemoveComponentExtension(const std::string& extension_id) |
266 OVERRIDE; | 267 OVERRIDE; |
267 | 268 |
268 // Unload all extensions. Does not send notifications. | 269 // Unload all extensions. Does not send notifications. |
269 void UnloadAllExtensionsForTest(); | 270 void UnloadAllExtensionsForTest(); |
270 | 271 |
271 // Reloads all extensions. Does not notify that extensions are ready. | 272 // Reloads all extensions. Does not notify that extensions are ready. |
272 void ReloadExtensionsForTest(); | 273 void ReloadExtensionsForTest(); |
273 | 274 |
274 // Scan the extension directory and clean up the cruft. | |
275 void GarbageCollectExtensions(); | |
276 | |
277 // Called when the initial extensions load has completed. | 275 // Called when the initial extensions load has completed. |
278 virtual void OnLoadedInstalledExtensions(); | 276 virtual void OnLoadedInstalledExtensions(); |
279 | 277 |
280 // Adds |extension| to this ExtensionService and notifies observers that the | 278 // Adds |extension| to this ExtensionService and notifies observers that the |
281 // extensions have been loaded. | 279 // extensions have been loaded. |
282 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE; | 280 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE; |
283 | 281 |
284 // Check if we have preferences for the component extension and, if not or if | 282 // Check if we have preferences for the component extension and, if not or if |
285 // the stored version differs, install the extension (without requirements | 283 // the stored version differs, install the extension (without requirements |
286 // checking) before calling AddExtension. | 284 // checking) before calling AddExtension. |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 472 |
475 // Marks alertable extensions as acknowledged, after the user presses the | 473 // Marks alertable extensions as acknowledged, after the user presses the |
476 // accept button. | 474 // accept button. |
477 void HandleExtensionAlertAccept(); | 475 void HandleExtensionAlertAccept(); |
478 | 476 |
479 // content::NotificationObserver | 477 // content::NotificationObserver |
480 virtual void Observe(int type, | 478 virtual void Observe(int type, |
481 const content::NotificationSource& source, | 479 const content::NotificationSource& source, |
482 const content::NotificationDetails& details) OVERRIDE; | 480 const content::NotificationDetails& details) OVERRIDE; |
483 | 481 |
| 482 // Postpone installations so that we don't have to worry about race |
| 483 // conditions. |
| 484 void OnGarbageCollectIsolatedStorageStart(); |
| 485 |
| 486 // Restart any extension installs which were delayed for isolated storage |
| 487 // garbage collection. |
| 488 void OnGarbageCollectIsolatedStorageFinished(); |
| 489 |
484 // Record a histogram using the PermissionMessage enum values for each | 490 // Record a histogram using the PermissionMessage enum values for each |
485 // permission in |e|. | 491 // permission in |e|. |
486 // NOTE: If this is ever called with high frequency, the implementation may | 492 // NOTE: If this is ever called with high frequency, the implementation may |
487 // need to be made more efficient. | 493 // need to be made more efficient. |
488 static void RecordPermissionMessagesHistogram( | 494 static void RecordPermissionMessagesHistogram( |
489 const extensions::Extension* e, const char* histogram); | 495 const extensions::Extension* e, const char* histogram); |
490 | 496 |
491 #if defined(UNIT_TEST) | 497 #if defined(UNIT_TEST) |
492 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) { | 498 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) { |
493 TrackTerminatedExtension(extension); | 499 TrackTerminatedExtension(extension); |
494 } | 500 } |
495 | 501 |
496 void FinishInstallationForTest(const extensions::Extension* extension) { | 502 void FinishInstallationForTest(const extensions::Extension* extension) { |
497 FinishInstallation(extension); | 503 FinishInstallation(extension); |
498 } | 504 } |
499 #endif | 505 #endif |
500 | 506 |
501 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); } | 507 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); } |
502 | 508 |
| 509 extensions::ExtensionGarbageCollector* garbage_collector() { |
| 510 return garbage_collector_.get(); |
| 511 } |
| 512 |
503 bool browser_terminating() const { return browser_terminating_; } | 513 bool browser_terminating() const { return browser_terminating_; } |
504 | 514 |
505 // For testing. | 515 // For testing. |
506 void set_browser_terminating_for_test(bool value) { | 516 void set_browser_terminating_for_test(bool value) { |
507 browser_terminating_ = value; | 517 browser_terminating_ = value; |
508 } | 518 } |
509 | 519 |
510 // By default ExtensionService will wait with installing an updated extension | 520 // By default ExtensionService will wait with installing an updated extension |
511 // until the extension is idle. Tests might not like this behavior, so you can | 521 // until the extension is idle. Tests might not like this behavior, so you can |
512 // disable it with this method. | 522 // disable it with this method. |
513 void set_install_updates_when_idle_for_test(bool value) { | 523 void set_install_updates_when_idle_for_test(bool value) { |
514 install_updates_when_idle_ = value; | 524 install_updates_when_idle_ = value; |
515 } | 525 } |
516 | 526 |
517 // Set a callback to be called when all external providers are ready and their | 527 // Set a callback to be called when all external providers are ready and their |
518 // extensions have been installed. | 528 // extensions have been installed. |
519 void set_external_updates_finished_callback_for_test( | 529 void set_external_updates_finished_callback_for_test( |
520 const base::Closure& callback) { | 530 const base::Closure& callback) { |
521 external_updates_finished_callback_ = callback; | 531 external_updates_finished_callback_ = callback; |
522 } | 532 } |
523 | 533 |
524 // Adds/Removes update observers. | 534 // Adds/Removes update observers. |
525 void AddUpdateObserver(extensions::UpdateObserver* observer); | 535 void AddUpdateObserver(extensions::UpdateObserver* observer); |
526 void RemoveUpdateObserver(extensions::UpdateObserver* observer); | 536 void RemoveUpdateObserver(extensions::UpdateObserver* observer); |
527 | 537 |
528 #if defined(OS_CHROMEOS) | |
529 void disable_garbage_collection() { | |
530 disable_garbage_collection_ = true; | |
531 } | |
532 void enable_garbage_collection() { | |
533 disable_garbage_collection_ = false; | |
534 } | |
535 #endif | |
536 | |
537 private: | 538 private: |
538 // Populates greylist_. | 539 // Populates greylist_. |
539 void LoadGreylistFromPrefs(); | 540 void LoadGreylistFromPrefs(); |
540 | 541 |
541 // Signals *ready_ and sends a notification to the listeners. | 542 // Signals *ready_ and sends a notification to the listeners. |
542 void SetReadyAndNotifyListeners(); | 543 void SetReadyAndNotifyListeners(); |
543 | 544 |
544 // Return true if the sync type of |extension| matches |type|. | 545 // Return true if the sync type of |extension| matches |type|. |
545 void OnExtensionInstallPrefChanged(); | 546 void OnExtensionInstallPrefChanged(); |
546 | 547 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 | 589 |
589 // Helper to determine whether we should initially enable an installed | 590 // Helper to determine whether we should initially enable an installed |
590 // (or upgraded) extension. | 591 // (or upgraded) extension. |
591 bool ShouldEnableOnInstall(const extensions::Extension* extension); | 592 bool ShouldEnableOnInstall(const extensions::Extension* extension); |
592 | 593 |
593 // Helper to determine if updating an extensions should proceed immediately, | 594 // Helper to determine if updating an extensions should proceed immediately, |
594 // or if we should delay the update until further notice. | 595 // or if we should delay the update until further notice. |
595 bool ShouldDelayExtensionUpdate(const std::string& extension_id, | 596 bool ShouldDelayExtensionUpdate(const std::string& extension_id, |
596 bool wait_for_idle) const; | 597 bool wait_for_idle) const; |
597 | 598 |
598 // Helper to search storage directories for extensions with isolated storage | |
599 // that have been orphaned by an uninstall. | |
600 void GarbageCollectIsolatedStorage(); | |
601 void OnGarbageCollectIsolatedStorageFinished(); | |
602 | |
603 // extensions::Blacklist::Observer implementation. | 599 // extensions::Blacklist::Observer implementation. |
604 virtual void OnBlacklistUpdated() OVERRIDE; | 600 virtual void OnBlacklistUpdated() OVERRIDE; |
605 | 601 |
606 // Manages the blacklisted extensions, intended as callback from | 602 // Manages the blacklisted extensions, intended as callback from |
607 // Blacklist::GetBlacklistedIDs. | 603 // Blacklist::GetBlacklistedIDs. |
608 void ManageBlacklist( | 604 void ManageBlacklist( |
609 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids); | 605 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids); |
610 | 606 |
611 // Add extensions in |blocked| to blacklisted_extensions, remove extensions | 607 // Add extensions in |blocked| to blacklisted_extensions, remove extensions |
612 // that are neither in |blocked|, nor in |unchanged|. | 608 // that are neither in |blocked|, nor in |unchanged|. |
613 void UpdateBlockedExtensions(const ExtensionIdSet& blocked, | 609 void UpdateBlockedExtensions(const ExtensionIdSet& blocked, |
614 const ExtensionIdSet& unchanged); | 610 const ExtensionIdSet& unchanged); |
615 | 611 |
616 void UpdateGreylistedExtensions( | 612 void UpdateGreylistedExtensions( |
617 const ExtensionIdSet& greylist, | 613 const ExtensionIdSet& greylist, |
618 const ExtensionIdSet& unchanged, | 614 const ExtensionIdSet& unchanged, |
619 const extensions::Blacklist::BlacklistStateMap& state_map); | 615 const extensions::Blacklist::BlacklistStateMap& state_map); |
620 | 616 |
621 // Controls if installs are delayed. See comment for | |
622 // |installs_delayed_for_gc_|. | |
623 void set_installs_delayed_for_gc(bool value) { | |
624 installs_delayed_for_gc_ = value; | |
625 } | |
626 bool installs_delayed_for_gc() const { return installs_delayed_for_gc_; } | |
627 | |
628 // Used only by test code. | 617 // Used only by test code. |
629 void UnloadAllExtensionsInternal(); | 618 void UnloadAllExtensionsInternal(); |
630 | 619 |
631 // The normal profile associated with this ExtensionService. | 620 // The normal profile associated with this ExtensionService. |
632 Profile* profile_; | 621 Profile* profile_; |
633 | 622 |
634 // The ExtensionSystem for the profile above. | 623 // The ExtensionSystem for the profile above. |
635 extensions::ExtensionSystem* system_; | 624 extensions::ExtensionSystem* system_; |
636 | 625 |
637 // Preferences for the owning profile. | 626 // Preferences for the owning profile. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 // Sequenced task runner for extension related file operations. | 736 // Sequenced task runner for extension related file operations. |
748 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 737 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
749 | 738 |
750 #if defined(ENABLE_EXTENSIONS) | 739 #if defined(ENABLE_EXTENSIONS) |
751 scoped_ptr<extensions::ExtensionActionStorageManager> | 740 scoped_ptr<extensions::ExtensionActionStorageManager> |
752 extension_action_storage_manager_; | 741 extension_action_storage_manager_; |
753 #endif | 742 #endif |
754 scoped_ptr<extensions::ManagementPolicy::Provider> | 743 scoped_ptr<extensions::ManagementPolicy::Provider> |
755 shared_module_policy_provider_; | 744 shared_module_policy_provider_; |
756 | 745 |
| 746 // The ExtensionGarbageCollector to clean up all the garbage that leaks into |
| 747 // the extensions directory. |
| 748 scoped_ptr<extensions::ExtensionGarbageCollector> garbage_collector_; |
| 749 |
757 ObserverList<extensions::UpdateObserver, true> update_observers_; | 750 ObserverList<extensions::UpdateObserver, true> update_observers_; |
758 | 751 |
759 #if defined(OS_CHROMEOS) | |
760 // TODO(rkc): HACK alert - this is only in place to allow the | |
761 // kiosk_mode_screensaver to prevent its extension from getting garbage | |
762 // collected. Remove this once KioskModeScreensaver is removed. | |
763 // See crbug.com/280363 | |
764 bool disable_garbage_collection_; | |
765 #endif | |
766 | |
767 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 752 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
768 InstallAppsWithUnlimtedStorage); | 753 InstallAppsWithUnlimtedStorage); |
769 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 754 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
770 InstallAppsAndCheckStorageProtection); | 755 InstallAppsAndCheckStorageProtection); |
771 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs); | 756 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs); |
772 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 757 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
773 BlacklistedExtensionWillNotInstall); | 758 BlacklistedExtensionWillNotInstall); |
774 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 759 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
775 UnloadBlacklistedExtensionPolicy); | 760 UnloadBlacklistedExtensionPolicy); |
776 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 761 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
777 WillNotLoadBlacklistedExtensionsFromDirectory); | 762 WillNotLoadBlacklistedExtensionsFromDirectory); |
778 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 763 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
779 BlacklistedInPrefsFromStartup); | 764 BlacklistedInPrefsFromStartup); |
780 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 765 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
781 GreylistedExtensionDisabled); | 766 GreylistedExtensionDisabled); |
782 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 767 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
783 GreylistDontEnableManuallyDisabled); | 768 GreylistDontEnableManuallyDisabled); |
784 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 769 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
785 GreylistUnknownDontChange); | 770 GreylistUnknownDontChange); |
786 DISALLOW_COPY_AND_ASSIGN(ExtensionService); | 771 DISALLOW_COPY_AND_ASSIGN(ExtensionService); |
787 }; | 772 }; |
788 | 773 |
789 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 774 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
OLD | NEW |