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

Side by Side Diff: chrome/browser/extensions/extension_service.h

Issue 1890163004: extensions: Abstract out install delay strategy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for comments in #4 Created 4 years, 8 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) 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 <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
20 #include "chrome/browser/extensions/blacklist.h" 20 #include "chrome/browser/extensions/blacklist.h"
21 #include "chrome/browser/extensions/extension_management.h" 21 #include "chrome/browser/extensions/extension_management.h"
22 #include "chrome/browser/extensions/install_gate.h"
22 #include "chrome/browser/extensions/pending_extension_manager.h" 23 #include "chrome/browser/extensions/pending_extension_manager.h"
23 #include "content/public/browser/notification_observer.h" 24 #include "content/public/browser/notification_observer.h"
24 #include "content/public/browser/notification_registrar.h" 25 #include "content/public/browser/notification_registrar.h"
25 #include "extensions/browser/crx_file_info.h" 26 #include "extensions/browser/crx_file_info.h"
27 #include "extensions/browser/extension_prefs.h"
26 #include "extensions/browser/external_provider_interface.h" 28 #include "extensions/browser/external_provider_interface.h"
27 #include "extensions/browser/install_flag.h" 29 #include "extensions/browser/install_flag.h"
28 #include "extensions/browser/process_manager.h" 30 #include "extensions/browser/process_manager.h"
29 #include "extensions/browser/uninstall_reason.h" 31 #include "extensions/browser/uninstall_reason.h"
30 #include "extensions/common/extension.h" 32 #include "extensions/common/extension.h"
31 #include "extensions/common/extension_set.h" 33 #include "extensions/common/extension_set.h"
32 #include "extensions/common/manifest.h" 34 #include "extensions/common/manifest.h"
33 #include "sync/api/string_ordinal.h" 35 #include "sync/api/string_ordinal.h"
34 36
35 #if !defined(ENABLE_EXTENSIONS) 37 #if !defined(ENABLE_EXTENSIONS)
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 void MaybeFinishDelayedInstallations(); 341 void MaybeFinishDelayedInstallations();
340 342
341 // ExtensionHost of background page calls this method right after its render 343 // ExtensionHost of background page calls this method right after its render
342 // view has been created. 344 // view has been created.
343 void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host); 345 void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host);
344 346
345 // Changes sequenced task runner for crx installation tasks to |task_runner|. 347 // Changes sequenced task runner for crx installation tasks to |task_runner|.
346 void SetFileTaskRunnerForTesting( 348 void SetFileTaskRunnerForTesting(
347 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 349 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
348 350
349 // Postpone installations so that we don't have to worry about race
350 // conditions.
351 void OnGarbageCollectIsolatedStorageStart();
352
353 // Restart any extension installs which were delayed for isolated storage
354 // garbage collection.
355 void OnGarbageCollectIsolatedStorageFinished();
356
357 // Record a histogram using the PermissionMessage enum values for each 351 // Record a histogram using the PermissionMessage enum values for each
358 // permission in |e|. 352 // permission in |e|.
359 // NOTE: If this is ever called with high frequency, the implementation may 353 // NOTE: If this is ever called with high frequency, the implementation may
360 // need to be made more efficient. 354 // need to be made more efficient.
361 static void RecordPermissionMessagesHistogram( 355 static void RecordPermissionMessagesHistogram(
362 const extensions::Extension* extension, const char* histogram); 356 const extensions::Extension* extension, const char* histogram);
363 357
364 // Unloads the given extension and mark the extension as terminated. This 358 // Unloads the given extension and mark the extension as terminated. This
365 // doesn't notify the user that the extension was terminated, if such a 359 // doesn't notify the user that the extension was terminated, if such a
366 // notification is desired the calling code is responsible for doing that. 360 // notification is desired the calling code is responsible for doing that.
367 void TerminateExtension(const std::string& extension_id); 361 void TerminateExtension(const std::string& extension_id);
368 362
369 // Register self and content settings API with the specified map. 363 // Register self and content settings API with the specified map.
370 void RegisterContentSettings( 364 void RegisterContentSettings(
371 HostContentSettingsMap* host_content_settings_map); 365 HostContentSettingsMap* host_content_settings_map);
372 366
373 // Adds/Removes update observers. 367 // Adds/Removes update observers.
374 void AddUpdateObserver(extensions::UpdateObserver* observer); 368 void AddUpdateObserver(extensions::UpdateObserver* observer);
375 void RemoveUpdateObserver(extensions::UpdateObserver* observer); 369 void RemoveUpdateObserver(extensions::UpdateObserver* observer);
376 370
371 // Register/unregister an InstallGate with the service.
372 void RegisterInstallGate(extensions::ExtensionPrefs::DelayReason reason,
373 extensions::InstallGate* install_delayer);
374 void UnregisterInstallGate(extensions::InstallGate* install_delayer);
375
377 ////////////////////////////////////////////////////////////////////////////// 376 //////////////////////////////////////////////////////////////////////////////
378 // Simple Accessors 377 // Simple Accessors
379 378
380 // Returns a WeakPtr to the ExtensionService. 379 // Returns a WeakPtr to the ExtensionService.
381 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); } 380 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
382 381
383 // Returns profile_ as a BrowserContext. 382 // Returns profile_ as a BrowserContext.
384 content::BrowserContext* GetBrowserContext() const; 383 content::BrowserContext* GetBrowserContext() const;
385 384
386 bool extensions_enabled() const { return extensions_enabled_; } 385 bool extensions_enabled() const { return extensions_enabled_; }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 442
444 void FinishInstallationForTest(const extensions::Extension* extension) { 443 void FinishInstallationForTest(const extensions::Extension* extension) {
445 FinishInstallation(extension); 444 FinishInstallation(extension);
446 } 445 }
447 #endif 446 #endif
448 447
449 void set_browser_terminating_for_test(bool value) { 448 void set_browser_terminating_for_test(bool value) {
450 browser_terminating_ = value; 449 browser_terminating_ = value;
451 } 450 }
452 451
453 // By default ExtensionService will wait with installing an updated extension
454 // until the extension is idle. Tests might not like this behavior, so you can
455 // disable it with this method.
456 void set_install_updates_when_idle_for_test(bool value) {
457 install_updates_when_idle_ = value;
458 }
459
460 // Set a callback to be called when all external providers are ready and their 452 // Set a callback to be called when all external providers are ready and their
461 // extensions have been installed. 453 // extensions have been installed.
462 void set_external_updates_finished_callback_for_test( 454 void set_external_updates_finished_callback_for_test(
463 const base::Closure& callback) { 455 const base::Closure& callback) {
464 external_updates_finished_callback_ = callback; 456 external_updates_finished_callback_ = callback;
465 } 457 }
466 458
467 private: 459 private:
468 // Reloads the specified extension, sending the onLaunched() event to it if it 460 // Reloads the specified extension, sending the onLaunched() event to it if it
469 // currently has any window showing. |be_noisy| determines whether noisy 461 // currently has any window showing. |be_noisy| determines whether noisy
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 void UpdateActiveExtensionsInCrashReporter(); 543 void UpdateActiveExtensionsInCrashReporter();
552 544
553 // Helper to get the disable reasons for an installed (or upgraded) extension. 545 // Helper to get the disable reasons for an installed (or upgraded) extension.
554 // A return value of Extension::DISABLE_NONE indicates that we should enable 546 // A return value of Extension::DISABLE_NONE indicates that we should enable
555 // this extension initially. 547 // this extension initially.
556 int GetDisableReasonsOnInstalled(const extensions::Extension* extension); 548 int GetDisableReasonsOnInstalled(const extensions::Extension* extension);
557 549
558 // Helper method to determine if an extension can be blocked. 550 // Helper method to determine if an extension can be blocked.
559 bool CanBlockExtension(const extensions::Extension* extension) const; 551 bool CanBlockExtension(const extensions::Extension* extension) const;
560 552
561 // Helper to determine if updating an extensions should proceed immediately, 553 // Helper to determine if installing an extensions should proceed immediately,
562 // or if we should delay the update until further notice. 554 // or if we should delay the install until further notice, or if the install
563 bool ShouldDelayExtensionUpdate(const std::string& extension_id, 555 // should be aborted. A pending install is delayed or aborted when any of the
564 bool install_immediately) const; 556 // delayers say so and only proceeds when all delayers return INSTALL.
557 // |extension| is the extension to be installed. |install_immediately| is the
558 // install flag set with the install. |reason| is the reason associated with
559 // the install delayer that wants to defer or abort the install.
560 extensions::InstallGate::Action ShouldDelayExtensionInstall(
561 const extensions::Extension* extension,
562 bool install_immediately,
563 extensions::ExtensionPrefs::DelayReason* reason) const;
565 564
566 // Manages the blacklisted extensions, intended as callback from 565 // Manages the blacklisted extensions, intended as callback from
567 // Blacklist::GetBlacklistedIDs. 566 // Blacklist::GetBlacklistedIDs.
568 void ManageBlacklist( 567 void ManageBlacklist(
569 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids); 568 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids);
570 569
571 // Add extensions in |blacklisted| to blacklisted_extensions, remove 570 // Add extensions in |blacklisted| to blacklisted_extensions, remove
572 // extensions that are neither in |blacklisted|, nor in |unchanged|. 571 // extensions that are neither in |blacklisted|, nor in |unchanged|.
573 void UpdateBlacklistedExtensions( 572 void UpdateBlacklistedExtensions(
574 const extensions::ExtensionIdSet& to_blacklist, 573 const extensions::ExtensionIdSet& to_blacklist,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 626
628 // The full path to the directory where extensions are installed. 627 // The full path to the directory where extensions are installed.
629 base::FilePath install_directory_; 628 base::FilePath install_directory_;
630 629
631 // Whether or not extensions are enabled. 630 // Whether or not extensions are enabled.
632 bool extensions_enabled_ = true; 631 bool extensions_enabled_ = true;
633 632
634 // Whether to notify users when they attempt to install an extension. 633 // Whether to notify users when they attempt to install an extension.
635 bool show_extensions_prompts_ = true; 634 bool show_extensions_prompts_ = true;
636 635
637 // Whether to delay installing of extension updates until the extension is
638 // idle.
639 bool install_updates_when_idle_ = true;
640
641 // Signaled when all extensions are loaded. 636 // Signaled when all extensions are loaded.
642 extensions::OneShotEvent* const ready_; 637 extensions::OneShotEvent* const ready_;
643 638
644 // Our extension updater, if updates are turned on. 639 // Our extension updater, if updates are turned on.
645 std::unique_ptr<extensions::ExtensionUpdater> updater_; 640 std::unique_ptr<extensions::ExtensionUpdater> updater_;
646 641
647 // Map unloaded extensions' ids to their paths. When a temporarily loaded 642 // Map unloaded extensions' ids to their paths. When a temporarily loaded
648 // extension is unloaded, we lose the information about it and don't have 643 // extension is unloaded, we lose the information about it and don't have
649 // any in the extension preferences file. 644 // any in the extension preferences file.
650 using UnloadedExtensionPathMap = std::map<std::string, base::FilePath>; 645 using UnloadedExtensionPathMap = std::map<std::string, base::FilePath>;
(...skipping 25 matching lines...) Expand all
676 // A callback to be called when all external providers are ready and their 671 // A callback to be called when all external providers are ready and their
677 // extensions have been installed. Normally this is a null callback, but 672 // extensions have been installed. Normally this is a null callback, but
678 // is used in external provider related tests. 673 // is used in external provider related tests.
679 base::Closure external_updates_finished_callback_; 674 base::Closure external_updates_finished_callback_;
680 675
681 // Set when the browser is terminating. Prevents us from installing or 676 // Set when the browser is terminating. Prevents us from installing or
682 // updating additional extensions and allows in-progress installations to 677 // updating additional extensions and allows in-progress installations to
683 // decide to abort. 678 // decide to abort.
684 bool browser_terminating_ = false; 679 bool browser_terminating_ = false;
685 680
686 // Set to true to delay all new extension installations. Acts as a lock to
687 // allow background processing of garbage collection of on-disk state without
688 // needing to worry about race conditions caused by extension installation and
689 // reinstallation.
690 bool installs_delayed_for_gc_ = false;
691
692 // Set to true if this is the first time this ExtensionService has run. 681 // Set to true if this is the first time this ExtensionService has run.
693 // Used for specially handling external extensions that are installed the 682 // Used for specially handling external extensions that are installed the
694 // first time. 683 // first time.
695 bool is_first_run_ = false; 684 bool is_first_run_ = false;
696 685
697 // Set to true if extensions are all to be blocked. 686 // Set to true if extensions are all to be blocked.
698 bool block_extensions_ = false; 687 bool block_extensions_ = false;
699 688
700 // Store the ids of reloading extensions. We use this to re-enable extensions 689 // Store the ids of reloading extensions. We use this to re-enable extensions
701 // which were disabled for a reload. 690 // which were disabled for a reload.
(...skipping 18 matching lines...) Expand all
720 extension_action_storage_manager_; 709 extension_action_storage_manager_;
721 710
722 // The SharedModuleService used to check for import dependencies. 711 // The SharedModuleService used to check for import dependencies.
723 std::unique_ptr<extensions::SharedModuleService> shared_module_service_; 712 std::unique_ptr<extensions::SharedModuleService> shared_module_service_;
724 713
725 base::ObserverList<extensions::UpdateObserver, true> update_observers_; 714 base::ObserverList<extensions::UpdateObserver, true> update_observers_;
726 715
727 // Migrates app data when upgrading a legacy packaged app to a platform app 716 // Migrates app data when upgrading a legacy packaged app to a platform app
728 std::unique_ptr<extensions::AppDataMigrator> app_data_migrator_; 717 std::unique_ptr<extensions::AppDataMigrator> app_data_migrator_;
729 718
719 using InstallGateRegistry = std::map<extensions::ExtensionPrefs::DelayReason,
720 extensions::InstallGate*>;
721 InstallGateRegistry install_delayer_registry_;
722
730 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 723 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
731 DestroyingProfileClearsExtensions); 724 DestroyingProfileClearsExtensions);
732 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs); 725 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs);
733 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 726 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
734 BlacklistedExtensionWillNotInstall); 727 BlacklistedExtensionWillNotInstall);
735 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 728 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
736 UnloadBlacklistedExtensionPolicy); 729 UnloadBlacklistedExtensionPolicy);
737 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 730 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
738 WillNotLoadBlacklistedExtensionsFromDirectory); 731 WillNotLoadBlacklistedExtensionsFromDirectory);
739 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, ReloadBlacklistedExtension); 732 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, ReloadBlacklistedExtension);
740 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, BlacklistedInPrefsFromStartup); 733 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, BlacklistedInPrefsFromStartup);
741 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 734 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
742 GreylistedExtensionDisabled); 735 GreylistedExtensionDisabled);
743 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 736 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
744 GreylistDontEnableManuallyDisabled); 737 GreylistDontEnableManuallyDisabled);
745 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 738 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
746 GreylistUnknownDontChange); 739 GreylistUnknownDontChange);
747 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 740 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
748 ManagementPolicyProhibitsEnableOnInstalled); 741 ManagementPolicyProhibitsEnableOnInstalled);
749 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 742 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
750 BlockAndUnblockBlacklistedExtension); 743 BlockAndUnblockBlacklistedExtension);
751 744
752 DISALLOW_COPY_AND_ASSIGN(ExtensionService); 745 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
753 }; 746 };
754 747
755 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 748 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_gcm_app_handler_unittest.cc ('k') | chrome/browser/extensions/extension_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698