OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SOCKETS_TCP_TCP_SOCKET_EVENT_DISPATCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKETS_TCP_TCP_SOCKET_EVENT_DISPATCHER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKETS_TCP_TCP_SOCKET_EVENT_DISPATCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKETS_TCP_TCP_SOCKET_EVENT_DISPATCHER_H_ |
7 | 7 |
8 #include "chrome/browser/extensions/api/api_resource_manager.h" | 8 #include "chrome/browser/extensions/api/api_resource_manager.h" |
9 #include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h" | 9 #include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 class BrowserContext; | 12 class BrowserContext; |
13 } | 13 } |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 struct Event; | 16 struct Event; |
17 class ResumableTCPSocket; | 17 class ResumableTCPSocket; |
18 } | 18 } |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 namespace api { | 21 namespace api { |
22 | 22 |
23 // Dispatch events related to "sockets.tcp" sockets from callback on native | 23 // Dispatch events related to "sockets.tcp" sockets from callback on native |
24 // socket instances. There is one instance per profile. | 24 // socket instances. There is one instance per profile. |
25 class TCPSocketEventDispatcher | 25 class TCPSocketEventDispatcher |
26 : public ProfileKeyedAPI, | 26 : public BrowserContextKeyedAPI, |
27 public base::SupportsWeakPtr<TCPSocketEventDispatcher> { | 27 public base::SupportsWeakPtr<TCPSocketEventDispatcher> { |
28 public: | 28 public: |
29 explicit TCPSocketEventDispatcher(content::BrowserContext* context); | 29 explicit TCPSocketEventDispatcher(content::BrowserContext* context); |
30 virtual ~TCPSocketEventDispatcher(); | 30 virtual ~TCPSocketEventDispatcher(); |
31 | 31 |
32 // Socket is active, start receving from it. | 32 // Socket is active, start receving from it. |
33 void OnSocketConnect(const std::string& extension_id, int socket_id); | 33 void OnSocketConnect(const std::string& extension_id, int socket_id); |
34 | 34 |
35 // Socket is active again, start receiving data from it. | 35 // Socket is active again, start receiving data from it. |
36 void OnSocketResume(const std::string& extension_id, int socket_id); | 36 void OnSocketResume(const std::string& extension_id, int socket_id); |
37 | 37 |
38 // ProfileKeyedAPI implementation. | 38 // BrowserContextKeyedAPI implementation. |
39 static ProfileKeyedAPIFactory<TCPSocketEventDispatcher>* GetFactoryInstance(); | 39 static BrowserContextKeyedAPIFactory<TCPSocketEventDispatcher>* |
| 40 GetFactoryInstance(); |
40 | 41 |
41 // Convenience method to get the SocketEventDispatcher for a profile. | 42 // Convenience method to get the SocketEventDispatcher for a profile. |
42 static TCPSocketEventDispatcher* Get(content::BrowserContext* context); | 43 static TCPSocketEventDispatcher* Get(content::BrowserContext* context); |
43 | 44 |
44 private: | 45 private: |
45 typedef ApiResourceManager<ResumableTCPSocket>::ApiResourceData SocketData; | 46 typedef ApiResourceManager<ResumableTCPSocket>::ApiResourceData SocketData; |
46 friend class ProfileKeyedAPIFactory<TCPSocketEventDispatcher>; | 47 friend class BrowserContextKeyedAPIFactory<TCPSocketEventDispatcher>; |
47 // ProfileKeyedAPI implementation. | 48 // BrowserContextKeyedAPI implementation. |
48 static const char* service_name() { | 49 static const char* service_name() { |
49 return "TCPSocketEventDispatcher"; | 50 return "TCPSocketEventDispatcher"; |
50 } | 51 } |
51 static const bool kServiceHasOwnInstanceInIncognito = true; | 52 static const bool kServiceHasOwnInstanceInIncognito = true; |
52 static const bool kServiceIsNULLWhileTesting = true; | 53 static const bool kServiceIsNULLWhileTesting = true; |
53 | 54 |
54 // base::Bind supports methods with up to 6 parameters. ReadParams is used | 55 // base::Bind supports methods with up to 6 parameters. ReadParams is used |
55 // as a workaround that limitation for invoking StartReceive. | 56 // as a workaround that limitation for invoking StartReceive. |
56 struct ReadParams { | 57 struct ReadParams { |
57 ReadParams(); | 58 ReadParams(); |
(...skipping 28 matching lines...) Expand all Loading... |
86 // Usually IO thread (except for unit testing). | 87 // Usually IO thread (except for unit testing). |
87 content::BrowserThread::ID thread_id_; | 88 content::BrowserThread::ID thread_id_; |
88 content::BrowserContext* const browser_context_; | 89 content::BrowserContext* const browser_context_; |
89 scoped_refptr<SocketData> sockets_; | 90 scoped_refptr<SocketData> sockets_; |
90 }; | 91 }; |
91 | 92 |
92 } // namespace api | 93 } // namespace api |
93 } // namespace extensions | 94 } // namespace extensions |
94 | 95 |
95 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKETS_TCP_TCP_SOCKET_EVENT_DISPATCHER
_H_ | 96 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKETS_TCP_TCP_SOCKET_EVENT_DISPATCHER
_H_ |
OLD | NEW |