| 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" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | |
| 16 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
| 17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 21 #include "extensions/browser/browser_context_keyed_api_factory.h" | 20 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 22 #include "extensions/browser/extension_host.h" | 21 #include "extensions/browser/extension_host.h" |
| 22 #include "extensions/browser/notification_types.h" |
| 23 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 | 26 |
| 27 namespace api { | 27 namespace api { |
| 28 class BluetoothSocketApiFunction; | 28 class BluetoothSocketApiFunction; |
| 29 class BluetoothSocketEventDispatcher; | 29 class BluetoothSocketEventDispatcher; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace core_api { | 32 namespace core_api { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // return g_factory.Pointer(); | 110 // return g_factory.Pointer(); |
| 111 // } | 111 // } |
| 112 template <class T, typename ThreadingTraits = NamedThreadTraits<T> > | 112 template <class T, typename ThreadingTraits = NamedThreadTraits<T> > |
| 113 class ApiResourceManager : public BrowserContextKeyedAPI, | 113 class ApiResourceManager : public BrowserContextKeyedAPI, |
| 114 public base::NonThreadSafe, | 114 public base::NonThreadSafe, |
| 115 public content::NotificationObserver { | 115 public content::NotificationObserver { |
| 116 public: | 116 public: |
| 117 explicit ApiResourceManager(content::BrowserContext* context) | 117 explicit ApiResourceManager(content::BrowserContext* context) |
| 118 : data_(new ApiResourceData()) { | 118 : data_(new ApiResourceData()) { |
| 119 registrar_.Add(this, | 119 registrar_.Add(this, |
| 120 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 120 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| 121 content::NotificationService::AllSources()); | 121 content::NotificationService::AllSources()); |
| 122 registrar_.Add(this, | 122 registrar_.Add(this, |
| 123 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 123 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 124 content::NotificationService::AllSources()); | 124 content::NotificationService::AllSources()); |
| 125 } | 125 } |
| 126 // For Testing. | 126 // For Testing. |
| 127 static ApiResourceManager<T, TestThreadTraits<T> >* | 127 static ApiResourceManager<T, TestThreadTraits<T> >* |
| 128 CreateApiResourceManagerForTest(content::BrowserContext* context, | 128 CreateApiResourceManagerForTest(content::BrowserContext* context, |
| 129 content::BrowserThread::ID thread_id) { | 129 content::BrowserThread::ID thread_id) { |
| 130 TestThreadTraits<T>::thread_id_ = thread_id; | 130 TestThreadTraits<T>::thread_id_ = thread_id; |
| 131 ApiResourceManager<T, TestThreadTraits<T> >* manager = | 131 ApiResourceManager<T, TestThreadTraits<T> >* manager = |
| 132 new ApiResourceManager<T, TestThreadTraits<T> >(context); | 132 new ApiResourceManager<T, TestThreadTraits<T> >(context); |
| 133 return manager; | 133 return manager; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 T* resource) { | 179 T* resource) { |
| 180 return data_->Replace(extension_id, api_resource_id, resource); | 180 return data_->Replace(extension_id, api_resource_id, resource); |
| 181 } | 181 } |
| 182 | 182 |
| 183 protected: | 183 protected: |
| 184 // content::NotificationObserver: | 184 // content::NotificationObserver: |
| 185 virtual void Observe(int type, | 185 virtual void Observe(int type, |
| 186 const content::NotificationSource& source, | 186 const content::NotificationSource& source, |
| 187 const content::NotificationDetails& details) OVERRIDE { | 187 const content::NotificationDetails& details) OVERRIDE { |
| 188 switch (type) { | 188 switch (type) { |
| 189 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 189 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
| 190 std::string id = content::Details<extensions::UnloadedExtensionInfo>( | 190 std::string id = content::Details<extensions::UnloadedExtensionInfo>( |
| 191 details)->extension->id(); | 191 details)->extension->id(); |
| 192 data_->InitiateExtensionUnloadedCleanup(id); | 192 data_->InitiateExtensionUnloadedCleanup(id); |
| 193 break; | 193 break; |
| 194 } | 194 } |
| 195 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 195 case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
| 196 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 196 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 197 data_->InitiateExtensionSuspendedCleanup(host->extension_id()); | 197 data_->InitiateExtensionSuspendedCleanup(host->extension_id()); |
| 198 break; | 198 break; |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 private: | 203 private: |
| 204 // TODO(rockot): ApiResourceData could be moved out of ApiResourceManager and | 204 // TODO(rockot): ApiResourceData could be moved out of ApiResourceManager and |
| 205 // we could avoid maintaining a friends list here. | 205 // we could avoid maintaining a friends list here. |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 ->GetSequencedTaskRunnerWithShutdownBehavior( | 462 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 463 content::BrowserThread::GetBlockingPool()->GetNamedSequenceToken( | 463 content::BrowserThread::GetBlockingPool()->GetNamedSequenceToken( |
| 464 T::kSequenceToken), | 464 T::kSequenceToken), |
| 465 T::kShutdownBehavior); | 465 T::kShutdownBehavior); |
| 466 } | 466 } |
| 467 }; | 467 }; |
| 468 | 468 |
| 469 } // namespace extensions | 469 } // namespace extensions |
| 470 | 470 |
| 471 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ | 471 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ |
| OLD | NEW |