| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 class CommandLine; | 45 class CommandLine; |
| 46 class SequencedTaskRunner; | 46 class SequencedTaskRunner; |
| 47 class Version; | 47 class Version; |
| 48 } | 48 } |
| 49 | 49 |
| 50 namespace extensions { | 50 namespace extensions { |
| 51 class BrowserEventRouter; | 51 class BrowserEventRouter; |
| 52 class ComponentLoader; | 52 class ComponentLoader; |
| 53 class CrxInstaller; | 53 class CrxInstaller; |
| 54 class ExtensionActionStorageManager; | 54 class ExtensionActionStorageManager; |
| 55 class ExtensionGarbageCollector; |
| 55 class ExtensionRegistry; | 56 class ExtensionRegistry; |
| 56 class ExtensionSystem; | 57 class ExtensionSystem; |
| 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; |
| 64 | 65 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // Remove the specified component extension. | 288 // Remove the specified component extension. |
| 288 virtual void RemoveComponentExtension(const std::string& extension_id) | 289 virtual void RemoveComponentExtension(const std::string& extension_id) |
| 289 OVERRIDE; | 290 OVERRIDE; |
| 290 | 291 |
| 291 // Unload all extensions. Does not send notifications. | 292 // Unload all extensions. Does not send notifications. |
| 292 void UnloadAllExtensionsForTest(); | 293 void UnloadAllExtensionsForTest(); |
| 293 | 294 |
| 294 // Reloads all extensions. Does not notify that extensions are ready. | 295 // Reloads all extensions. Does not notify that extensions are ready. |
| 295 void ReloadExtensionsForTest(); | 296 void ReloadExtensionsForTest(); |
| 296 | 297 |
| 297 // Scan the extension directory and clean up the cruft. | |
| 298 void GarbageCollectExtensions(); | |
| 299 | |
| 300 // Returns true if |url| should get extension api bindings and be permitted | 298 // Returns true if |url| should get extension api bindings and be permitted |
| 301 // to make api calls. Note that this is independent of what extension | 299 // to make api calls. Note that this is independent of what extension |
| 302 // permissions the given extension has been granted. | 300 // permissions the given extension has been granted. |
| 303 bool ExtensionBindingsAllowed(const GURL& url); | 301 bool ExtensionBindingsAllowed(const GURL& url); |
| 304 | 302 |
| 305 // Called when the initial extensions load has completed. | 303 // Called when the initial extensions load has completed. |
| 306 virtual void OnLoadedInstalledExtensions(); | 304 virtual void OnLoadedInstalledExtensions(); |
| 307 | 305 |
| 308 // Adds |extension| to this ExtensionService and notifies observers that the | 306 // Adds |extension| to this ExtensionService and notifies observers that the |
| 309 // extensions have been loaded. | 307 // extensions have been loaded. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 500 |
| 503 // Marks alertable extensions as acknowledged, after the user presses the | 501 // Marks alertable extensions as acknowledged, after the user presses the |
| 504 // accept button. | 502 // accept button. |
| 505 void HandleExtensionAlertAccept(); | 503 void HandleExtensionAlertAccept(); |
| 506 | 504 |
| 507 // content::NotificationObserver | 505 // content::NotificationObserver |
| 508 virtual void Observe(int type, | 506 virtual void Observe(int type, |
| 509 const content::NotificationSource& source, | 507 const content::NotificationSource& source, |
| 510 const content::NotificationDetails& details) OVERRIDE; | 508 const content::NotificationDetails& details) OVERRIDE; |
| 511 | 509 |
| 510 // Postpone installations so that we don't have to worry about race |
| 511 // conditions. |
| 512 void OnGarbageCollectIsolatedStorageStart(); |
| 513 |
| 514 // Restart any extension installs which were delayed for isolated storage |
| 515 // garbage collection. |
| 516 void OnGarbageCollectIsolatedStorageFinished(); |
| 517 |
| 512 // Record a histogram using the PermissionMessage enum values for each | 518 // Record a histogram using the PermissionMessage enum values for each |
| 513 // permission in |e|. | 519 // permission in |e|. |
| 514 // NOTE: If this is ever called with high frequency, the implementation may | 520 // NOTE: If this is ever called with high frequency, the implementation may |
| 515 // need to be made more efficient. | 521 // need to be made more efficient. |
| 516 static void RecordPermissionMessagesHistogram( | 522 static void RecordPermissionMessagesHistogram( |
| 517 const extensions::Extension* e, const char* histogram); | 523 const extensions::Extension* e, const char* histogram); |
| 518 | 524 |
| 519 #if defined(UNIT_TEST) | 525 #if defined(UNIT_TEST) |
| 520 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) { | 526 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) { |
| 521 TrackTerminatedExtension(extension); | 527 TrackTerminatedExtension(extension); |
| 522 } | 528 } |
| 523 | 529 |
| 524 void FinishInstallationForTest(const extensions::Extension* extension) { | 530 void FinishInstallationForTest(const extensions::Extension* extension) { |
| 525 FinishInstallation(extension); | 531 FinishInstallation(extension); |
| 526 } | 532 } |
| 527 #endif | 533 #endif |
| 528 | 534 |
| 529 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); } | 535 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); } |
| 530 | 536 |
| 537 extensions::ExtensionGarbageCollector* garbage_collector() { |
| 538 return garbage_collector_.get(); |
| 539 } |
| 540 |
| 531 bool browser_terminating() const { return browser_terminating_; } | 541 bool browser_terminating() const { return browser_terminating_; } |
| 532 | 542 |
| 533 // For testing. | 543 // For testing. |
| 534 void set_browser_terminating_for_test(bool value) { | 544 void set_browser_terminating_for_test(bool value) { |
| 535 browser_terminating_ = value; | 545 browser_terminating_ = value; |
| 536 } | 546 } |
| 537 | 547 |
| 538 // By default ExtensionService will wait with installing an updated extension | 548 // By default ExtensionService will wait with installing an updated extension |
| 539 // until the extension is idle. Tests might not like this behavior, so you can | 549 // until the extension is idle. Tests might not like this behavior, so you can |
| 540 // disable it with this method. | 550 // disable it with this method. |
| 541 void set_install_updates_when_idle_for_test(bool value) { | 551 void set_install_updates_when_idle_for_test(bool value) { |
| 542 install_updates_when_idle_ = value; | 552 install_updates_when_idle_ = value; |
| 543 } | 553 } |
| 544 | 554 |
| 545 // Set a callback to be called when all external providers are ready and their | 555 // Set a callback to be called when all external providers are ready and their |
| 546 // extensions have been installed. | 556 // extensions have been installed. |
| 547 void set_external_updates_finished_callback_for_test( | 557 void set_external_updates_finished_callback_for_test( |
| 548 const base::Closure& callback) { | 558 const base::Closure& callback) { |
| 549 external_updates_finished_callback_ = callback; | 559 external_updates_finished_callback_ = callback; |
| 550 } | 560 } |
| 551 | 561 |
| 552 // Adds/Removes update observers. | 562 // Adds/Removes update observers. |
| 553 void AddUpdateObserver(extensions::UpdateObserver* observer); | 563 void AddUpdateObserver(extensions::UpdateObserver* observer); |
| 554 void RemoveUpdateObserver(extensions::UpdateObserver* observer); | 564 void RemoveUpdateObserver(extensions::UpdateObserver* observer); |
| 555 | 565 |
| 556 #if defined(OS_CHROMEOS) | |
| 557 void disable_garbage_collection() { | |
| 558 disable_garbage_collection_ = true; | |
| 559 } | |
| 560 void enable_garbage_collection() { | |
| 561 disable_garbage_collection_ = false; | |
| 562 } | |
| 563 #endif | |
| 564 | |
| 565 private: | 566 private: |
| 566 // Populates greylist_. | 567 // Populates greylist_. |
| 567 void LoadGreylistFromPrefs(); | 568 void LoadGreylistFromPrefs(); |
| 568 | 569 |
| 569 // Signals *ready_ and sends a notification to the listeners. | 570 // Signals *ready_ and sends a notification to the listeners. |
| 570 void SetReadyAndNotifyListeners(); | 571 void SetReadyAndNotifyListeners(); |
| 571 | 572 |
| 572 // Return true if the sync type of |extension| matches |type|. | 573 // Return true if the sync type of |extension| matches |type|. |
| 573 void OnExtensionInstallPrefChanged(); | 574 void OnExtensionInstallPrefChanged(); |
| 574 | 575 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 | 617 |
| 617 // Helper to determine whether we should initially enable an installed | 618 // Helper to determine whether we should initially enable an installed |
| 618 // (or upgraded) extension. | 619 // (or upgraded) extension. |
| 619 bool ShouldEnableOnInstall(const extensions::Extension* extension); | 620 bool ShouldEnableOnInstall(const extensions::Extension* extension); |
| 620 | 621 |
| 621 // Helper to determine if updating an extensions should proceed immediately, | 622 // Helper to determine if updating an extensions should proceed immediately, |
| 622 // or if we should delay the update until further notice. | 623 // or if we should delay the update until further notice. |
| 623 bool ShouldDelayExtensionUpdate(const std::string& extension_id, | 624 bool ShouldDelayExtensionUpdate(const std::string& extension_id, |
| 624 bool wait_for_idle) const; | 625 bool wait_for_idle) const; |
| 625 | 626 |
| 626 // Helper to search storage directories for extensions with isolated storage | |
| 627 // that have been orphaned by an uninstall. | |
| 628 void GarbageCollectIsolatedStorage(); | |
| 629 void OnGarbageCollectIsolatedStorageFinished(); | |
| 630 | |
| 631 // extensions::Blacklist::Observer implementation. | 627 // extensions::Blacklist::Observer implementation. |
| 632 virtual void OnBlacklistUpdated() OVERRIDE; | 628 virtual void OnBlacklistUpdated() OVERRIDE; |
| 633 | 629 |
| 634 // Manages the blacklisted extensions, intended as callback from | 630 // Manages the blacklisted extensions, intended as callback from |
| 635 // Blacklist::GetBlacklistedIDs. | 631 // Blacklist::GetBlacklistedIDs. |
| 636 void ManageBlacklist( | 632 void ManageBlacklist( |
| 637 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids); | 633 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids); |
| 638 | 634 |
| 639 // Add extensions in |blocked| to blacklisted_extensions, remove extensions | 635 // Add extensions in |blocked| to blacklisted_extensions, remove extensions |
| 640 // that are neither in |blocked|, nor in |unchanged|. | 636 // that are neither in |blocked|, nor in |unchanged|. |
| 641 void UpdateBlockedExtensions(const ExtensionIdSet& blocked, | 637 void UpdateBlockedExtensions(const ExtensionIdSet& blocked, |
| 642 const ExtensionIdSet& unchanged); | 638 const ExtensionIdSet& unchanged); |
| 643 | 639 |
| 644 void UpdateGreylistedExtensions( | 640 void UpdateGreylistedExtensions( |
| 645 const ExtensionIdSet& greylist, | 641 const ExtensionIdSet& greylist, |
| 646 const ExtensionIdSet& unchanged, | 642 const ExtensionIdSet& unchanged, |
| 647 const extensions::Blacklist::BlacklistStateMap& state_map); | 643 const extensions::Blacklist::BlacklistStateMap& state_map); |
| 648 | 644 |
| 649 // Controls if installs are delayed. See comment for | |
| 650 // |installs_delayed_for_gc_|. | |
| 651 void set_installs_delayed_for_gc(bool value) { | |
| 652 installs_delayed_for_gc_ = value; | |
| 653 } | |
| 654 bool installs_delayed_for_gc() const { return installs_delayed_for_gc_; } | |
| 655 | |
| 656 // Used only by test code. | 645 // Used only by test code. |
| 657 void UnloadAllExtensionsInternal(); | 646 void UnloadAllExtensionsInternal(); |
| 658 | 647 |
| 659 // The normal profile associated with this ExtensionService. | 648 // The normal profile associated with this ExtensionService. |
| 660 Profile* profile_; | 649 Profile* profile_; |
| 661 | 650 |
| 662 // The ExtensionSystem for the profile above. | 651 // The ExtensionSystem for the profile above. |
| 663 extensions::ExtensionSystem* system_; | 652 extensions::ExtensionSystem* system_; |
| 664 | 653 |
| 665 // Preferences for the owning profile. | 654 // Preferences for the owning profile. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 // Sequenced task runner for extension related file operations. | 764 // Sequenced task runner for extension related file operations. |
| 776 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 765 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
| 777 | 766 |
| 778 #if defined(ENABLE_EXTENSIONS) | 767 #if defined(ENABLE_EXTENSIONS) |
| 779 scoped_ptr<extensions::ExtensionActionStorageManager> | 768 scoped_ptr<extensions::ExtensionActionStorageManager> |
| 780 extension_action_storage_manager_; | 769 extension_action_storage_manager_; |
| 781 #endif | 770 #endif |
| 782 scoped_ptr<extensions::ManagementPolicy::Provider> | 771 scoped_ptr<extensions::ManagementPolicy::Provider> |
| 783 shared_module_policy_provider_; | 772 shared_module_policy_provider_; |
| 784 | 773 |
| 774 // The ExtensionGarbageCollector to clean up all the garbage that leaks into |
| 775 // the extensions directory. |
| 776 scoped_ptr<extensions::ExtensionGarbageCollector> garbage_collector_; |
| 777 |
| 785 ObserverList<extensions::UpdateObserver, true> update_observers_; | 778 ObserverList<extensions::UpdateObserver, true> update_observers_; |
| 786 | 779 |
| 787 #if defined(OS_CHROMEOS) | |
| 788 // TODO(rkc): HACK alert - this is only in place to allow the | |
| 789 // kiosk_mode_screensaver to prevent its extension from getting garbage | |
| 790 // collected. Remove this once KioskModeScreensaver is removed. | |
| 791 // See crbug.com/280363 | |
| 792 bool disable_garbage_collection_; | |
| 793 #endif | |
| 794 | |
| 795 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 780 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 796 InstallAppsWithUnlimtedStorage); | 781 InstallAppsWithUnlimtedStorage); |
| 797 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 782 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 798 InstallAppsAndCheckStorageProtection); | 783 InstallAppsAndCheckStorageProtection); |
| 799 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs); | 784 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs); |
| 800 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 785 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 801 BlacklistedExtensionWillNotInstall); | 786 BlacklistedExtensionWillNotInstall); |
| 802 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 787 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 803 UnloadBlacklistedExtensionPolicy); | 788 UnloadBlacklistedExtensionPolicy); |
| 804 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 789 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 805 WillNotLoadBlacklistedExtensionsFromDirectory); | 790 WillNotLoadBlacklistedExtensionsFromDirectory); |
| 806 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 791 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 807 BlacklistedInPrefsFromStartup); | 792 BlacklistedInPrefsFromStartup); |
| 808 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 793 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 809 GreylistedExtensionDisabled); | 794 GreylistedExtensionDisabled); |
| 810 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 795 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 811 GreylistDontEnableManuallyDisabled); | 796 GreylistDontEnableManuallyDisabled); |
| 812 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 797 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 813 GreylistUnknownDontChange); | 798 GreylistUnknownDontChange); |
| 814 DISALLOW_COPY_AND_ASSIGN(ExtensionService); | 799 DISALLOW_COPY_AND_ASSIGN(ExtensionService); |
| 815 }; | 800 }; |
| 816 | 801 |
| 817 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 802 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
| OLD | NEW |