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_SOCKET_SOCKET_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "chrome/browser/extensions/api/api_function.h" | 10 #include "chrome/browser/extensions/api/api_function.h" |
11 #include "chrome/browser/extensions/api/api_resource_manager.h" | 11 #include "chrome/browser/extensions/api/api_resource_manager.h" |
12 #include "chrome/common/extensions/api/socket.h" | 12 #include "chrome/common/extensions/api/socket.h" |
13 #include "extensions/browser/extension_function.h" | 13 #include "extensions/browser/extension_function.h" |
14 #include "net/base/address_list.h" | 14 #include "net/base/address_list.h" |
15 #include "net/dns/host_resolver.h" | 15 #include "net/dns/host_resolver.h" |
16 #include "net/socket/tcp_client_socket.h" | 16 #include "net/socket/tcp_client_socket.h" |
17 | 17 |
18 #include <string> | 18 #include <string> |
19 | 19 |
20 class IOThread; | 20 class IOThread; |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 class IOBuffer; | 23 class IOBuffer; |
24 class URLRequestContextGetter; | |
25 class SSLClientSocket; | |
24 } | 26 } |
25 | 27 |
26 namespace extensions { | 28 namespace extensions { |
27 | 29 class TLSSocket; |
28 class Socket; | 30 class Socket; |
29 | 31 |
30 // A simple interface to ApiResourceManager<Socket> or derived class. The goal | 32 // A simple interface to ApiResourceManager<Socket> or derived class. The goal |
31 // of this interface is to allow Socket API functions to use distinct instances | 33 // of this interface is to allow Socket API functions to use distinct instances |
32 // of ApiResourceManager<> depending on the type of socket (old version in | 34 // of ApiResourceManager<> depending on the type of socket (old version in |
33 // "socket" namespace vs new version in "socket.xxx" namespaces). | 35 // "socket" namespace vs new version in "socket.xxx" namespaces). |
34 class SocketResourceManagerInterface { | 36 class SocketResourceManagerInterface { |
35 public: | 37 public: |
36 virtual ~SocketResourceManagerInterface() {} | 38 virtual ~SocketResourceManagerInterface() {} |
37 | 39 |
38 virtual bool SetProfile(Profile* profile) = 0; | 40 virtual bool SetProfile(Profile* profile) = 0; |
39 virtual int Add(Socket *socket) = 0; | 41 virtual int Add(Socket *socket) = 0; |
40 virtual Socket* Get(const std::string& extension_id, | 42 virtual Socket* Get(const std::string& extension_id, |
41 int api_resource_id) = 0; | 43 int api_resource_id) = 0; |
42 virtual void Remove(const std::string& extension_id, | 44 virtual void Remove(const std::string& extension_id, |
43 int api_resource_id) = 0; | 45 int api_resource_id) = 0; |
46 virtual void Set(const std::string& extension_id, int api_resource_id, | |
Ryan Sleevi
2013/12/17 00:37:40
style nit: api_resource_id should be on its own li
lally
2014/01/09 18:47:16
Done.
| |
47 Socket *socket) = 0; | |
44 virtual base::hash_set<int>* GetResourceIds( | 48 virtual base::hash_set<int>* GetResourceIds( |
45 const std::string& extension_id) = 0; | 49 const std::string& extension_id) = 0; |
46 }; | 50 }; |
47 | 51 |
48 // Implementation of SocketResourceManagerInterface using an | 52 // Implementation of SocketResourceManagerInterface using an |
49 // ApiResourceManager<T> instance (where T derives from Socket). | 53 // ApiResourceManager<T> instance (where T derives from Socket). |
50 template<typename T> | 54 template<typename T> |
51 class SocketResourceManager : public SocketResourceManagerInterface { | 55 class SocketResourceManager : public SocketResourceManagerInterface { |
52 public: | 56 public: |
53 SocketResourceManager() | 57 SocketResourceManager() |
(...skipping 12 matching lines...) Expand all Loading... | |
66 virtual int Add(Socket *socket) OVERRIDE { | 70 virtual int Add(Socket *socket) OVERRIDE { |
67 // Note: Cast needed here, because "T" may be a subclass of "Socket". | 71 // Note: Cast needed here, because "T" may be a subclass of "Socket". |
68 return manager_->Add(static_cast<T*>(socket)); | 72 return manager_->Add(static_cast<T*>(socket)); |
69 } | 73 } |
70 | 74 |
71 virtual Socket* Get(const std::string& extension_id, | 75 virtual Socket* Get(const std::string& extension_id, |
72 int api_resource_id) OVERRIDE { | 76 int api_resource_id) OVERRIDE { |
73 return manager_->Get(extension_id, api_resource_id); | 77 return manager_->Get(extension_id, api_resource_id); |
74 } | 78 } |
75 | 79 |
80 virtual void Set(const std::string& extension_id, int api_resource_id, | |
81 Socket *socket) OVERRIDE { | |
82 manager_->Set(extension_id, api_resource_id, static_cast<T*>(socket)); | |
83 } | |
84 | |
76 virtual void Remove(const std::string& extension_id, | 85 virtual void Remove(const std::string& extension_id, |
77 int api_resource_id) OVERRIDE { | 86 int api_resource_id) OVERRIDE { |
78 manager_->Remove(extension_id, api_resource_id); | 87 manager_->Remove(extension_id, api_resource_id); |
79 } | 88 } |
80 | 89 |
81 virtual base::hash_set<int>* GetResourceIds( | 90 virtual base::hash_set<int>* GetResourceIds( |
82 const std::string& extension_id) OVERRIDE { | 91 const std::string& extension_id) OVERRIDE { |
83 return manager_->GetResourceIds(extension_id); | 92 return manager_->GetResourceIds(extension_id); |
84 } | 93 } |
85 | 94 |
(...skipping 10 matching lines...) Expand all Loading... | |
96 | 105 |
97 // AsyncApiFunction: | 106 // AsyncApiFunction: |
98 virtual bool PrePrepare() OVERRIDE; | 107 virtual bool PrePrepare() OVERRIDE; |
99 virtual bool Respond() OVERRIDE; | 108 virtual bool Respond() OVERRIDE; |
100 | 109 |
101 virtual scoped_ptr<SocketResourceManagerInterface> | 110 virtual scoped_ptr<SocketResourceManagerInterface> |
102 CreateSocketResourceManager(); | 111 CreateSocketResourceManager(); |
103 | 112 |
104 int AddSocket(Socket* socket); | 113 int AddSocket(Socket* socket); |
105 Socket* GetSocket(int api_resource_id); | 114 Socket* GetSocket(int api_resource_id); |
115 void SetSocket(int api_resource_id, Socket* socket); | |
106 void RemoveSocket(int api_resource_id); | 116 void RemoveSocket(int api_resource_id); |
107 base::hash_set<int>* GetSocketIds(); | 117 base::hash_set<int>* GetSocketIds(); |
108 | 118 |
109 private: | 119 private: |
110 scoped_ptr<SocketResourceManagerInterface> manager_; | 120 scoped_ptr<SocketResourceManagerInterface> manager_; |
111 }; | 121 }; |
112 | 122 |
113 class SocketExtensionWithDnsLookupFunction : public SocketAsyncApiFunction { | 123 class SocketExtensionWithDnsLookupFunction : public SocketAsyncApiFunction { |
114 protected: | 124 protected: |
115 SocketExtensionWithDnsLookupFunction(); | 125 SocketExtensionWithDnsLookupFunction(); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 protected: | 507 protected: |
498 virtual ~SocketGetJoinedGroupsFunction(); | 508 virtual ~SocketGetJoinedGroupsFunction(); |
499 | 509 |
500 // AsyncApiFunction | 510 // AsyncApiFunction |
501 virtual bool Prepare() OVERRIDE; | 511 virtual bool Prepare() OVERRIDE; |
502 virtual void Work() OVERRIDE; | 512 virtual void Work() OVERRIDE; |
503 | 513 |
504 private: | 514 private: |
505 scoped_ptr<api::socket::GetJoinedGroups::Params> params_; | 515 scoped_ptr<api::socket::GetJoinedGroups::Params> params_; |
506 }; | 516 }; |
517 | |
518 class SocketSecureFunction : public SocketAsyncApiFunction { | |
519 public: | |
520 DECLARE_EXTENSION_FUNCTION("socket.secure", SOCKET_SECURE); | |
521 SocketSecureFunction(); | |
522 | |
523 protected: | |
524 virtual ~SocketSecureFunction(); | |
525 | |
526 // AsyncApiFunction | |
527 virtual bool Prepare() OVERRIDE; | |
528 virtual void AsyncWorkStart() OVERRIDE; | |
529 | |
530 private: | |
Ryan Sleevi
2013/12/17 00:37:40
DISALLOW_COPY_AND_ASSIGN ? Although this seems to
lally
2014/01/09 18:47:16
Done.
| |
531 // Callback from TLSSocket::SecureTCPSocket(). | |
532 void TlsConnectDone(TLSSocket* socket, int result); | |
533 | |
534 scoped_ptr<api::socket::Secure::Params> params_; | |
535 net::URLRequestContextGetter* url_request_getter_; | |
536 }; | |
537 | |
507 } // namespace extensions | 538 } // namespace extensions |
508 | 539 |
509 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ | 540 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ |
OLD | NEW |