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_UDP_UDP_SOCKET_EVENT_DISPATCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKETS_UDP_UDP_SOCKET_EVENT_DISPATCHER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKETS_UDP_UDP_SOCKET_EVENT_DISPATCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKETS_UDP_UDP_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_udp/sockets_udp_api.h" | 9 #include "chrome/browser/extensions/api/sockets_udp/sockets_udp_api.h" |
10 | 10 |
11 namespace extensions { | 11 namespace extensions { |
12 struct Event; | 12 struct Event; |
13 class ResumableUDPSocket; | 13 class ResumableUDPSocket; |
14 } | 14 } |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 namespace api { | 17 namespace api { |
18 | 18 |
19 // Dispatch events related to "sockets.udp" sockets from callback on native | 19 // Dispatch events related to "sockets.udp" sockets from callback on native |
20 // socket instances. There is one instance per profile. | 20 // socket instances. There is one instance per profile. |
21 class UDPSocketEventDispatcher | 21 class UDPSocketEventDispatcher |
22 : public ProfileKeyedAPI, | 22 : public ProfileKeyedAPI, |
23 public base::SupportsWeakPtr<UDPSocketEventDispatcher> { | 23 public base::SupportsWeakPtr<UDPSocketEventDispatcher> { |
24 public: | 24 public: |
25 explicit UDPSocketEventDispatcher(Profile* profile); | 25 explicit UDPSocketEventDispatcher(content::BrowserContext* context); |
26 virtual ~UDPSocketEventDispatcher(); | 26 virtual ~UDPSocketEventDispatcher(); |
27 | 27 |
28 // Socket is active, start receving from it. | 28 // Socket is active, start receving from it. |
29 void OnSocketBind(const std::string& extension_id, int socket_id); | 29 void OnSocketBind(const std::string& extension_id, int socket_id); |
30 | 30 |
31 // Socket is active again, start receiving data from it. | 31 // Socket is active again, start receiving data from it. |
32 void OnSocketResume(const std::string& extension_id, int socket_id); | 32 void OnSocketResume(const std::string& extension_id, int socket_id); |
33 | 33 |
34 // ProfileKeyedAPI implementation. | 34 // ProfileKeyedAPI implementation. |
35 static ProfileKeyedAPIFactory<UDPSocketEventDispatcher>* GetFactoryInstance(); | 35 static ProfileKeyedAPIFactory<UDPSocketEventDispatcher>* GetFactoryInstance(); |
36 | 36 |
37 // Convenience method to get the SocketEventDispatcher for a profile. | 37 // Convenience method to get the SocketEventDispatcher for a profile. |
38 static UDPSocketEventDispatcher* Get(Profile* profile); | 38 static UDPSocketEventDispatcher* Get(content::BrowserContext* context); |
39 | 39 |
40 private: | 40 private: |
41 typedef ApiResourceManager<ResumableUDPSocket>::ApiResourceData SocketData; | 41 typedef ApiResourceManager<ResumableUDPSocket>::ApiResourceData SocketData; |
42 friend class ProfileKeyedAPIFactory<UDPSocketEventDispatcher>; | 42 friend class ProfileKeyedAPIFactory<UDPSocketEventDispatcher>; |
43 // ProfileKeyedAPI implementation. | 43 // ProfileKeyedAPI implementation. |
44 static const char* service_name() { | 44 static const char* service_name() { |
45 return "UDPSocketEventDispatcher"; | 45 return "UDPSocketEventDispatcher"; |
46 } | 46 } |
47 static const bool kServiceHasOwnInstanceInIncognito = true; | 47 static const bool kServiceHasOwnInstanceInIncognito = true; |
48 static const bool kServiceIsNULLWhileTesting = true; | 48 static const bool kServiceIsNULLWhileTesting = true; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // Usually IO thread (except for unit testing). | 81 // Usually IO thread (except for unit testing). |
82 content::BrowserThread::ID thread_id_; | 82 content::BrowserThread::ID thread_id_; |
83 Profile* const profile_; | 83 Profile* const profile_; |
84 scoped_refptr<SocketData> sockets_; | 84 scoped_refptr<SocketData> sockets_; |
85 }; | 85 }; |
86 | 86 |
87 } // namespace api | 87 } // namespace api |
88 } // namespace extensions | 88 } // namespace extensions |
89 | 89 |
90 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKETS_UDP_UDP_SOCKET_EVENT_DISPATCHER
_H_ | 90 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKETS_UDP_UDP_SOCKET_EVENT_DISPATCHER
_H_ |
OLD | NEW |