| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // template <> | 67 // template <> |
| 68 // ProfileKeyedAPIFactory<ApiResourceManager<Resource> >* | 68 // ProfileKeyedAPIFactory<ApiResourceManager<Resource> >* |
| 69 // ApiResourceManager<Resource>::GetFactoryInstance() { | 69 // ApiResourceManager<Resource>::GetFactoryInstance() { |
| 70 // return g_factory.Pointer(); | 70 // return g_factory.Pointer(); |
| 71 // } | 71 // } |
| 72 template <class T> | 72 template <class T> |
| 73 class ApiResourceManager : public ProfileKeyedAPI, | 73 class ApiResourceManager : public ProfileKeyedAPI, |
| 74 public base::NonThreadSafe, | 74 public base::NonThreadSafe, |
| 75 public content::NotificationObserver { | 75 public content::NotificationObserver { |
| 76 public: | 76 public: |
| 77 explicit ApiResourceManager(Profile* profile) | 77 explicit ApiResourceManager(content::BrowserContext* context) |
| 78 : thread_id_(T::kThreadId), | 78 : thread_id_(T::kThreadId), data_(new ApiResourceData(thread_id_)) { |
| 79 data_(new ApiResourceData(thread_id_)) { | |
| 80 registrar_.Add( | 79 registrar_.Add( |
| 81 this, | 80 this, |
| 82 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 81 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 83 content::NotificationService::AllSources()); | 82 content::NotificationService::AllSources()); |
| 84 registrar_.Add( | 83 registrar_.Add( |
| 85 this, | 84 this, |
| 86 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 85 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 87 content::NotificationService::AllSources()); | 86 content::NotificationService::AllSources()); |
| 88 } | 87 } |
| 89 | 88 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 104 "the thread message loop needed for that kind of resource. " | 103 "the thread message loop needed for that kind of resource. " |
| 105 "Please ensure that the appropriate message loop is operational."; | 104 "Please ensure that the appropriate message loop is operational."; |
| 106 | 105 |
| 107 data_->InititateCleanup(); | 106 data_->InititateCleanup(); |
| 108 } | 107 } |
| 109 | 108 |
| 110 // ProfileKeyedAPI implementation. | 109 // ProfileKeyedAPI implementation. |
| 111 static ProfileKeyedAPIFactory<ApiResourceManager<T> >* GetFactoryInstance(); | 110 static ProfileKeyedAPIFactory<ApiResourceManager<T> >* GetFactoryInstance(); |
| 112 | 111 |
| 113 // Convenience method to get the ApiResourceManager for a profile. | 112 // Convenience method to get the ApiResourceManager for a profile. |
| 114 static ApiResourceManager<T>* Get(Profile* profile) { | 113 static ApiResourceManager<T>* Get(content::BrowserContext* context) { |
| 115 return ProfileKeyedAPIFactory<ApiResourceManager<T> >::GetForProfile( | 114 return ProfileKeyedAPIFactory<ApiResourceManager<T> >::GetForProfile( |
| 116 profile); | 115 context); |
| 117 } | 116 } |
| 118 | 117 |
| 119 // Takes ownership. | 118 // Takes ownership. |
| 120 int Add(T* api_resource) { | 119 int Add(T* api_resource) { |
| 121 return data_->Add(api_resource); | 120 return data_->Add(api_resource); |
| 122 } | 121 } |
| 123 | 122 |
| 124 void Remove(const std::string& extension_id, int api_resource_id) { | 123 void Remove(const std::string& extension_id, int api_resource_id) { |
| 125 data_->Remove(extension_id, api_resource_id); | 124 data_->Remove(extension_id, api_resource_id); |
| 126 } | 125 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 }; | 324 }; |
| 326 | 325 |
| 327 content::BrowserThread::ID thread_id_; | 326 content::BrowserThread::ID thread_id_; |
| 328 content::NotificationRegistrar registrar_; | 327 content::NotificationRegistrar registrar_; |
| 329 scoped_refptr<ApiResourceData> data_; | 328 scoped_refptr<ApiResourceData> data_; |
| 330 }; | 329 }; |
| 331 | 330 |
| 332 } // namespace extensions | 331 } // namespace extensions |
| 333 | 332 |
| 334 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ | 333 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ |
| OLD | NEW |