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 #ifndef EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ |
6 #define EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 12 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
13 #include "extensions/common/extension_set.h" | 13 #include "extensions/common/extension_set.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 class BrowserContext; | 16 class BrowserContext; |
17 } | 17 } |
18 | 18 |
19 namespace extensions { | 19 namespace extensions { |
20 class Extension; | 20 class Extension; |
21 | 21 |
22 // ExtensionRegistry holds sets of the installed extensions for a given | 22 // ExtensionRegistry holds sets of the installed extensions for a given |
23 // BrowserContext. An incognito browser context and its master browser context | 23 // BrowserContext. An incognito browser context and its master browser context |
24 // share a single registry. | 24 // share a single registry. |
25 class ExtensionRegistry : public BrowserContextKeyedService { | 25 class ExtensionRegistry : public BrowserContextKeyedService { |
26 public: | 26 public: |
| 27 enum IncludeFlag { |
| 28 INCLUDE_NONE = 0, |
| 29 INCLUDE_ENABLED = 1 << 0, |
| 30 INCLUDE_DISABLED = 1 << 1, |
| 31 INCLUDE_TERMINATED = 1 << 2, |
| 32 INCLUDE_BLACKLISTED = 1 << 3, |
| 33 INCLUDE_EVERYTHING = (1 << 4) - 1, |
| 34 }; |
| 35 |
27 ExtensionRegistry(); | 36 ExtensionRegistry(); |
28 virtual ~ExtensionRegistry(); | 37 virtual ~ExtensionRegistry(); |
29 | 38 |
30 // Returns the instance for the given |browser_context|. | 39 // Returns the instance for the given |browser_context|. |
31 static ExtensionRegistry* Get(content::BrowserContext* browser_context); | 40 static ExtensionRegistry* Get(content::BrowserContext* browser_context); |
32 | 41 |
33 // NOTE: These sets are *eventually* mututally exclusive, but an extension can | 42 // NOTE: These sets are *eventually* mututally exclusive, but an extension can |
34 // appear in two sets for short periods of time. | 43 // appear in two sets for short periods of time. |
35 const ExtensionSet& enabled_extensions() const { | 44 const ExtensionSet& enabled_extensions() const { |
36 return enabled_extensions_; | 45 return enabled_extensions_; |
37 } | 46 } |
38 const ExtensionSet& disabled_extensions() const { | 47 const ExtensionSet& disabled_extensions() const { |
39 return disabled_extensions_; | 48 return disabled_extensions_; |
40 } | 49 } |
41 const ExtensionSet& terminated_extensions() const { | 50 const ExtensionSet& terminated_extensions() const { |
42 return terminated_extensions_; | 51 return terminated_extensions_; |
43 } | 52 } |
44 const ExtensionSet& blacklisted_extensions() const { | 53 const ExtensionSet& blacklisted_extensions() const { |
45 return blacklisted_extensions_; | 54 return blacklisted_extensions_; |
46 } | 55 } |
47 | 56 |
| 57 // Look up an extension by ID, selecting which sets to look in: |
| 58 // * enabled_extensions() --> INCLUDE_ENABLED |
| 59 // * disabled_extensions() --> INCLUDE_DISABLED |
| 60 // * terminated_extensions() --> INCLUDE_TERMINATED |
| 61 // * blacklisted_extensions() --> INCLUDE_BLACKLISTED |
| 62 const Extension* GetExtensionById(const std::string& id, |
| 63 int include_mask) const; |
| 64 |
48 // Adds the specified extension to the enabled set. The registry becomes an | 65 // Adds the specified extension to the enabled set. The registry becomes an |
49 // owner. Any previous extension with the same ID is removed. | 66 // owner. Any previous extension with the same ID is removed. |
50 // Returns true if there is no previous extension. | 67 // Returns true if there is no previous extension. |
51 // NOTE: You probably want to use ExtensionService instead of calling this | 68 // NOTE: You probably want to use ExtensionService instead of calling this |
52 // method directly. | 69 // method directly. |
53 bool AddEnabled(const scoped_refptr<const Extension>& extension); | 70 bool AddEnabled(const scoped_refptr<const Extension>& extension); |
54 | 71 |
55 // Removes the specified extension from the enabled set. | 72 // Removes the specified extension from the enabled set. |
56 // Returns true if the set contained the specified extension. | 73 // Returns true if the set contained the specified extension. |
57 // NOTE: You probably want to use ExtensionService instead of calling this | 74 // NOTE: You probably want to use ExtensionService instead of calling this |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // so that if extensions are blacklisted by mistake they can easily be | 114 // so that if extensions are blacklisted by mistake they can easily be |
98 // un-blacklisted. | 115 // un-blacklisted. |
99 ExtensionSet blacklisted_extensions_; | 116 ExtensionSet blacklisted_extensions_; |
100 | 117 |
101 DISALLOW_COPY_AND_ASSIGN(ExtensionRegistry); | 118 DISALLOW_COPY_AND_ASSIGN(ExtensionRegistry); |
102 }; | 119 }; |
103 | 120 |
104 } // namespace extensions | 121 } // namespace extensions |
105 | 122 |
106 #endif // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ | 123 #endif // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ |
OLD | NEW |