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

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

Issue 183893041: Move sockets APIs out of src/chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename api targets Created 6 years, 9 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
« no previous file with comments | « extensions/browser/DEPS ('k') | extensions/browser/api/socket/socket.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 143 }
143 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { 144 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
144 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 145 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
145 data_->InitiateExtensionSuspendedCleanup(host->extension_id()); 146 data_->InitiateExtensionSuspendedCleanup(host->extension_id());
146 break; 147 break;
147 } 148 }
148 } 149 }
149 } 150 }
150 151
151 private: 152 private:
153 // TODO(rockot): ApiResourceData could be moved out of ApiResourceManager and
154 // we could avoid maintaining a friends list here.
152 friend class api::SerialEventDispatcher; 155 friend class api::SerialEventDispatcher;
153 friend class api::TCPServerSocketEventDispatcher; 156 friend class core_api::TCPServerSocketEventDispatcher;
154 friend class api::TCPSocketEventDispatcher; 157 friend class core_api::TCPSocketEventDispatcher;
155 friend class api::UDPSocketEventDispatcher; 158 friend class core_api::UDPSocketEventDispatcher;
156 friend class BrowserContextKeyedAPIFactory<ApiResourceManager<T> >; 159 friend class BrowserContextKeyedAPIFactory<ApiResourceManager<T> >;
160
157 // BrowserContextKeyedAPI implementation. 161 // BrowserContextKeyedAPI implementation.
158 static const char* service_name() { return T::service_name(); } 162 static const char* service_name() { return T::service_name(); }
163
159 static const bool kServiceHasOwnInstanceInIncognito = true; 164 static const bool kServiceHasOwnInstanceInIncognito = true;
160 static const bool kServiceIsNULLWhileTesting = true; 165 static const bool kServiceIsNULLWhileTesting = true;
161 166
162 // ApiResourceData class handles resource bookkeeping on a thread 167 // ApiResourceData class handles resource bookkeeping on a thread
163 // where resource lifetime is handled. 168 // where resource lifetime is handled.
164 class ApiResourceData : public base::RefCountedThreadSafe<ApiResourceData> { 169 class ApiResourceData : public base::RefCountedThreadSafe<ApiResourceData> {
165 public: 170 public:
166 typedef std::map<int, linked_ptr<T> > ApiResourceMap; 171 typedef std::map<int, linked_ptr<T> > ApiResourceMap;
167 // Lookup map from extension id's to allocated resource id's. 172 // Lookup map from extension id's to allocated resource id's.
168 typedef std::map<std::string, base::hash_set<int> > ExtensionToResourceMap; 173 typedef std::map<std::string, base::hash_set<int> > ExtensionToResourceMap;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 }; 322 };
318 323
319 content::BrowserThread::ID thread_id_; 324 content::BrowserThread::ID thread_id_;
320 content::NotificationRegistrar registrar_; 325 content::NotificationRegistrar registrar_;
321 scoped_refptr<ApiResourceData> data_; 326 scoped_refptr<ApiResourceData> data_;
322 }; 327 };
323 328
324 } // namespace extensions 329 } // namespace extensions
325 330
326 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_ 331 #endif // EXTENSIONS_BROWSER_API_API_RESOURCE_MANAGER_H_
OLDNEW
« no previous file with comments | « extensions/browser/DEPS ('k') | extensions/browser/api/socket/socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698