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 bool Set(const std::string& extension_id, int api_resource_id, T* resource) { |
| 137 return data_->Set(extension_id, api_resource_id, resource); |
| 138 } |
| 139 |
136 protected: | 140 protected: |
137 // content::NotificationObserver: | 141 // content::NotificationObserver: |
138 virtual void Observe(int type, | 142 virtual void Observe(int type, |
139 const content::NotificationSource& source, | 143 const content::NotificationSource& source, |
140 const content::NotificationDetails& details) OVERRIDE { | 144 const content::NotificationDetails& details) OVERRIDE { |
141 switch (type) { | 145 switch (type) { |
142 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 146 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
143 std::string id = | 147 std::string id = |
144 content::Details<extensions::UnloadedExtensionInfo>(details)-> | 148 content::Details<extensions::UnloadedExtensionInfo>(details)-> |
145 extension->id(); | 149 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); | 211 extension_resource_map_[extension_id].erase(api_resource_id); |
208 api_resource_map_.erase(api_resource_id); | 212 api_resource_map_.erase(api_resource_id); |
209 } | 213 } |
210 } | 214 } |
211 | 215 |
212 T* Get(const std::string& extension_id, int api_resource_id) { | 216 T* Get(const std::string& extension_id, int api_resource_id) { |
213 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); | 217 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); |
214 return GetOwnedResource(extension_id, api_resource_id); | 218 return GetOwnedResource(extension_id, api_resource_id); |
215 } | 219 } |
216 | 220 |
| 221 bool Set(const std::string& extension_id, int api_resource_id, |
| 222 T* api_resource) { |
| 223 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); |
| 224 T* old_resource = api_resource_map_[api_resource_id].get(); |
| 225 if (old_resource && extension_id == old_resource->owner_extension_id()) { |
| 226 api_resource_map_[api_resource_id] = linked_ptr<T>(api_resource); |
| 227 return true; |
| 228 } else { |
| 229 return false; |
| 230 } |
| 231 } |
| 232 |
| 233 |
217 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { | 234 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { |
218 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); | 235 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); |
219 return GetOwnedResourceIds(extension_id); | 236 return GetOwnedResourceIds(extension_id); |
220 } | 237 } |
221 | 238 |
222 void InitiateExtensionUnloadedCleanup(const std::string& extension_id) { | 239 void InitiateExtensionUnloadedCleanup(const std::string& extension_id) { |
223 content::BrowserThread::PostTask(thread_id_, FROM_HERE, | 240 content::BrowserThread::PostTask(thread_id_, FROM_HERE, |
224 base::Bind(&ApiResourceData::CleanupResourcesFromUnloadedExtension, | 241 base::Bind(&ApiResourceData::CleanupResourcesFromUnloadedExtension, |
225 this, extension_id)); | 242 this, extension_id)); |
226 } | 243 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 }; | 342 }; |
326 | 343 |
327 content::BrowserThread::ID thread_id_; | 344 content::BrowserThread::ID thread_id_; |
328 content::NotificationRegistrar registrar_; | 345 content::NotificationRegistrar registrar_; |
329 scoped_refptr<ApiResourceData> data_; | 346 scoped_refptr<ApiResourceData> data_; |
330 }; | 347 }; |
331 | 348 |
332 } // namespace extensions | 349 } // namespace extensions |
333 | 350 |
334 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ | 351 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ |
OLD | NEW |