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