1 // Copyright 2013 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.
5 #ifndef EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/observer_list.h"
13 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
14 #include "extensions/common/extension_set.h"
20 namespace extensions
{
22 class ExtensionRegistryObserver
;
24 // ExtensionRegistry holds sets of the installed extensions for a given
25 // BrowserContext. An incognito browser context and its master browser context
26 // share a single registry.
27 class ExtensionRegistry
: public BrowserContextKeyedService
{
29 // Flags to pass to GetExtensionById() to select which sets to look in.
36 EVERYTHING
= (1 << 4) - 1,
40 virtual ~ExtensionRegistry();
42 // Returns the instance for the given |browser_context|.
43 static ExtensionRegistry
* Get(content::BrowserContext
* browser_context
);
45 // NOTE: These sets are *eventually* mututally exclusive, but an extension can
46 // appear in two sets for short periods of time.
47 const ExtensionSet
& enabled_extensions() const {
48 return enabled_extensions_
;
50 const ExtensionSet
& disabled_extensions() const {
51 return disabled_extensions_
;
53 const ExtensionSet
& terminated_extensions() const {
54 return terminated_extensions_
;
56 const ExtensionSet
& blacklisted_extensions() const {
57 return blacklisted_extensions_
;
60 // The usual observer interface.
61 void AddObserver(ExtensionRegistryObserver
* observer
);
62 void RemoveObserver(ExtensionRegistryObserver
* observer
);
64 // Invokes the observer method OnExtensionUnloaded(). The extension must not
65 // be enabled at the time of the call.
66 void TriggerOnUnloaded(const Extension
* extension
);
68 // Find an extension by ID using |include_mask| to pick the sets to search:
69 // * enabled_extensions() --> ExtensionRegistry::ENABLED
70 // * disabled_extensions() --> ExtensionRegistry::DISABLED
71 // * terminated_extensions() --> ExtensionRegistry::TERMINATED
72 // * blacklisted_extensions() --> ExtensionRegistry::BLACKLISTED
73 // Returns NULL if the extension is not found in the selected sets.
74 const Extension
* GetExtensionById(const std::string
& id
,
75 int include_mask
) const;
77 // Adds the specified extension to the enabled set. The registry becomes an
78 // owner. Any previous extension with the same ID is removed.
79 // Returns true if there is no previous extension.
80 // NOTE: You probably want to use ExtensionService instead of calling this
82 bool AddEnabled(const scoped_refptr
<const Extension
>& extension
);
84 // Removes the specified extension from the enabled set.
85 // Returns true if the set contained the specified extension.
86 // NOTE: You probably want to use ExtensionService instead of calling this
88 bool RemoveEnabled(const std::string
& id
);
90 // As above, but for the disabled set.
91 bool AddDisabled(const scoped_refptr
<const Extension
>& extension
);
92 bool RemoveDisabled(const std::string
& id
);
94 // As above, but for the terminated set.
95 bool AddTerminated(const scoped_refptr
<const Extension
>& extension
);
96 bool RemoveTerminated(const std::string
& id
);
98 // As above, but for the blacklisted set.
99 bool AddBlacklisted(const scoped_refptr
<const Extension
>& extension
);
100 bool RemoveBlacklisted(const std::string
& id
);
102 // Removes all extensions from all sets.
105 // Sets a callback to run when the disabled extension set is modified.
106 // TODO(jamescook): This is too specific for a generic registry; find some
107 // other way to do this.
108 void SetDisabledModificationCallback(
109 const ExtensionSet::ModificationCallback
& callback
);
111 // BrowserContextKeyedService implementation:
112 virtual void Shutdown() OVERRIDE
;
115 // Extensions that are installed, enabled and not terminated.
116 ExtensionSet enabled_extensions_
;
118 // Extensions that are installed and disabled.
119 ExtensionSet disabled_extensions_
;
121 // Extensions that are installed and terminated.
122 ExtensionSet terminated_extensions_
;
124 // Extensions that are installed and blacklisted. Generally these shouldn't be
125 // considered as installed by the extension platform: we only keep them around
126 // so that if extensions are blacklisted by mistake they can easily be
128 ExtensionSet blacklisted_extensions_
;
130 ObserverList
<ExtensionRegistryObserver
> observers_
;
132 DISALLOW_COPY_AND_ASSIGN(ExtensionRegistry
);
135 } // namespace extensions
137 #endif // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_