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 #include "extensions/browser/extension_registry.h"
7 #include "base/strings/string_util.h"
8 #include "extensions/browser/extension_registry_factory.h"
9 #include "extensions/browser/extension_registry_observer.h"
11 namespace extensions
{
13 ExtensionRegistry::ExtensionRegistry(content::BrowserContext
* browser_context
)
14 : browser_context_(browser_context
) {}
15 ExtensionRegistry::~ExtensionRegistry() {}
18 ExtensionRegistry
* ExtensionRegistry::Get(content::BrowserContext
* context
) {
19 return ExtensionRegistryFactory::GetForBrowserContext(context
);
22 scoped_ptr
<ExtensionSet
> ExtensionRegistry::GenerateInstalledExtensionsSet()
24 scoped_ptr
<ExtensionSet
> installed_extensions(new ExtensionSet
);
25 installed_extensions
->InsertAll(enabled_extensions_
);
26 installed_extensions
->InsertAll(disabled_extensions_
);
27 installed_extensions
->InsertAll(terminated_extensions_
);
28 installed_extensions
->InsertAll(blacklisted_extensions_
);
29 return installed_extensions
.Pass();
32 void ExtensionRegistry::AddObserver(ExtensionRegistryObserver
* observer
) {
33 observers_
.AddObserver(observer
);
36 void ExtensionRegistry::RemoveObserver(ExtensionRegistryObserver
* observer
) {
37 observers_
.RemoveObserver(observer
);
40 void ExtensionRegistry::TriggerOnLoaded(const Extension
* extension
) {
41 DCHECK(enabled_extensions_
.Contains(extension
->id()));
42 FOR_EACH_OBSERVER(ExtensionRegistryObserver
,
44 OnExtensionLoaded(browser_context_
, extension
));
47 void ExtensionRegistry::TriggerOnUnloaded(const Extension
* extension
) {
48 DCHECK(!enabled_extensions_
.Contains(extension
->id()));
49 FOR_EACH_OBSERVER(ExtensionRegistryObserver
,
51 OnExtensionUnloaded(browser_context_
, extension
));
54 const Extension
* ExtensionRegistry::GetExtensionById(const std::string
& id
,
55 int include_mask
) const {
56 std::string lowercase_id
= StringToLowerASCII(id
);
57 if (include_mask
& ENABLED
) {
58 const Extension
* extension
= enabled_extensions_
.GetByID(lowercase_id
);
62 if (include_mask
& DISABLED
) {
63 const Extension
* extension
= disabled_extensions_
.GetByID(lowercase_id
);
67 if (include_mask
& TERMINATED
) {
68 const Extension
* extension
= terminated_extensions_
.GetByID(lowercase_id
);
72 if (include_mask
& BLACKLISTED
) {
73 const Extension
* extension
= blacklisted_extensions_
.GetByID(lowercase_id
);
80 bool ExtensionRegistry::AddEnabled(
81 const scoped_refptr
<const Extension
>& extension
) {
82 return enabled_extensions_
.Insert(extension
);
85 bool ExtensionRegistry::RemoveEnabled(const std::string
& id
) {
86 return enabled_extensions_
.Remove(id
);
89 bool ExtensionRegistry::AddDisabled(
90 const scoped_refptr
<const Extension
>& extension
) {
91 return disabled_extensions_
.Insert(extension
);
94 bool ExtensionRegistry::RemoveDisabled(const std::string
& id
) {
95 return disabled_extensions_
.Remove(id
);
98 bool ExtensionRegistry::AddTerminated(
99 const scoped_refptr
<const Extension
>& extension
) {
100 return terminated_extensions_
.Insert(extension
);
103 bool ExtensionRegistry::RemoveTerminated(const std::string
& id
) {
104 return terminated_extensions_
.Remove(id
);
107 bool ExtensionRegistry::AddBlacklisted(
108 const scoped_refptr
<const Extension
>& extension
) {
109 return blacklisted_extensions_
.Insert(extension
);
112 bool ExtensionRegistry::RemoveBlacklisted(const std::string
& id
) {
113 return blacklisted_extensions_
.Remove(id
);
116 void ExtensionRegistry::ClearAll() {
117 enabled_extensions_
.Clear();
118 disabled_extensions_
.Clear();
119 terminated_extensions_
.Clear();
120 blacklisted_extensions_
.Clear();
123 void ExtensionRegistry::SetDisabledModificationCallback(
124 const ExtensionSet::ModificationCallback
& callback
) {
125 disabled_extensions_
.set_modification_callback(callback
);
128 void ExtensionRegistry::Shutdown() {
129 // Release references to all Extension objects in the sets.
133 } // namespace extensions