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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 124 } |
125 | 125 |
126 T* Get(const std::string& extension_id, int api_resource_id) { | 126 T* Get(const std::string& extension_id, int api_resource_id) { |
127 return data_->Get(extension_id, api_resource_id); | 127 return data_->Get(extension_id, api_resource_id); |
128 } | 128 } |
129 | 129 |
130 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { | 130 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { |
131 return data_->GetResourceIds(extension_id); | 131 return data_->GetResourceIds(extension_id); |
132 } | 132 } |
133 | 133 |
| 134 // Change the resource mapped to this |extension_id| at this |
| 135 // |api_resource_id| to |resource|. Returns true and succeeds unless |
| 136 // |api_resource_id| does not already identify a resource held by |
| 137 // |extension_id|. |
| 138 bool Replace(const std::string& extension_id, |
| 139 int api_resource_id, |
| 140 T* resource) { |
| 141 return data_->Replace(extension_id, api_resource_id, resource); |
| 142 } |
| 143 |
134 protected: | 144 protected: |
135 // content::NotificationObserver: | 145 // content::NotificationObserver: |
136 virtual void Observe(int type, | 146 virtual void Observe(int type, |
137 const content::NotificationSource& source, | 147 const content::NotificationSource& source, |
138 const content::NotificationDetails& details) OVERRIDE { | 148 const content::NotificationDetails& details) OVERRIDE { |
139 switch (type) { | 149 switch (type) { |
140 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 150 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
141 std::string id = content::Details<extensions::UnloadedExtensionInfo>( | 151 std::string id = content::Details<extensions::UnloadedExtensionInfo>( |
142 details)->extension->id(); | 152 details)->extension->id(); |
143 data_->InitiateExtensionUnloadedCleanup(id); | 153 data_->InitiateExtensionUnloadedCleanup(id); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 extension_resource_map_[extension_id].erase(api_resource_id); | 217 extension_resource_map_[extension_id].erase(api_resource_id); |
208 api_resource_map_.erase(api_resource_id); | 218 api_resource_map_.erase(api_resource_id); |
209 } | 219 } |
210 } | 220 } |
211 | 221 |
212 T* Get(const std::string& extension_id, int api_resource_id) { | 222 T* Get(const std::string& extension_id, int api_resource_id) { |
213 DCHECK_CURRENTLY_ON(thread_id_); | 223 DCHECK_CURRENTLY_ON(thread_id_); |
214 return GetOwnedResource(extension_id, api_resource_id); | 224 return GetOwnedResource(extension_id, api_resource_id); |
215 } | 225 } |
216 | 226 |
| 227 // Change the resource mapped to this |extension_id| at this |
| 228 // |api_resource_id| to |resource|. Returns true and succeeds unless |
| 229 // |api_resource_id| does not already identify a resource held by |
| 230 // |extension_id|. |
| 231 bool Replace(const std::string& extension_id, |
| 232 int api_resource_id, |
| 233 T* api_resource) { |
| 234 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); |
| 235 T* old_resource = api_resource_map_[api_resource_id].get(); |
| 236 if (old_resource && extension_id == old_resource->owner_extension_id()) { |
| 237 api_resource_map_[api_resource_id] = linked_ptr<T>(api_resource); |
| 238 return true; |
| 239 } |
| 240 return false; |
| 241 } |
| 242 |
217 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { | 243 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { |
218 DCHECK_CURRENTLY_ON(thread_id_); | 244 DCHECK_CURRENTLY_ON(thread_id_); |
219 return GetOwnedResourceIds(extension_id); | 245 return GetOwnedResourceIds(extension_id); |
220 } | 246 } |
221 | 247 |
222 void InitiateExtensionUnloadedCleanup(const std::string& extension_id) { | 248 void InitiateExtensionUnloadedCleanup(const std::string& extension_id) { |
223 if (content::BrowserThread::CurrentlyOn(thread_id_)) { | 249 if (content::BrowserThread::CurrentlyOn(thread_id_)) { |
224 CleanupResourcesFromUnloadedExtension(extension_id); | 250 CleanupResourcesFromUnloadedExtension(extension_id); |
225 } else { | 251 } else { |
226 content::BrowserThread::PostTask( | 252 content::BrowserThread::PostTask( |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 }; | 365 }; |
340 | 366 |
341 content::BrowserThread::ID thread_id_; | 367 content::BrowserThread::ID thread_id_; |
342 content::NotificationRegistrar registrar_; | 368 content::NotificationRegistrar registrar_; |
343 scoped_refptr<ApiResourceData> data_; | 369 scoped_refptr<ApiResourceData> data_; |
344 }; | 370 }; |
345 | 371 |
346 } // namespace extensions | 372 } // namespace extensions |
347 | 373 |
348 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ | 374 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ |
OLD | NEW |