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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // return g_factory.Pointer(); | 71 // return g_factory.Pointer(); |
72 // } | 72 // } |
73 template <class T> | 73 template <class T> |
74 class ApiResourceManager : public BrowserContextKeyedAPI, | 74 class ApiResourceManager : public BrowserContextKeyedAPI, |
75 public base::NonThreadSafe, | 75 public base::NonThreadSafe, |
76 public content::NotificationObserver { | 76 public content::NotificationObserver { |
77 public: | 77 public: |
78 explicit ApiResourceManager(content::BrowserContext* context) | 78 explicit ApiResourceManager(content::BrowserContext* context) |
79 : thread_id_(T::kThreadId), data_(new ApiResourceData(thread_id_)) { | 79 : thread_id_(T::kThreadId), data_(new ApiResourceData(thread_id_)) { |
80 registrar_.Add(this, | 80 registrar_.Add(this, |
81 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 81 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
82 content::NotificationService::AllSources()); | 82 content::NotificationService::AllSources()); |
83 registrar_.Add(this, | 83 registrar_.Add(this, |
84 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 84 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
85 content::NotificationService::AllSources()); | 85 content::NotificationService::AllSources()); |
86 } | 86 } |
87 | 87 |
88 // For Testing. | 88 // For Testing. |
89 static ApiResourceManager<T>* CreateApiResourceManagerForTest( | 89 static ApiResourceManager<T>* CreateApiResourceManagerForTest( |
90 content::BrowserContext* context, | 90 content::BrowserContext* context, |
91 content::BrowserThread::ID thread_id) { | 91 content::BrowserThread::ID thread_id) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { | 128 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { |
129 return data_->GetResourceIds(extension_id); | 129 return data_->GetResourceIds(extension_id); |
130 } | 130 } |
131 | 131 |
132 protected: | 132 protected: |
133 // content::NotificationObserver: | 133 // content::NotificationObserver: |
134 virtual void Observe(int type, | 134 virtual void Observe(int type, |
135 const content::NotificationSource& source, | 135 const content::NotificationSource& source, |
136 const content::NotificationDetails& details) OVERRIDE { | 136 const content::NotificationDetails& details) OVERRIDE { |
137 switch (type) { | 137 switch (type) { |
138 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 138 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
139 std::string id = content::Details<extensions::UnloadedExtensionInfo>( | 139 std::string id = content::Details<extensions::UnloadedExtensionInfo>( |
140 details)->extension->id(); | 140 details)->extension->id(); |
141 data_->InitiateExtensionUnloadedCleanup(id); | 141 data_->InitiateExtensionUnloadedCleanup(id); |
142 break; | 142 break; |
143 } | 143 } |
144 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 144 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
145 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 145 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
146 data_->InitiateExtensionSuspendedCleanup(host->extension_id()); | 146 data_->InitiateExtensionSuspendedCleanup(host->extension_id()); |
147 break; | 147 break; |
148 } | 148 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 }; | 322 }; |
323 | 323 |
324 content::BrowserThread::ID thread_id_; | 324 content::BrowserThread::ID thread_id_; |
325 content::NotificationRegistrar registrar_; | 325 content::NotificationRegistrar registrar_; |
326 scoped_refptr<ApiResourceData> data_; | 326 scoped_refptr<ApiResourceData> data_; |
327 }; | 327 }; |
328 | 328 |
329 } // namespace extensions | 329 } // namespace extensions |
330 | 330 |
331 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ | 331 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ |
OLD | NEW |