Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: trunk/src/extensions/browser/api/api_resource_manager.h

Issue 227493006: Revert 262175 "* Replace "read" method with onReceiveXxx events." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "components/keyed_service/core/keyed_service.h" 16 #include "components/keyed_service/core/keyed_service.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
21 #include "extensions/browser/browser_context_keyed_api_factory.h" 21 #include "extensions/browser/browser_context_keyed_api_factory.h"
22 #include "extensions/browser/extension_host.h" 22 #include "extensions/browser/extension_host.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;
29 class BluetoothSocketEventDispatcher;
30 class SerialEventDispatcher; 28 class SerialEventDispatcher;
31 } 29 }
32 30
33 namespace core_api { 31 namespace core_api {
34 class TCPServerSocketEventDispatcher; 32 class TCPServerSocketEventDispatcher;
35 class TCPSocketEventDispatcher; 33 class TCPSocketEventDispatcher;
36 class UDPSocketEventDispatcher; 34 class UDPSocketEventDispatcher;
37 } 35 }
38 36
39 // An ApiResourceManager manages the lifetime of a set of resources that 37 // An ApiResourceManager manages the lifetime of a set of resources that
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 145 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
148 data_->InitiateExtensionSuspendedCleanup(host->extension_id()); 146 data_->InitiateExtensionSuspendedCleanup(host->extension_id());
149 break; 147 break;
150 } 148 }
151 } 149 }
152 } 150 }
153 151
154 private: 152 private:
155 // TODO(rockot): ApiResourceData could be moved out of ApiResourceManager and 153 // TODO(rockot): ApiResourceData could be moved out of ApiResourceManager and
156 // we could avoid maintaining a friends list here. 154 // we could avoid maintaining a friends list here.
157 friend class BluetoothAPI;
158 friend class api::BluetoothSocketApiFunction;
159 friend class api::BluetoothSocketEventDispatcher;
160 friend class api::SerialEventDispatcher; 155 friend class api::SerialEventDispatcher;
161 friend class core_api::TCPServerSocketEventDispatcher; 156 friend class core_api::TCPServerSocketEventDispatcher;
162 friend class core_api::TCPSocketEventDispatcher; 157 friend class core_api::TCPSocketEventDispatcher;
163 friend class core_api::UDPSocketEventDispatcher; 158 friend class core_api::UDPSocketEventDispatcher;
164 friend class BrowserContextKeyedAPIFactory<ApiResourceManager<T> >; 159 friend class BrowserContextKeyedAPIFactory<ApiResourceManager<T> >;
165 160
166 // BrowserContextKeyedAPI implementation. 161 // BrowserContextKeyedAPI implementation.
167 static const char* service_name() { return T::service_name(); } 162 static const char* service_name() { return T::service_name(); }
168 163
169 static const bool kServiceHasOwnInstanceInIncognito = true; 164 static const bool kServiceHasOwnInstanceInIncognito = true;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 DCHECK_CURRENTLY_ON(thread_id_); 208 DCHECK_CURRENTLY_ON(thread_id_);
214 return GetOwnedResource(extension_id, api_resource_id); 209 return GetOwnedResource(extension_id, api_resource_id);
215 } 210 }
216 211
217 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { 212 base::hash_set<int>* GetResourceIds(const std::string& extension_id) {
218 DCHECK_CURRENTLY_ON(thread_id_); 213 DCHECK_CURRENTLY_ON(thread_id_);
219 return GetOwnedResourceIds(extension_id); 214 return GetOwnedResourceIds(extension_id);
220 } 215 }
221 216
222 void InitiateExtensionUnloadedCleanup(const std::string& extension_id) { 217 void InitiateExtensionUnloadedCleanup(const std::string& extension_id) {
223 if (content::BrowserThread::CurrentlyOn(thread_id_)) { 218 content::BrowserThread::PostTask(
224 CleanupResourcesFromUnloadedExtension(extension_id); 219 thread_id_,
225 } else { 220 FROM_HERE,
226 content::BrowserThread::PostTask( 221 base::Bind(&ApiResourceData::CleanupResourcesFromUnloadedExtension,
227 thread_id_, 222 this,
228 FROM_HERE, 223 extension_id));
229 base::Bind(&ApiResourceData::CleanupResourcesFromUnloadedExtension,
230 this,
231 extension_id));
232 }
233 } 224 }
234 225
235 void InitiateExtensionSuspendedCleanup(const std::string& extension_id) { 226 void InitiateExtensionSuspendedCleanup(const std::string& extension_id) {
236 if (content::BrowserThread::CurrentlyOn(thread_id_)) { 227 content::BrowserThread::PostTask(
237 CleanupResourcesFromSuspendedExtension(extension_id); 228 thread_id_,
238 } else { 229 FROM_HERE,
239 content::BrowserThread::PostTask( 230 base::Bind(&ApiResourceData::CleanupResourcesFromSuspendedExtension,
240 thread_id_, 231 this,
241 FROM_HERE, 232 extension_id));
242 base::Bind(&ApiResourceData::CleanupResourcesFromSuspendedExtension,
243 this,
244 extension_id));
245 }
246 } 233 }
247 234
248 void InititateCleanup() { 235 void InititateCleanup() {
249 if (content::BrowserThread::CurrentlyOn(thread_id_)) { 236 content::BrowserThread::PostTask(
250 Cleanup(); 237 thread_id_, FROM_HERE, base::Bind(&ApiResourceData::Cleanup, this));
251 } else {
252 content::BrowserThread::PostTask(
253 thread_id_, FROM_HERE, base::Bind(&ApiResourceData::Cleanup, this));
254 }
255 } 238 }
256 239
257 private: 240 private:
258 friend class base::RefCountedThreadSafe<ApiResourceData>; 241 friend class base::RefCountedThreadSafe<ApiResourceData>;
259 242
260 virtual ~ApiResourceData() {} 243 virtual ~ApiResourceData() {}
261 244
262 T* GetOwnedResource(const std::string& extension_id, int api_resource_id) { 245 T* GetOwnedResource(const std::string& extension_id, int api_resource_id) {
263 linked_ptr<T> ptr = api_resource_map_[api_resource_id]; 246 linked_ptr<T> ptr = api_resource_map_[api_resource_id];
264 T* resource = ptr.get(); 247 T* resource = ptr.get();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 }; 322 };
340 323
341 content::BrowserThread::ID thread_id_; 324 content::BrowserThread::ID thread_id_;
342 content::NotificationRegistrar registrar_; 325 content::NotificationRegistrar registrar_;
343 scoped_refptr<ApiResourceData> data_; 326 scoped_refptr<ApiResourceData> data_;
344 }; 327 };
345 328
346 } // namespace extensions 329 } // namespace extensions
347 330
348 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ 331 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_
OLDNEW
« no previous file with comments | « trunk/src/device/bluetooth/test/mock_bluetooth_socket.h ('k') | trunk/src/extensions/browser/api/async_api_function.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698