blob: bc5247cdce2002d9cadaf121809d15f0bcbc8e59 [file] [log] [blame]
[email protected]bb1bc9b32013-12-21 03:09:141// 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.
4
5#include "extensions/browser/extension_registry.h"
6
[email protected]599539802014-01-07 23:06:007#include "base/strings/string_util.h"
[email protected]5fdfa562013-12-27 17:43:598#include "extensions/browser/extension_registry_factory.h"
9
[email protected]bb1bc9b32013-12-21 03:09:1410namespace extensions {
11
12ExtensionRegistry::ExtensionRegistry() {}
13ExtensionRegistry::~ExtensionRegistry() {}
14
[email protected]5fdfa562013-12-27 17:43:5915// static
16ExtensionRegistry* ExtensionRegistry::Get(content::BrowserContext* context) {
17 return ExtensionRegistryFactory::GetForBrowserContext(context);
18}
19
[email protected]599539802014-01-07 23:06:0020const Extension* ExtensionRegistry::GetExtensionById(const std::string& id,
21 int include_mask) const {
22 std::string lowercase_id = StringToLowerASCII(id);
23 if (include_mask & ENABLED) {
24 const Extension* extension = enabled_extensions_.GetByID(lowercase_id);
25 if (extension)
26 return extension;
27 }
28 if (include_mask & DISABLED) {
29 const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
30 if (extension)
31 return extension;
32 }
33 if (include_mask & TERMINATED) {
34 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
35 if (extension)
36 return extension;
37 }
38 if (include_mask & BLACKLISTED) {
39 const Extension* extension = blacklisted_extensions_.GetByID(lowercase_id);
40 if (extension)
41 return extension;
42 }
43 return NULL;
44}
45
[email protected]bb1bc9b32013-12-21 03:09:1446bool ExtensionRegistry::AddEnabled(
47 const scoped_refptr<const Extension>& extension) {
48 return enabled_extensions_.Insert(extension);
49}
50
51bool ExtensionRegistry::RemoveEnabled(const std::string& id) {
52 return enabled_extensions_.Remove(id);
53}
54
55bool ExtensionRegistry::AddDisabled(
56 const scoped_refptr<const Extension>& extension) {
57 return disabled_extensions_.Insert(extension);
58}
59
60bool ExtensionRegistry::RemoveDisabled(const std::string& id) {
61 return disabled_extensions_.Remove(id);
62}
63
64bool ExtensionRegistry::AddTerminated(
65 const scoped_refptr<const Extension>& extension) {
66 return terminated_extensions_.Insert(extension);
67}
68
69bool ExtensionRegistry::RemoveTerminated(const std::string& id) {
70 return terminated_extensions_.Remove(id);
71}
72
73bool ExtensionRegistry::AddBlacklisted(
74 const scoped_refptr<const Extension>& extension) {
75 return blacklisted_extensions_.Insert(extension);
76}
77
78bool ExtensionRegistry::RemoveBlacklisted(const std::string& id) {
79 return blacklisted_extensions_.Remove(id);
80}
81
82void ExtensionRegistry::ClearAll() {
83 enabled_extensions_.Clear();
84 disabled_extensions_.Clear();
85 terminated_extensions_.Clear();
86 blacklisted_extensions_.Clear();
87}
88
89void ExtensionRegistry::SetDisabledModificationCallback(
90 const ExtensionSet::ModificationCallback& callback) {
91 disabled_extensions_.set_modification_callback(callback);
92}
93
[email protected]5fdfa562013-12-27 17:43:5994void ExtensionRegistry::Shutdown() {
95 // Release references to all Extension objects in the sets.
96 ClearAll();
97}
98
[email protected]bb1bc9b32013-12-21 03:09:1499} // namespace extensions