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" |
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 "chrome/browser/extensions/extension_host.h" | 16 #include "chrome/browser/extensions/extension_host.h" |
17 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | 17 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "extensions/browser/browser_context_keyed_api_factory.h" | 22 #include "extensions/browser/browser_context_keyed_api_factory.h" |
23 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
24 | 24 |
25 namespace extensions { | 25 namespace extensions { |
26 | |
26 namespace api { | 27 namespace api { |
27 class SerialEventDispatcher; | 28 class SerialEventDispatcher; |
29 } | |
30 | |
31 namespace core_api { | |
28 class TCPServerSocketEventDispatcher; | 32 class TCPServerSocketEventDispatcher; |
29 class TCPSocketEventDispatcher; | 33 class TCPSocketEventDispatcher; |
30 class UDPSocketEventDispatcher; | 34 class UDPSocketEventDispatcher; |
31 } | 35 } |
32 } | |
33 | |
34 namespace extensions { | |
35 | 36 |
36 // An ApiResourceManager manages the lifetime of a set of resources that | 37 // An ApiResourceManager manages the lifetime of a set of resources that |
37 // ApiFunctions use. Examples are sockets or USB connections. | 38 // ApiFunctions use. Examples are sockets or USB connections. |
38 // | 39 // |
39 // Users of this class should define kThreadId to be the thread that | 40 // Users of this class should define kThreadId to be the thread that |
40 // ApiResourceManager to works on. The default is defined in ApiResource. | 41 // ApiResourceManager to works on. The default is defined in ApiResource. |
41 // The user must also define a static const char* service_name() that returns | 42 // The user must also define a static const char* service_name() that returns |
42 // the name of the service, and in order for ApiResourceManager to use | 43 // the name of the service, and in order for ApiResourceManager to use |
43 // service_name() friend this class. | 44 // service_name() friend this class. |
44 // | 45 // |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 } | 148 } |
148 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 149 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
149 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 150 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
150 data_->InitiateExtensionSuspendedCleanup(host->extension_id()); | 151 data_->InitiateExtensionSuspendedCleanup(host->extension_id()); |
151 break; | 152 break; |
152 } | 153 } |
153 } | 154 } |
154 } | 155 } |
155 | 156 |
156 private: | 157 private: |
158 // TODO(rockot): ApiResourceData could be moved out of ApiResourceManager and | |
159 // we could avoid maintaining a friends list here. | |
157 friend class api::SerialEventDispatcher; | 160 friend class api::SerialEventDispatcher; |
158 friend class api::TCPServerSocketEventDispatcher; | 161 friend class core_api::TCPServerSocketEventDispatcher; |
159 friend class api::TCPSocketEventDispatcher; | 162 friend class core_api::TCPSocketEventDispatcher; |
160 friend class api::UDPSocketEventDispatcher; | 163 friend class core_api::UDPSocketEventDispatcher; |
161 friend class BrowserContextKeyedAPIFactory<ApiResourceManager<T> >; | 164 friend class BrowserContextKeyedAPIFactory<ApiResourceManager<T> >; |
162 // BrowserContextKeyedAPI implementation. | 165 |
James Cook
2014/03/06 18:31:00
nit: I would keep this comment since these statics
Ken Rockot(use gerrit already)
2014/03/06 18:46:32
Yeah, that was a manual merge mistake. Fixed.
| |
163 static const char* service_name() { | 166 static const char* service_name() { |
164 return T::service_name(); | 167 return T::service_name(); |
165 } | 168 } |
166 static const bool kServiceHasOwnInstanceInIncognito = true; | 169 static const bool kServiceHasOwnInstanceInIncognito = true; |
167 static const bool kServiceIsNULLWhileTesting = true; | 170 static const bool kServiceIsNULLWhileTesting = true; |
168 | 171 |
169 // ApiResourceData class handles resource bookkeeping on a thread | 172 // ApiResourceData class handles resource bookkeeping on a thread |
170 // where resource lifetime is handled. | 173 // where resource lifetime is handled. |
171 class ApiResourceData : public base::RefCountedThreadSafe<ApiResourceData> { | 174 class ApiResourceData : public base::RefCountedThreadSafe<ApiResourceData> { |
172 public: | 175 public: |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 }; | 327 }; |
325 | 328 |
326 content::BrowserThread::ID thread_id_; | 329 content::BrowserThread::ID thread_id_; |
327 content::NotificationRegistrar registrar_; | 330 content::NotificationRegistrar registrar_; |
328 scoped_refptr<ApiResourceData> data_; | 331 scoped_refptr<ApiResourceData> data_; |
329 }; | 332 }; |
330 | 333 |
331 } // namespace extensions | 334 } // namespace extensions |
332 | 335 |
333 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ | 336 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ |
OLD | NEW |