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
5#ifndef EXTENSIONS_BROWSER_EXTENSION_SYSTEM_H_
6#define EXTENSIONS_BROWSER_EXTENSION_SYSTEM_H_
7
8#include <string>
9
10#include "base/memory/ref_counted.h"
11#include "components/keyed_service/core/keyed_service.h"
12#include "extensions/common/extension.h"
13
14class ExtensionService;
15
16#if defined(OS_CHROMEOS)
17namespace chromeos {
18class DeviceLocalAccountManagementPolicyProvider;
19}
20#endif  // defined(OS_CHROMEOS)
21
22namespace content {
23class BrowserContext;
24}
25
26namespace extensions {
27
28class Blacklist;
29class ContentVerifier;
30class ErrorConsole;
31class EventRouter;
32class Extension;
33class ExtensionSet;
34class ExtensionWarningService;
35class InfoMap;
36class InstallVerifier;
37class LazyBackgroundTaskQueue;
38class ManagementPolicy;
39class OneShotEvent;
40class ProcessManager;
41class QuotaService;
42class RuntimeData;
43class StateStore;
44class UserScriptMaster;
45
46// ExtensionSystem manages the lifetime of many of the services used by the
47// extensions and apps system, and it handles startup and shutdown as needed.
48// Eventually, we'd like to make more of these services into KeyedServices in
49// their own right.
50class ExtensionSystem : public KeyedService {
51 public:
52  ExtensionSystem();
53  virtual ~ExtensionSystem();
54
55  // Returns the instance for the given browser context, or NULL if none.
56  static ExtensionSystem* Get(content::BrowserContext* context);
57
58  // Initializes extensions machinery.
59  // Component extensions are always enabled, external and user extensions are
60  // controlled by |extensions_enabled|.
61  virtual void InitForRegularProfile(bool extensions_enabled) = 0;
62
63  // The ExtensionService is created at startup.
64  virtual ExtensionService* extension_service() = 0;
65
66  // Per-extension data that can change during the life of the process but
67  // does not persist across restarts. Lives on UI thread. Created at startup.
68  virtual RuntimeData* runtime_data() = 0;
69
70  // The class controlling whether users are permitted to perform certain
71  // actions on extensions (install, uninstall, disable, etc.).
72  // The ManagementPolicy is created at startup.
73  virtual ManagementPolicy* management_policy() = 0;
74
75  // The UserScriptMaster is created at startup.
76  virtual UserScriptMaster* user_script_master() = 0;
77
78  // The ProcessManager is created at startup.
79  virtual ProcessManager* process_manager() = 0;
80
81  // The StateStore is created at startup.
82  virtual StateStore* state_store() = 0;
83
84  // The rules store is created at startup.
85  virtual StateStore* rules_store() = 0;
86
87  // Returns the IO-thread-accessible extension data.
88  virtual InfoMap* info_map() = 0;
89
90  // The LazyBackgroundTaskQueue is created at startup.
91  virtual LazyBackgroundTaskQueue* lazy_background_task_queue() = 0;
92
93  // The EventRouter is created at startup.
94  virtual EventRouter* event_router() = 0;
95
96  // The ExtensionWarningService is created at startup.
97  virtual ExtensionWarningService* warning_service() = 0;
98
99  // The blacklist is created at startup.
100  virtual Blacklist* blacklist() = 0;
101
102  // The ErrorConsole is created at startup.
103  virtual ErrorConsole* error_console() = 0;
104
105  // The InstallVerifier is created at startup.
106  virtual InstallVerifier* install_verifier() = 0;
107
108  // Returns the QuotaService that limits calls to certain extension functions.
109  // Lives on the UI thread. Created at startup.
110  virtual QuotaService* quota_service() = 0;
111
112  // Called by the ExtensionService that lives in this system. Gives the
113  // info map a chance to react to the load event before the EXTENSION_LOADED
114  // notification has fired. The purpose for handling this event first is to
115  // avoid race conditions by making sure URLRequestContexts learn about new
116  // extensions before anything else needs them to know.
117  virtual void RegisterExtensionWithRequestContexts(
118      const Extension* extension) {}
119
120  // Called by the ExtensionService that lives in this system. Lets the
121  // info map clean up its RequestContexts once all the listeners to the
122  // EXTENSION_UNLOADED notification have finished running.
123  virtual void UnregisterExtensionWithRequestContexts(
124      const std::string& extension_id,
125      const UnloadedExtensionInfo::Reason reason) {}
126
127  // Signaled when the extension system has completed its startup tasks.
128  virtual const OneShotEvent& ready() const = 0;
129
130  // Returns the content verifier, if any.
131  virtual ContentVerifier* content_verifier() = 0;
132
133  // Get a set of extensions that depend on the given extension.
134  // TODO(elijahtaylor): Move SharedModuleService out of chrome/browser
135  // so it can be retrieved from ExtensionSystem directly.
136  virtual scoped_ptr<ExtensionSet> GetDependentExtensions(
137      const Extension* extension) = 0;
138};
139
140}  // namespace extensions
141
142#endif  // EXTENSIONS_BROWSER_EXTENSION_SYSTEM_H_
143