OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
not at google - send to devlin
2015/08/17 20:43:05
2015, and in the .cc file.
annekao
2015/08/17 23:51:10
Done.
| |
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_COMMON_EXTENSION_SET_H_ | 5 #ifndef EXTENSIONS_RENDERER_RENDERER_EXTENSION_REGISTRY_H_ |
6 #define EXTENSIONS_COMMON_EXTENSION_SET_H_ | 6 #define EXTENSIONS_RENDERER_RENDERER_EXTENSION_REGISTRY_H_ |
7 | 7 |
8 #include <iterator> | 8 #include <iterator> |
9 #include <map> | 9 #include <map> |
not at google - send to devlin
2015/08/17 20:43:05
you can remove this <map> include.
annekao
2015/08/17 23:51:10
Done.
| |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
not at google - send to devlin
2015/08/17 20:43:05
and once you delete that modification method, you
annekao
2015/08/17 23:51:10
Done.
| |
13 #include "base/gtest_prod_util.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/memory/ref_counted.h" | |
15 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
15 #include "extensions/common/extension_set.h" | |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 | 19 |
20 // The one true extension container. Extensions are identified by their id. | 20 // Thread-safe extension container. Contains all loaded extensions. |
21 // This is essentially the renderer counterpart to ExtensionService in | |
22 // the browser. It contains information about all extensions currently | |
23 // loaded by the browser. All functions forward to ExtensionSet. | |
24 // Extensions are identified by their id. | |
not at google - send to devlin
2015/08/17 20:43:05
Let's trim down this comment as well, it's unneces
annekao
2015/08/17 23:51:10
Done.
| |
21 // Only one extension can be in the set with a given ID. | 25 // Only one extension can be in the set with a given ID. |
22 class ExtensionSet { | 26 class RendererExtensionRegistry { |
23 public: | 27 public: |
24 typedef std::pair<base::FilePath, std::string> ExtensionPathAndDefaultLocale; | 28 RendererExtensionRegistry(); |
25 typedef std::map<std::string, scoped_refptr<const Extension> > ExtensionMap; | 29 ~RendererExtensionRegistry(); |
26 typedef base::Callback<void(const ExtensionIdSet&)> | |
27 ModificationCallback; | |
28 | 30 |
29 // Iteration over the values of the map (given that it's an ExtensionSet, | 31 static RendererExtensionRegistry* GetRegistry(); |
not at google - send to devlin
2015/08/17 20:43:05
Typically singleton accessors are just "Get" not "
annekao
2015/08/17 23:51:10
Done.
| |
30 // it should iterate like a set iterator). | |
31 class const_iterator : public std::iterator<std::input_iterator_tag, | |
32 scoped_refptr<const Extension> > { | |
33 public: | |
34 const_iterator(); | |
35 const_iterator(const const_iterator& other); | |
36 explicit const_iterator(ExtensionMap::const_iterator it); | |
37 ~const_iterator(); | |
38 const_iterator& operator++() { | |
39 ++it_; | |
40 return *this; | |
41 } | |
42 const_iterator operator++(int) { | |
43 const const_iterator old(*this); | |
44 ++it_; | |
45 return old; | |
46 } | |
47 const scoped_refptr<const Extension>& operator*() const { | |
48 return it_->second; | |
49 } | |
50 const scoped_refptr<const Extension>* operator->() const { | |
51 return &it_->second; | |
52 } | |
53 bool operator!=(const const_iterator& other) const { | |
54 return it_ != other.it_; | |
55 } | |
56 bool operator==(const const_iterator& other) const { | |
57 return it_ == other.it_; | |
58 } | |
59 | 32 |
60 private: | 33 ExtensionSet* GetMainThreadExtensionSet(); |
61 ExtensionMap::const_iterator it_; | |
62 }; | |
63 | |
64 ExtensionSet(); | |
65 ~ExtensionSet(); | |
66 | 34 |
67 size_t size() const; | 35 size_t size() const; |
68 bool is_empty() const; | 36 bool is_empty() const; |
69 | 37 |
70 // Iteration support. | 38 // Iteration support. |
71 const_iterator begin() const { return const_iterator(extensions_.begin()); } | 39 ExtensionSet::const_iterator begin() const { return extensions_.begin(); } |
72 const_iterator end() const { return const_iterator(extensions_.end()); } | 40 ExtensionSet::const_iterator end() const { return extensions_.end(); } |
73 | 41 |
74 // Returns true if the set contains the specified extension. | 42 // Returns true if the set contains the specified extension. |
75 bool Contains(const std::string& id) const; | 43 bool Contains(const std::string& id) const; |
76 | 44 |
77 // Adds the specified extension to the set. The set becomes an owner. Any | 45 // Adds the specified extension to the set. The set becomes an owner. Any |
78 // previous extension with the same ID is removed. | 46 // previous extension with the same ID is removed. |
79 // Returns true if there is no previous extension. | 47 // Returns true if there is no previous extension. |
80 bool Insert(const scoped_refptr<const Extension>& extension); | 48 bool Insert(const scoped_refptr<const Extension>& extension); |
81 | 49 |
82 // Copies different items from |extensions| to the current set and returns | 50 // Copies different items from |extensions| to the current set and returns |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 | 91 |
124 // Gets the IDs of all extensions in the set. | 92 // Gets the IDs of all extensions in the set. |
125 ExtensionIdSet GetIDs() const; | 93 ExtensionIdSet GetIDs() const; |
126 | 94 |
127 // Returns true if |info| should get extension api bindings and be permitted | 95 // Returns true if |info| should get extension api bindings and be permitted |
128 // to make api calls. Note that this is independent of what extension | 96 // to make api calls. Note that this is independent of what extension |
129 // permissions the given extension has been granted. | 97 // permissions the given extension has been granted. |
130 bool ExtensionBindingsAllowed(const GURL& url) const; | 98 bool ExtensionBindingsAllowed(const GURL& url) const; |
131 | 99 |
132 void set_modification_callback( | 100 void set_modification_callback( |
133 const ModificationCallback& modification_callback) { | 101 const ExtensionSet::ModificationCallback& modification_callback) { |
134 modification_callback_ = modification_callback; | 102 modification_callback_ = modification_callback; |
135 } | 103 } |
136 | 104 |
137 private: | 105 private: |
138 FRIEND_TEST_ALL_PREFIXES(ExtensionSetTest, ExtensionSet); | 106 ExtensionSet extensions_; |
139 | 107 |
140 ExtensionMap extensions_; | 108 mutable base::Lock lock_; |
141 | 109 |
142 // If non-null, called with the extension ids in this set after a modification | 110 // If non-null, called with the extension ids in this set after a modification |
143 // occurred. This is not called on Clear() which is typically used when | 111 // occurred. This is not called on Clear() which is typically used when |
144 // discarding the set (e.g., on shutdown) and we do not want to track that as | 112 // discarding the set (e.g., on shutdown) and we do not want to track that as |
145 // a real modification. | 113 // a real modification. |
146 ModificationCallback modification_callback_; | 114 ExtensionSet::ModificationCallback modification_callback_; |
not at google - send to devlin
2015/08/17 20:43:05
Let's trim this interface a bit. Can we get rid of
annekao
2015/08/17 23:51:10
Done. Took out functions that weren't used in any
| |
147 | 115 |
148 DISALLOW_COPY_AND_ASSIGN(ExtensionSet); | 116 DISALLOW_COPY_AND_ASSIGN(RendererExtensionRegistry); |
149 }; | 117 }; |
150 | 118 |
151 } // namespace extensions | 119 } // namespace extensions |
152 | 120 |
153 #endif // EXTENSIONS_COMMON_EXTENSION_SET_H_ | 121 #endif // EXTENSIONS_RENDERER_RENDERER_EXTENSION_REGISTRY_H_ |
OLD | NEW |