Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_system_impl.h
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 CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_
7
8 #include "base/memory/scoped_vector.h"
9 #include "extensions/browser/extension_system.h"
10 #include "extensions/common/one_shot_event.h"
11
12 class Profile;
13
14 namespace extensions {
15
16 class ContentVerifier;
17 class DeclarativeUserScriptMaster;
18 class ExtensionSystemSharedFactory;
19 class NavigationObserver;
20 class SharedUserScriptMaster;
21 class StateStoreNotificationObserver;
22
23 // The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl.
24 // Implementation details: non-shared services are owned by
25 // ExtensionSystemImpl, a KeyedService with separate incognito
26 // instances. A private Shared class (also a KeyedService,
27 // but with a shared instance for incognito) keeps the common services.
28 class ExtensionSystemImpl : public ExtensionSystem {
29  public:
30   explicit ExtensionSystemImpl(Profile* profile);
31   ~ExtensionSystemImpl() override;
32
33   // KeyedService implementation.
34   void Shutdown() override;
35
36   void InitForRegularProfile(bool extensions_enabled) override;
37
38   ExtensionService* extension_service() override;  // shared
39   RuntimeData* runtime_data() override;            // shared
40   ManagementPolicy* management_policy() override;  // shared
41   // shared
42   SharedUserScriptMaster* shared_user_script_master() override;
43   StateStore* state_store() override;                              // shared
44   StateStore* rules_store() override;                              // shared
45   LazyBackgroundTaskQueue* lazy_background_task_queue() override;  // shared
46   InfoMap* info_map() override;                                    // shared
47   EventRouter* event_router() override;                            // shared
48   ErrorConsole* error_console() override;
49   InstallVerifier* install_verifier() override;
50   QuotaService* quota_service() override;  // shared
51
52   void RegisterExtensionWithRequestContexts(
53       const Extension* extension) override;
54
55   void UnregisterExtensionWithRequestContexts(
56       const std::string& extension_id,
57       const UnloadedExtensionInfo::Reason reason) override;
58
59   const OneShotEvent& ready() const override;
60   ContentVerifier* content_verifier() override;  // shared
61   scoped_ptr<ExtensionSet> GetDependentExtensions(
62       const Extension* extension) override;
63
64   DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByExtension(
65       const ExtensionId& extension_id) override;  // shared
66
67  private:
68   friend class ExtensionSystemSharedFactory;
69
70   // Owns the Extension-related systems that have a single instance
71   // shared between normal and incognito profiles.
72   class Shared : public KeyedService {
73    public:
74     explicit Shared(Profile* profile);
75     ~Shared() override;
76
77     // Initialization takes place in phases.
78     virtual void InitPrefs();
79     // This must not be called until all the providers have been created.
80     void RegisterManagementPolicyProviders();
81     void Init(bool extensions_enabled);
82
83     // KeyedService implementation.
84     void Shutdown() override;
85
86     StateStore* state_store();
87     StateStore* rules_store();
88     ExtensionService* extension_service();
89     RuntimeData* runtime_data();
90     ManagementPolicy* management_policy();
91     SharedUserScriptMaster* shared_user_script_master();
92     InfoMap* info_map();
93     LazyBackgroundTaskQueue* lazy_background_task_queue();
94     EventRouter* event_router();
95     ErrorConsole* error_console();
96     InstallVerifier* install_verifier();
97     QuotaService* quota_service();
98     const OneShotEvent& ready() const { return ready_; }
99     ContentVerifier* content_verifier();
100
101     DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByExtension(
102         const ExtensionId& extension_id);
103
104    private:
105     Profile* profile_;
106
107     // The services that are shared between normal and incognito profiles.
108
109     scoped_ptr<StateStore> state_store_;
110     scoped_ptr<StateStoreNotificationObserver>
111         state_store_notification_observer_;
112     scoped_ptr<StateStore> rules_store_;
113     // LazyBackgroundTaskQueue is a dependency of
114     // MessageService and EventRouter.
115     scoped_ptr<LazyBackgroundTaskQueue> lazy_background_task_queue_;
116     scoped_ptr<EventRouter> event_router_;
117     scoped_ptr<NavigationObserver> navigation_observer_;
118     // Shared memory region manager for scripts statically declared in extension
119     // manifests. This region is shared between all extensions.
120     scoped_ptr<SharedUserScriptMaster> shared_user_script_master_;
121     // Shared memory region manager for programmatically declared scripts, one
122     // per extension. Managers are instantiated the first time the declarative
123     // API is used by an extension to request content scripts.
124     ScopedVector<DeclarativeUserScriptMaster> declarative_user_script_masters_;
125     scoped_ptr<RuntimeData> runtime_data_;
126     // ExtensionService depends on StateStore, Blacklist and RuntimeData.
127     scoped_ptr<ExtensionService> extension_service_;
128     scoped_ptr<ManagementPolicy> management_policy_;
129     // extension_info_map_ needs to outlive process_manager_.
130     scoped_refptr<InfoMap> extension_info_map_;
131     scoped_ptr<ErrorConsole> error_console_;
132     scoped_ptr<InstallVerifier> install_verifier_;
133     scoped_ptr<QuotaService> quota_service_;
134
135     // For verifying the contents of extensions read from disk.
136     scoped_refptr<ContentVerifier> content_verifier_;
137
138 #if defined(OS_CHROMEOS)
139     scoped_ptr<chromeos::DeviceLocalAccountManagementPolicyProvider>
140         device_local_account_management_policy_provider_;
141 #endif
142
143     OneShotEvent ready_;
144   };
145
146   Profile* profile_;
147
148   Shared* shared_;
149
150   DISALLOW_COPY_AND_ASSIGN(ExtensionSystemImpl);
151 };
152
153 }  // namespace extensions
154
155 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_