[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "extensions/browser/extension_registry.h" |
| 6 | |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame^] | 7 | #include "base/strings/string_util.h" |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 8 | #include "extensions/browser/extension_registry_factory.h" |
| 9 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 10 | namespace extensions { |
| 11 | |
| 12 | ExtensionRegistry::ExtensionRegistry() {} |
| 13 | ExtensionRegistry::~ExtensionRegistry() {} |
| 14 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 15 | // static |
| 16 | ExtensionRegistry* ExtensionRegistry::Get(content::BrowserContext* context) { |
| 17 | return ExtensionRegistryFactory::GetForBrowserContext(context); |
| 18 | } |
| 19 | |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame^] | 20 | const 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] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 46 | bool ExtensionRegistry::AddEnabled( |
| 47 | const scoped_refptr<const Extension>& extension) { |
| 48 | return enabled_extensions_.Insert(extension); |
| 49 | } |
| 50 | |
| 51 | bool ExtensionRegistry::RemoveEnabled(const std::string& id) { |
| 52 | return enabled_extensions_.Remove(id); |
| 53 | } |
| 54 | |
| 55 | bool ExtensionRegistry::AddDisabled( |
| 56 | const scoped_refptr<const Extension>& extension) { |
| 57 | return disabled_extensions_.Insert(extension); |
| 58 | } |
| 59 | |
| 60 | bool ExtensionRegistry::RemoveDisabled(const std::string& id) { |
| 61 | return disabled_extensions_.Remove(id); |
| 62 | } |
| 63 | |
| 64 | bool ExtensionRegistry::AddTerminated( |
| 65 | const scoped_refptr<const Extension>& extension) { |
| 66 | return terminated_extensions_.Insert(extension); |
| 67 | } |
| 68 | |
| 69 | bool ExtensionRegistry::RemoveTerminated(const std::string& id) { |
| 70 | return terminated_extensions_.Remove(id); |
| 71 | } |
| 72 | |
| 73 | bool ExtensionRegistry::AddBlacklisted( |
| 74 | const scoped_refptr<const Extension>& extension) { |
| 75 | return blacklisted_extensions_.Insert(extension); |
| 76 | } |
| 77 | |
| 78 | bool ExtensionRegistry::RemoveBlacklisted(const std::string& id) { |
| 79 | return blacklisted_extensions_.Remove(id); |
| 80 | } |
| 81 | |
| 82 | void ExtensionRegistry::ClearAll() { |
| 83 | enabled_extensions_.Clear(); |
| 84 | disabled_extensions_.Clear(); |
| 85 | terminated_extensions_.Clear(); |
| 86 | blacklisted_extensions_.Clear(); |
| 87 | } |
| 88 | |
| 89 | void ExtensionRegistry::SetDisabledModificationCallback( |
| 90 | const ExtensionSet::ModificationCallback& callback) { |
| 91 | disabled_extensions_.set_modification_callback(callback); |
| 92 | } |
| 93 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 94 | void ExtensionRegistry::Shutdown() { |
| 95 | // Release references to all Extension objects in the sets. |
| 96 | ClearAll(); |
| 97 | } |
| 98 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 99 | } // namespace extensions |