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