electron_extension_system.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_SYSTEM_H_
  5. #define ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_SYSTEM_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "base/one_shot_event.h"
  11. #include "components/value_store/value_store_factory.h"
  12. #include "components/value_store/value_store_factory_impl.h"
  13. #include "extensions/browser/extension_system.h"
  14. namespace base {
  15. class FilePath;
  16. }
  17. namespace content {
  18. class BrowserContext;
  19. }
  20. namespace extensions {
  21. class ElectronExtensionLoader;
  22. class ValueStoreFactory;
  23. // A simplified version of ExtensionSystem for app_shell. Allows
  24. // app_shell to skip initialization of services it doesn't need.
  25. class ElectronExtensionSystem : public ExtensionSystem {
  26. public:
  27. using InstallUpdateCallback = ExtensionSystem::InstallUpdateCallback;
  28. explicit ElectronExtensionSystem(content::BrowserContext* browser_context);
  29. ~ElectronExtensionSystem() override;
  30. // disable copy
  31. ElectronExtensionSystem(const ElectronExtensionSystem&) = delete;
  32. ElectronExtensionSystem& operator=(const ElectronExtensionSystem&) = delete;
  33. // Loads an unpacked extension from a directory. Returns the extension on
  34. // success, or nullptr otherwise.
  35. void LoadExtension(
  36. const base::FilePath& extension_dir,
  37. int load_flags,
  38. base::OnceCallback<void(const Extension*, const std::string&)> cb);
  39. // Finish initialization for the shell extension system.
  40. void FinishInitialization();
  41. // Reloads the extension with id |extension_id|.
  42. void ReloadExtension(const ExtensionId& extension_id);
  43. void RemoveExtension(const ExtensionId& extension_id);
  44. // KeyedService implementation:
  45. void Shutdown() override;
  46. // ExtensionSystem implementation:
  47. void InitForRegularProfile(bool extensions_enabled) override;
  48. ExtensionService* extension_service() override;
  49. ManagementPolicy* management_policy() override;
  50. ServiceWorkerManager* service_worker_manager() override;
  51. UserScriptManager* user_script_manager() override;
  52. StateStore* state_store() override;
  53. StateStore* rules_store() override;
  54. StateStore* dynamic_user_scripts_store() override;
  55. scoped_refptr<value_store::ValueStoreFactory> store_factory() override;
  56. QuotaService* quota_service() override;
  57. AppSorting* app_sorting() override;
  58. const base::OneShotEvent& ready() const override;
  59. bool is_ready() const override;
  60. ContentVerifier* content_verifier() override;
  61. std::unique_ptr<ExtensionSet> GetDependentExtensions(
  62. const Extension* extension) override;
  63. void InstallUpdate(const std::string& extension_id,
  64. const std::string& public_key,
  65. const base::FilePath& temp_dir,
  66. bool install_immediately,
  67. InstallUpdateCallback install_update_callback) override;
  68. bool FinishDelayedInstallationIfReady(const std::string& extension_id,
  69. bool install_immediately) override;
  70. void PerformActionBasedOnOmahaAttributes(
  71. const std::string& extension_id,
  72. const base::Value::Dict& attributes) override;
  73. private:
  74. void OnExtensionRegisteredWithRequestContexts(
  75. scoped_refptr<Extension> extension);
  76. void LoadComponentExtensions();
  77. raw_ptr<content::BrowserContext> browser_context_; // Not owned.
  78. std::unique_ptr<ServiceWorkerManager> service_worker_manager_;
  79. std::unique_ptr<QuotaService> quota_service_;
  80. std::unique_ptr<UserScriptManager> user_script_manager_;
  81. std::unique_ptr<AppSorting> app_sorting_;
  82. std::unique_ptr<ManagementPolicy> management_policy_;
  83. std::unique_ptr<ElectronExtensionLoader> extension_loader_;
  84. scoped_refptr<value_store::ValueStoreFactory> store_factory_;
  85. // Signaled when the extension system has completed its startup tasks.
  86. base::OneShotEvent ready_;
  87. base::WeakPtrFactory<ElectronExtensionSystem> weak_factory_{this};
  88. };
  89. } // namespace extensions
  90. #endif // ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_SYSTEM_H_