OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_API_API_RESOURCE_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ |
6 #define EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 122 } |
123 | 123 |
124 T* Get(const std::string& extension_id, int api_resource_id) { | 124 T* Get(const std::string& extension_id, int api_resource_id) { |
125 return data_->Get(extension_id, api_resource_id); | 125 return data_->Get(extension_id, api_resource_id); |
126 } | 126 } |
127 | 127 |
128 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { | 128 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { |
129 return data_->GetResourceIds(extension_id); | 129 return data_->GetResourceIds(extension_id); |
130 } | 130 } |
131 | 131 |
| 132 // Change the resource mapped to this |extension_id| at this |
| 133 // |api_resource_id| to |resource|. Returns true and succeeds unless |
| 134 // |api_resource_id| does not already identify a resource held by |
| 135 // |extension_id|. |
| 136 bool Replace(const std::string& extension_id, |
| 137 int api_resource_id, |
| 138 T* resource) { |
| 139 return data_->Replace(extension_id, api_resource_id, resource); |
| 140 } |
| 141 |
132 protected: | 142 protected: |
133 // content::NotificationObserver: | 143 // content::NotificationObserver: |
134 virtual void Observe(int type, | 144 virtual void Observe(int type, |
135 const content::NotificationSource& source, | 145 const content::NotificationSource& source, |
136 const content::NotificationDetails& details) OVERRIDE { | 146 const content::NotificationDetails& details) OVERRIDE { |
137 switch (type) { | 147 switch (type) { |
138 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 148 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
139 std::string id = content::Details<extensions::UnloadedExtensionInfo>( | 149 std::string id = content::Details<extensions::UnloadedExtensionInfo>( |
140 details)->extension->id(); | 150 details)->extension->id(); |
141 data_->InitiateExtensionUnloadedCleanup(id); | 151 data_->InitiateExtensionUnloadedCleanup(id); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 extension_resource_map_[extension_id].erase(api_resource_id); | 212 extension_resource_map_[extension_id].erase(api_resource_id); |
203 api_resource_map_.erase(api_resource_id); | 213 api_resource_map_.erase(api_resource_id); |
204 } | 214 } |
205 } | 215 } |
206 | 216 |
207 T* Get(const std::string& extension_id, int api_resource_id) { | 217 T* Get(const std::string& extension_id, int api_resource_id) { |
208 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); | 218 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); |
209 return GetOwnedResource(extension_id, api_resource_id); | 219 return GetOwnedResource(extension_id, api_resource_id); |
210 } | 220 } |
211 | 221 |
| 222 // Change the resource mapped to this |extension_id| at this |
| 223 // |api_resource_id| to |resource|. Returns true and succeeds unless |
| 224 // |api_resource_id| does not already identify a resource held by |
| 225 // |extension_id|. |
| 226 bool Replace(const std::string& extension_id, |
| 227 int api_resource_id, |
| 228 T* api_resource) { |
| 229 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); |
| 230 T* old_resource = api_resource_map_[api_resource_id].get(); |
| 231 if (old_resource && extension_id == old_resource->owner_extension_id()) { |
| 232 api_resource_map_[api_resource_id] = linked_ptr<T>(api_resource); |
| 233 return true; |
| 234 } |
| 235 return false; |
| 236 } |
| 237 |
212 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { | 238 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { |
213 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); | 239 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); |
214 return GetOwnedResourceIds(extension_id); | 240 return GetOwnedResourceIds(extension_id); |
215 } | 241 } |
216 | 242 |
217 void InitiateExtensionUnloadedCleanup(const std::string& extension_id) { | 243 void InitiateExtensionUnloadedCleanup(const std::string& extension_id) { |
218 content::BrowserThread::PostTask( | 244 content::BrowserThread::PostTask( |
219 thread_id_, | 245 thread_id_, |
220 FROM_HERE, | 246 FROM_HERE, |
221 base::Bind(&ApiResourceData::CleanupResourcesFromUnloadedExtension, | 247 base::Bind(&ApiResourceData::CleanupResourcesFromUnloadedExtension, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 }; | 348 }; |
323 | 349 |
324 content::BrowserThread::ID thread_id_; | 350 content::BrowserThread::ID thread_id_; |
325 content::NotificationRegistrar registrar_; | 351 content::NotificationRegistrar registrar_; |
326 scoped_refptr<ApiResourceData> data_; | 352 scoped_refptr<ApiResourceData> data_; |
327 }; | 353 }; |
328 | 354 |
329 } // namespace extensions | 355 } // namespace extensions |
330 | 356 |
331 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ | 357 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ |
OLD | NEW |