electron_extension_system.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_SYSTEM_H_
  5. #define SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_SYSTEM_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/compiler_specific.h"
  10. #include "base/macros.h"
  11. #include "base/memory/ref_counted.h"
  12. #include "base/memory/weak_ptr.h"
  13. #include "base/one_shot_event.h"
  14. #include "extensions/browser/extension_system.h"
  15. namespace base {
  16. class FilePath;
  17. }
  18. namespace content {
  19. class BrowserContext;
  20. }
  21. namespace extensions {
  22. class ElectronExtensionLoader;
  23. class ValueStoreFactory;
  24. // A simplified version of ExtensionSystem for app_shell. Allows
  25. // app_shell to skip initialization of services it doesn't need.
  26. class ElectronExtensionSystem : public ExtensionSystem {
  27. public:
  28. using InstallUpdateCallback = ExtensionSystem::InstallUpdateCallback;
  29. explicit ElectronExtensionSystem(content::BrowserContext* browser_context);
  30. ~ElectronExtensionSystem() override;
  31. // Loads an unpacked extension from a directory. Returns the extension on
  32. // success, or nullptr otherwise.
  33. void LoadExtension(
  34. const base::FilePath& extension_dir,
  35. base::OnceCallback<void(const Extension*, const std::string&)> cb);
  36. // Finish initialization for the shell extension system.
  37. void FinishInitialization();
  38. // Reloads the extension with id |extension_id|.
  39. void ReloadExtension(const ExtensionId& extension_id);
  40. void RemoveExtension(const ExtensionId& extension_id);
  41. // KeyedService implementation:
  42. void Shutdown() override;
  43. // ExtensionSystem implementation:
  44. void InitForRegularProfile(bool extensions_enabled) override;
  45. ExtensionService* extension_service() override;
  46. RuntimeData* runtime_data() override;
  47. ManagementPolicy* management_policy() override;
  48. ServiceWorkerManager* service_worker_manager() override;
  49. SharedUserScriptManager* shared_user_script_manager() override;
  50. StateStore* state_store() override;
  51. StateStore* rules_store() override;
  52. scoped_refptr<ValueStoreFactory> store_factory() override;
  53. InfoMap* info_map() override;
  54. QuotaService* quota_service() override;
  55. AppSorting* app_sorting() override;
  56. void RegisterExtensionWithRequestContexts(
  57. const Extension* extension,
  58. base::OnceClosure callback) override;
  59. void UnregisterExtensionWithRequestContexts(
  60. const std::string& extension_id,
  61. const UnloadedExtensionReason reason) override;
  62. const base::OneShotEvent& ready() const override;
  63. bool is_ready() const override;
  64. ContentVerifier* content_verifier() override;
  65. std::unique_ptr<ExtensionSet> GetDependentExtensions(
  66. const Extension* extension) override;
  67. void InstallUpdate(const std::string& extension_id,
  68. const std::string& public_key,
  69. const base::FilePath& temp_dir,
  70. bool install_immediately,
  71. InstallUpdateCallback install_update_callback) override;
  72. bool FinishDelayedInstallationIfReady(const std::string& extension_id,
  73. bool install_immediately) override;
  74. void PerformActionBasedOnOmahaAttributes(
  75. const std::string& extension_id,
  76. const base::Value& attributes) override;
  77. private:
  78. void OnExtensionRegisteredWithRequestContexts(
  79. scoped_refptr<Extension> extension);
  80. void LoadComponentExtensions();
  81. content::BrowserContext* browser_context_; // Not owned.
  82. // Data to be accessed on the IO thread. Must outlive process_manager_.
  83. scoped_refptr<InfoMap> info_map_;
  84. std::unique_ptr<ServiceWorkerManager> service_worker_manager_;
  85. std::unique_ptr<RuntimeData> runtime_data_;
  86. std::unique_ptr<QuotaService> quota_service_;
  87. std::unique_ptr<SharedUserScriptManager> shared_user_script_manager_;
  88. std::unique_ptr<AppSorting> app_sorting_;
  89. std::unique_ptr<ElectronExtensionLoader> extension_loader_;
  90. scoped_refptr<ValueStoreFactory> store_factory_;
  91. // Signaled when the extension system has completed its startup tasks.
  92. base::OneShotEvent ready_;
  93. base::WeakPtrFactory<ElectronExtensionSystem> weak_factory_;
  94. DISALLOW_COPY_AND_ASSIGN(ElectronExtensionSystem);
  95. };
  96. } // namespace extensions
  97. #endif // SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_SYSTEM_H_