Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: extensions/browser/extension_registry.h

Issue 125573002: Move ExtensionService::GetExtensionById() to ExtensionRegistry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, add test, get_extension_by_id Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Flags to pass to GetExtensionById() to select which sets to look in.
28 enum IncludeFlag {
29 NONE = 0,
30 ENABLED = 1 << 0,
31 DISABLED = 1 << 1,
32 TERMINATED = 1 << 2,
33 BLACKLISTED = 1 << 3,
34 EVERYTHING = (1 << 4) - 1,
35 };
36
27 ExtensionRegistry(); 37 ExtensionRegistry();
28 virtual ~ExtensionRegistry(); 38 virtual ~ExtensionRegistry();
29 39
30 // Returns the instance for the given |browser_context|. 40 // Returns the instance for the given |browser_context|.
31 static ExtensionRegistry* Get(content::BrowserContext* browser_context); 41 static ExtensionRegistry* Get(content::BrowserContext* browser_context);
32 42
33 // NOTE: These sets are *eventually* mututally exclusive, but an extension can 43 // NOTE: These sets are *eventually* mututally exclusive, but an extension can
34 // appear in two sets for short periods of time. 44 // appear in two sets for short periods of time.
35 const ExtensionSet& enabled_extensions() const { 45 const ExtensionSet& enabled_extensions() const {
36 return enabled_extensions_; 46 return enabled_extensions_;
37 } 47 }
38 const ExtensionSet& disabled_extensions() const { 48 const ExtensionSet& disabled_extensions() const {
39 return disabled_extensions_; 49 return disabled_extensions_;
40 } 50 }
41 const ExtensionSet& terminated_extensions() const { 51 const ExtensionSet& terminated_extensions() const {
42 return terminated_extensions_; 52 return terminated_extensions_;
43 } 53 }
44 const ExtensionSet& blacklisted_extensions() const { 54 const ExtensionSet& blacklisted_extensions() const {
45 return blacklisted_extensions_; 55 return blacklisted_extensions_;
46 } 56 }
47 57
58 // Find an extension by ID using |include_mask| to pick the sets to search:
59 // * enabled_extensions() --> ExtensionRegistry::ENABLED
60 // * disabled_extensions() --> ExtensionRegistry::DISABLED
61 // * terminated_extensions() --> ExtensionRegistry::TERMINATED
62 // * blacklisted_extensions() --> ExtensionRegistry::BLACKLISTED
63 // Returns NULL if the extension is not found in the selected sets.
64 const Extension* GetExtensionById(const std::string& id,
65 int include_mask) const;
66
48 // Adds the specified extension to the enabled set. The registry becomes an 67 // Adds the specified extension to the enabled set. The registry becomes an
49 // owner. Any previous extension with the same ID is removed. 68 // owner. Any previous extension with the same ID is removed.
50 // Returns true if there is no previous extension. 69 // Returns true if there is no previous extension.
51 // NOTE: You probably want to use ExtensionService instead of calling this 70 // NOTE: You probably want to use ExtensionService instead of calling this
52 // method directly. 71 // method directly.
53 bool AddEnabled(const scoped_refptr<const Extension>& extension); 72 bool AddEnabled(const scoped_refptr<const Extension>& extension);
54 73
55 // Removes the specified extension from the enabled set. 74 // Removes the specified extension from the enabled set.
56 // Returns true if the set contained the specified extension. 75 // Returns true if the set contained the specified extension.
57 // NOTE: You probably want to use ExtensionService instead of calling this 76 // NOTE: You probably want to use ExtensionService instead of calling this
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // so that if extensions are blacklisted by mistake they can easily be 116 // so that if extensions are blacklisted by mistake they can easily be
98 // un-blacklisted. 117 // un-blacklisted.
99 ExtensionSet blacklisted_extensions_; 118 ExtensionSet blacklisted_extensions_;
100 119
101 DISALLOW_COPY_AND_ASSIGN(ExtensionRegistry); 120 DISALLOW_COPY_AND_ASSIGN(ExtensionRegistry);
102 }; 121 };
103 122
104 } // namespace extensions 123 } // namespace extensions
105 124
106 #endif // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_ 125 #endif // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/extensions/application_launch.cc ('k') | extensions/browser/extension_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698