OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/extension_registry.h" | 5 #include "extensions/browser/extension_registry.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "extensions/browser/extension_registry_factory.h" | 8 #include "extensions/browser/extension_registry_factory.h" |
9 #include "extensions/browser/extension_registry_observer.h" | 9 #include "extensions/browser/extension_registry_observer.h" |
10 | 10 |
11 namespace extensions { | 11 namespace extensions { |
12 | 12 |
13 ExtensionRegistry::ExtensionRegistry() {} | 13 ExtensionRegistry::ExtensionRegistry(content::BrowserContext* browser_context) |
| 14 : browser_context_(browser_context) {} |
14 ExtensionRegistry::~ExtensionRegistry() {} | 15 ExtensionRegistry::~ExtensionRegistry() {} |
15 | 16 |
16 // static | 17 // static |
17 ExtensionRegistry* ExtensionRegistry::Get(content::BrowserContext* context) { | 18 ExtensionRegistry* ExtensionRegistry::Get(content::BrowserContext* context) { |
18 return ExtensionRegistryFactory::GetForBrowserContext(context); | 19 return ExtensionRegistryFactory::GetForBrowserContext(context); |
19 } | 20 } |
20 | 21 |
21 scoped_ptr<ExtensionSet> ExtensionRegistry::GenerateInstalledExtensionsSet() | 22 scoped_ptr<ExtensionSet> ExtensionRegistry::GenerateInstalledExtensionsSet() |
22 const { | 23 const { |
23 scoped_ptr<ExtensionSet> installed_extensions(new ExtensionSet); | 24 scoped_ptr<ExtensionSet> installed_extensions(new ExtensionSet); |
24 installed_extensions->InsertAll(enabled_extensions_); | 25 installed_extensions->InsertAll(enabled_extensions_); |
25 installed_extensions->InsertAll(disabled_extensions_); | 26 installed_extensions->InsertAll(disabled_extensions_); |
26 installed_extensions->InsertAll(terminated_extensions_); | 27 installed_extensions->InsertAll(terminated_extensions_); |
27 installed_extensions->InsertAll(blacklisted_extensions_); | 28 installed_extensions->InsertAll(blacklisted_extensions_); |
28 return installed_extensions.Pass(); | 29 return installed_extensions.Pass(); |
29 } | 30 } |
30 | 31 |
31 void ExtensionRegistry::AddObserver(ExtensionRegistryObserver* observer) { | 32 void ExtensionRegistry::AddObserver(ExtensionRegistryObserver* observer) { |
32 observers_.AddObserver(observer); | 33 observers_.AddObserver(observer); |
33 } | 34 } |
34 | 35 |
35 void ExtensionRegistry::RemoveObserver(ExtensionRegistryObserver* observer) { | 36 void ExtensionRegistry::RemoveObserver(ExtensionRegistryObserver* observer) { |
36 observers_.RemoveObserver(observer); | 37 observers_.RemoveObserver(observer); |
37 } | 38 } |
38 | 39 |
39 void ExtensionRegistry::TriggerOnLoaded(const Extension* extension) { | 40 void ExtensionRegistry::TriggerOnLoaded(const Extension* extension) { |
40 DCHECK(enabled_extensions_.Contains(extension->id())); | 41 DCHECK(enabled_extensions_.Contains(extension->id())); |
41 FOR_EACH_OBSERVER( | 42 FOR_EACH_OBSERVER(ExtensionRegistryObserver, |
42 ExtensionRegistryObserver, observers_, OnExtensionLoaded(extension)); | 43 observers_, |
| 44 OnExtensionLoaded(browser_context_, extension)); |
43 } | 45 } |
44 | 46 |
45 void ExtensionRegistry::TriggerOnUnloaded(const Extension* extension) { | 47 void ExtensionRegistry::TriggerOnUnloaded(const Extension* extension) { |
46 DCHECK(!enabled_extensions_.Contains(extension->id())); | 48 DCHECK(!enabled_extensions_.Contains(extension->id())); |
47 FOR_EACH_OBSERVER( | 49 FOR_EACH_OBSERVER(ExtensionRegistryObserver, |
48 ExtensionRegistryObserver, observers_, OnExtensionUnloaded(extension)); | 50 observers_, |
| 51 OnExtensionUnloaded(browser_context_, extension)); |
49 } | 52 } |
50 | 53 |
51 const Extension* ExtensionRegistry::GetExtensionById(const std::string& id, | 54 const Extension* ExtensionRegistry::GetExtensionById(const std::string& id, |
52 int include_mask) const { | 55 int include_mask) const { |
53 std::string lowercase_id = StringToLowerASCII(id); | 56 std::string lowercase_id = StringToLowerASCII(id); |
54 if (include_mask & ENABLED) { | 57 if (include_mask & ENABLED) { |
55 const Extension* extension = enabled_extensions_.GetByID(lowercase_id); | 58 const Extension* extension = enabled_extensions_.GetByID(lowercase_id); |
56 if (extension) | 59 if (extension) |
57 return extension; | 60 return extension; |
58 } | 61 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 const ExtensionSet::ModificationCallback& callback) { | 124 const ExtensionSet::ModificationCallback& callback) { |
122 disabled_extensions_.set_modification_callback(callback); | 125 disabled_extensions_.set_modification_callback(callback); |
123 } | 126 } |
124 | 127 |
125 void ExtensionRegistry::Shutdown() { | 128 void ExtensionRegistry::Shutdown() { |
126 // Release references to all Extension objects in the sets. | 129 // Release references to all Extension objects in the sets. |
127 ClearAll(); | 130 ClearAll(); |
128 } | 131 } |
129 | 132 |
130 } // namespace extensions | 133 } // namespace extensions |
OLD | NEW |