OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 126 } |
127 | 127 |
128 T* Get(const std::string& extension_id, int api_resource_id) { | 128 T* Get(const std::string& extension_id, int api_resource_id) { |
129 return data_->Get(extension_id, api_resource_id); | 129 return data_->Get(extension_id, api_resource_id); |
130 } | 130 } |
131 | 131 |
132 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { | 132 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { |
133 return data_->GetResourceIds(extension_id); | 133 return data_->GetResourceIds(extension_id); |
134 } | 134 } |
135 | 135 |
| 136 // Change the resource mapped to this |extension_id| at this |
| 137 // |api_resource_id| to |resource|. Returns true and succeeds unless |
| 138 // |api_resource_id| does not already identify a resource held by |
| 139 // |extension_id|. |
| 140 bool Replace(const std::string& extension_id, |
| 141 int api_resource_id, |
| 142 T* resource) { |
| 143 return data_->Replace(extension_id, api_resource_id, resource); |
| 144 } |
| 145 |
136 protected: | 146 protected: |
137 // content::NotificationObserver: | 147 // content::NotificationObserver: |
138 virtual void Observe(int type, | 148 virtual void Observe(int type, |
139 const content::NotificationSource& source, | 149 const content::NotificationSource& source, |
140 const content::NotificationDetails& details) OVERRIDE { | 150 const content::NotificationDetails& details) OVERRIDE { |
141 switch (type) { | 151 switch (type) { |
142 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 152 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
143 std::string id = | 153 std::string id = |
144 content::Details<extensions::UnloadedExtensionInfo>(details)-> | 154 content::Details<extensions::UnloadedExtensionInfo>(details)-> |
145 extension->id(); | 155 extension->id(); |
(...skipping 61 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(content::BrowserThread::CurrentlyOn(thread_id_)); | 223 DCHECK(content::BrowserThread::CurrentlyOn(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(content::BrowserThread::CurrentlyOn(thread_id_)); | 244 DCHECK(content::BrowserThread::CurrentlyOn(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 content::BrowserThread::PostTask(thread_id_, FROM_HERE, | 249 content::BrowserThread::PostTask(thread_id_, FROM_HERE, |
224 base::Bind(&ApiResourceData::CleanupResourcesFromUnloadedExtension, | 250 base::Bind(&ApiResourceData::CleanupResourcesFromUnloadedExtension, |
225 this, extension_id)); | 251 this, extension_id)); |
226 } | 252 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 }; | 351 }; |
326 | 352 |
327 content::BrowserThread::ID thread_id_; | 353 content::BrowserThread::ID thread_id_; |
328 content::NotificationRegistrar registrar_; | 354 content::NotificationRegistrar registrar_; |
329 scoped_refptr<ApiResourceData> data_; | 355 scoped_refptr<ApiResourceData> data_; |
330 }; | 356 }; |
331 | 357 |
332 } // namespace extensions | 358 } // namespace extensions |
333 | 359 |
334 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ | 360 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ |
OLD | NEW |