| OLD | NEW |
| 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_SOCKETS_TCP_SOCKETS_TCP_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_SOCKETS_TCP_SOCKETS_TCP_API_H_ |
| 6 #define EXTENSIONS_BROWSER_API_SOCKETS_TCP_SOCKETS_TCP_API_H_ | 6 #define EXTENSIONS_BROWSER_API_SOCKETS_TCP_SOCKETS_TCP_API_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "extensions/browser/api/socket/socket_api.h" | 12 #include "extensions/browser/api/socket/socket_api.h" |
| 13 #include "extensions/common/api/sockets_tcp.h" | 13 #include "extensions/common/api/sockets_tcp.h" |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 class ResumableTCPSocket; | 16 class ResumableTCPSocket; |
| 17 class TLSSocket; | 17 class TLSSocket; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 namespace api { | 21 namespace api { |
| 22 | 22 |
| 23 class TCPSocketEventDispatcher; | 23 class TCPSocketEventDispatcher; |
| 24 | 24 |
| 25 class TCPSocketAsyncApiFunction : public SocketAsyncApiFunction { | 25 class TCPSocketAsyncApiFunction : public SocketAsyncApiFunction { |
| 26 protected: | 26 protected: |
| 27 ~TCPSocketAsyncApiFunction() override; | 27 ~TCPSocketAsyncApiFunction() override; |
| 28 | 28 |
| 29 scoped_ptr<SocketResourceManagerInterface> CreateSocketResourceManager() | 29 std::unique_ptr<SocketResourceManagerInterface> CreateSocketResourceManager() |
| 30 override; | 30 override; |
| 31 | 31 |
| 32 ResumableTCPSocket* GetTcpSocket(int socket_id); | 32 ResumableTCPSocket* GetTcpSocket(int socket_id); |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class TCPSocketExtensionWithDnsLookupFunction | 35 class TCPSocketExtensionWithDnsLookupFunction |
| 36 : public SocketExtensionWithDnsLookupFunction { | 36 : public SocketExtensionWithDnsLookupFunction { |
| 37 protected: | 37 protected: |
| 38 ~TCPSocketExtensionWithDnsLookupFunction() override; | 38 ~TCPSocketExtensionWithDnsLookupFunction() override; |
| 39 | 39 |
| 40 scoped_ptr<SocketResourceManagerInterface> CreateSocketResourceManager() | 40 std::unique_ptr<SocketResourceManagerInterface> CreateSocketResourceManager() |
| 41 override; | 41 override; |
| 42 | 42 |
| 43 ResumableTCPSocket* GetTcpSocket(int socket_id); | 43 ResumableTCPSocket* GetTcpSocket(int socket_id); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class SocketsTcpCreateFunction : public TCPSocketAsyncApiFunction { | 46 class SocketsTcpCreateFunction : public TCPSocketAsyncApiFunction { |
| 47 public: | 47 public: |
| 48 DECLARE_EXTENSION_FUNCTION("sockets.tcp.create", SOCKETS_TCP_CREATE) | 48 DECLARE_EXTENSION_FUNCTION("sockets.tcp.create", SOCKETS_TCP_CREATE) |
| 49 | 49 |
| 50 SocketsTcpCreateFunction(); | 50 SocketsTcpCreateFunction(); |
| 51 | 51 |
| 52 protected: | 52 protected: |
| 53 ~SocketsTcpCreateFunction() override; | 53 ~SocketsTcpCreateFunction() override; |
| 54 | 54 |
| 55 // AsyncApiFunction: | 55 // AsyncApiFunction: |
| 56 bool Prepare() override; | 56 bool Prepare() override; |
| 57 void Work() override; | 57 void Work() override; |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 FRIEND_TEST_ALL_PREFIXES(SocketsTcpUnitTest, Create); | 60 FRIEND_TEST_ALL_PREFIXES(SocketsTcpUnitTest, Create); |
| 61 scoped_ptr<sockets_tcp::Create::Params> params_; | 61 std::unique_ptr<sockets_tcp::Create::Params> params_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class SocketsTcpUpdateFunction : public TCPSocketAsyncApiFunction { | 64 class SocketsTcpUpdateFunction : public TCPSocketAsyncApiFunction { |
| 65 public: | 65 public: |
| 66 DECLARE_EXTENSION_FUNCTION("sockets.tcp.update", SOCKETS_TCP_UPDATE) | 66 DECLARE_EXTENSION_FUNCTION("sockets.tcp.update", SOCKETS_TCP_UPDATE) |
| 67 | 67 |
| 68 SocketsTcpUpdateFunction(); | 68 SocketsTcpUpdateFunction(); |
| 69 | 69 |
| 70 protected: | 70 protected: |
| 71 ~SocketsTcpUpdateFunction() override; | 71 ~SocketsTcpUpdateFunction() override; |
| 72 | 72 |
| 73 // AsyncApiFunction: | 73 // AsyncApiFunction: |
| 74 bool Prepare() override; | 74 bool Prepare() override; |
| 75 void Work() override; | 75 void Work() override; |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 scoped_ptr<sockets_tcp::Update::Params> params_; | 78 std::unique_ptr<sockets_tcp::Update::Params> params_; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 class SocketsTcpSetPausedFunction : public TCPSocketAsyncApiFunction { | 81 class SocketsTcpSetPausedFunction : public TCPSocketAsyncApiFunction { |
| 82 public: | 82 public: |
| 83 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setPaused", SOCKETS_TCP_SETPAUSED) | 83 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setPaused", SOCKETS_TCP_SETPAUSED) |
| 84 | 84 |
| 85 SocketsTcpSetPausedFunction(); | 85 SocketsTcpSetPausedFunction(); |
| 86 | 86 |
| 87 protected: | 87 protected: |
| 88 ~SocketsTcpSetPausedFunction() override; | 88 ~SocketsTcpSetPausedFunction() override; |
| 89 | 89 |
| 90 // AsyncApiFunction | 90 // AsyncApiFunction |
| 91 bool Prepare() override; | 91 bool Prepare() override; |
| 92 void Work() override; | 92 void Work() override; |
| 93 | 93 |
| 94 private: | 94 private: |
| 95 scoped_ptr<sockets_tcp::SetPaused::Params> params_; | 95 std::unique_ptr<sockets_tcp::SetPaused::Params> params_; |
| 96 TCPSocketEventDispatcher* socket_event_dispatcher_; | 96 TCPSocketEventDispatcher* socket_event_dispatcher_; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 class SocketsTcpSetKeepAliveFunction : public TCPSocketAsyncApiFunction { | 99 class SocketsTcpSetKeepAliveFunction : public TCPSocketAsyncApiFunction { |
| 100 public: | 100 public: |
| 101 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setKeepAlive", | 101 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setKeepAlive", |
| 102 SOCKETS_TCP_SETKEEPALIVE) | 102 SOCKETS_TCP_SETKEEPALIVE) |
| 103 | 103 |
| 104 SocketsTcpSetKeepAliveFunction(); | 104 SocketsTcpSetKeepAliveFunction(); |
| 105 | 105 |
| 106 protected: | 106 protected: |
| 107 ~SocketsTcpSetKeepAliveFunction() override; | 107 ~SocketsTcpSetKeepAliveFunction() override; |
| 108 | 108 |
| 109 // AsyncApiFunction | 109 // AsyncApiFunction |
| 110 bool Prepare() override; | 110 bool Prepare() override; |
| 111 void Work() override; | 111 void Work() override; |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 scoped_ptr<sockets_tcp::SetKeepAlive::Params> params_; | 114 std::unique_ptr<sockets_tcp::SetKeepAlive::Params> params_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 class SocketsTcpSetNoDelayFunction : public TCPSocketAsyncApiFunction { | 117 class SocketsTcpSetNoDelayFunction : public TCPSocketAsyncApiFunction { |
| 118 public: | 118 public: |
| 119 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setNoDelay", SOCKETS_TCP_SETNODELAY) | 119 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setNoDelay", SOCKETS_TCP_SETNODELAY) |
| 120 | 120 |
| 121 SocketsTcpSetNoDelayFunction(); | 121 SocketsTcpSetNoDelayFunction(); |
| 122 | 122 |
| 123 protected: | 123 protected: |
| 124 ~SocketsTcpSetNoDelayFunction() override; | 124 ~SocketsTcpSetNoDelayFunction() override; |
| 125 | 125 |
| 126 // AsyncApiFunction | 126 // AsyncApiFunction |
| 127 bool Prepare() override; | 127 bool Prepare() override; |
| 128 void Work() override; | 128 void Work() override; |
| 129 | 129 |
| 130 private: | 130 private: |
| 131 scoped_ptr<sockets_tcp::SetNoDelay::Params> params_; | 131 std::unique_ptr<sockets_tcp::SetNoDelay::Params> params_; |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 class SocketsTcpConnectFunction | 134 class SocketsTcpConnectFunction |
| 135 : public TCPSocketExtensionWithDnsLookupFunction { | 135 : public TCPSocketExtensionWithDnsLookupFunction { |
| 136 public: | 136 public: |
| 137 DECLARE_EXTENSION_FUNCTION("sockets.tcp.connect", SOCKETS_TCP_CONNECT) | 137 DECLARE_EXTENSION_FUNCTION("sockets.tcp.connect", SOCKETS_TCP_CONNECT) |
| 138 | 138 |
| 139 SocketsTcpConnectFunction(); | 139 SocketsTcpConnectFunction(); |
| 140 | 140 |
| 141 protected: | 141 protected: |
| 142 ~SocketsTcpConnectFunction() override; | 142 ~SocketsTcpConnectFunction() override; |
| 143 | 143 |
| 144 // AsyncApiFunction: | 144 // AsyncApiFunction: |
| 145 bool Prepare() override; | 145 bool Prepare() override; |
| 146 void AsyncWorkStart() override; | 146 void AsyncWorkStart() override; |
| 147 | 147 |
| 148 // SocketExtensionWithDnsLookupFunction: | 148 // SocketExtensionWithDnsLookupFunction: |
| 149 void AfterDnsLookup(int lookup_result) override; | 149 void AfterDnsLookup(int lookup_result) override; |
| 150 | 150 |
| 151 private: | 151 private: |
| 152 void StartConnect(); | 152 void StartConnect(); |
| 153 void OnCompleted(int net_result); | 153 void OnCompleted(int net_result); |
| 154 | 154 |
| 155 scoped_ptr<sockets_tcp::Connect::Params> params_; | 155 std::unique_ptr<sockets_tcp::Connect::Params> params_; |
| 156 TCPSocketEventDispatcher* socket_event_dispatcher_; | 156 TCPSocketEventDispatcher* socket_event_dispatcher_; |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 class SocketsTcpDisconnectFunction : public TCPSocketAsyncApiFunction { | 159 class SocketsTcpDisconnectFunction : public TCPSocketAsyncApiFunction { |
| 160 public: | 160 public: |
| 161 DECLARE_EXTENSION_FUNCTION("sockets.tcp.disconnect", SOCKETS_TCP_DISCONNECT) | 161 DECLARE_EXTENSION_FUNCTION("sockets.tcp.disconnect", SOCKETS_TCP_DISCONNECT) |
| 162 | 162 |
| 163 SocketsTcpDisconnectFunction(); | 163 SocketsTcpDisconnectFunction(); |
| 164 | 164 |
| 165 protected: | 165 protected: |
| 166 ~SocketsTcpDisconnectFunction() override; | 166 ~SocketsTcpDisconnectFunction() override; |
| 167 | 167 |
| 168 // AsyncApiFunction: | 168 // AsyncApiFunction: |
| 169 bool Prepare() override; | 169 bool Prepare() override; |
| 170 void Work() override; | 170 void Work() override; |
| 171 | 171 |
| 172 private: | 172 private: |
| 173 scoped_ptr<sockets_tcp::Disconnect::Params> params_; | 173 std::unique_ptr<sockets_tcp::Disconnect::Params> params_; |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 class SocketsTcpSendFunction : public TCPSocketAsyncApiFunction { | 176 class SocketsTcpSendFunction : public TCPSocketAsyncApiFunction { |
| 177 public: | 177 public: |
| 178 DECLARE_EXTENSION_FUNCTION("sockets.tcp.send", SOCKETS_TCP_SEND) | 178 DECLARE_EXTENSION_FUNCTION("sockets.tcp.send", SOCKETS_TCP_SEND) |
| 179 | 179 |
| 180 SocketsTcpSendFunction(); | 180 SocketsTcpSendFunction(); |
| 181 | 181 |
| 182 protected: | 182 protected: |
| 183 ~SocketsTcpSendFunction() override; | 183 ~SocketsTcpSendFunction() override; |
| 184 | 184 |
| 185 // AsyncApiFunction: | 185 // AsyncApiFunction: |
| 186 bool Prepare() override; | 186 bool Prepare() override; |
| 187 void AsyncWorkStart() override; | 187 void AsyncWorkStart() override; |
| 188 | 188 |
| 189 private: | 189 private: |
| 190 void OnCompleted(int net_result); | 190 void OnCompleted(int net_result); |
| 191 void SetSendResult(int net_result, int bytes_sent); | 191 void SetSendResult(int net_result, int bytes_sent); |
| 192 | 192 |
| 193 scoped_ptr<sockets_tcp::Send::Params> params_; | 193 std::unique_ptr<sockets_tcp::Send::Params> params_; |
| 194 scoped_refptr<net::IOBuffer> io_buffer_; | 194 scoped_refptr<net::IOBuffer> io_buffer_; |
| 195 size_t io_buffer_size_; | 195 size_t io_buffer_size_; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 class SocketsTcpCloseFunction : public TCPSocketAsyncApiFunction { | 198 class SocketsTcpCloseFunction : public TCPSocketAsyncApiFunction { |
| 199 public: | 199 public: |
| 200 DECLARE_EXTENSION_FUNCTION("sockets.tcp.close", SOCKETS_TCP_CLOSE) | 200 DECLARE_EXTENSION_FUNCTION("sockets.tcp.close", SOCKETS_TCP_CLOSE) |
| 201 | 201 |
| 202 SocketsTcpCloseFunction(); | 202 SocketsTcpCloseFunction(); |
| 203 | 203 |
| 204 protected: | 204 protected: |
| 205 ~SocketsTcpCloseFunction() override; | 205 ~SocketsTcpCloseFunction() override; |
| 206 | 206 |
| 207 // AsyncApiFunction: | 207 // AsyncApiFunction: |
| 208 bool Prepare() override; | 208 bool Prepare() override; |
| 209 void Work() override; | 209 void Work() override; |
| 210 | 210 |
| 211 private: | 211 private: |
| 212 scoped_ptr<sockets_tcp::Close::Params> params_; | 212 std::unique_ptr<sockets_tcp::Close::Params> params_; |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 class SocketsTcpGetInfoFunction : public TCPSocketAsyncApiFunction { | 215 class SocketsTcpGetInfoFunction : public TCPSocketAsyncApiFunction { |
| 216 public: | 216 public: |
| 217 DECLARE_EXTENSION_FUNCTION("sockets.tcp.getInfo", SOCKETS_TCP_GETINFO) | 217 DECLARE_EXTENSION_FUNCTION("sockets.tcp.getInfo", SOCKETS_TCP_GETINFO) |
| 218 | 218 |
| 219 SocketsTcpGetInfoFunction(); | 219 SocketsTcpGetInfoFunction(); |
| 220 | 220 |
| 221 protected: | 221 protected: |
| 222 ~SocketsTcpGetInfoFunction() override; | 222 ~SocketsTcpGetInfoFunction() override; |
| 223 | 223 |
| 224 // AsyncApiFunction: | 224 // AsyncApiFunction: |
| 225 bool Prepare() override; | 225 bool Prepare() override; |
| 226 void Work() override; | 226 void Work() override; |
| 227 | 227 |
| 228 private: | 228 private: |
| 229 scoped_ptr<sockets_tcp::GetInfo::Params> params_; | 229 std::unique_ptr<sockets_tcp::GetInfo::Params> params_; |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 class SocketsTcpGetSocketsFunction : public TCPSocketAsyncApiFunction { | 232 class SocketsTcpGetSocketsFunction : public TCPSocketAsyncApiFunction { |
| 233 public: | 233 public: |
| 234 DECLARE_EXTENSION_FUNCTION("sockets.tcp.getSockets", SOCKETS_TCP_GETSOCKETS) | 234 DECLARE_EXTENSION_FUNCTION("sockets.tcp.getSockets", SOCKETS_TCP_GETSOCKETS) |
| 235 | 235 |
| 236 SocketsTcpGetSocketsFunction(); | 236 SocketsTcpGetSocketsFunction(); |
| 237 | 237 |
| 238 protected: | 238 protected: |
| 239 ~SocketsTcpGetSocketsFunction() override; | 239 ~SocketsTcpGetSocketsFunction() override; |
| 240 | 240 |
| 241 // AsyncApiFunction: | 241 // AsyncApiFunction: |
| 242 bool Prepare() override; | 242 bool Prepare() override; |
| 243 void Work() override; | 243 void Work() override; |
| 244 }; | 244 }; |
| 245 | 245 |
| 246 class SocketsTcpSecureFunction : public TCPSocketAsyncApiFunction { | 246 class SocketsTcpSecureFunction : public TCPSocketAsyncApiFunction { |
| 247 public: | 247 public: |
| 248 DECLARE_EXTENSION_FUNCTION("sockets.tcp.secure", SOCKETS_TCP_SECURE); | 248 DECLARE_EXTENSION_FUNCTION("sockets.tcp.secure", SOCKETS_TCP_SECURE); |
| 249 | 249 |
| 250 SocketsTcpSecureFunction(); | 250 SocketsTcpSecureFunction(); |
| 251 | 251 |
| 252 protected: | 252 protected: |
| 253 ~SocketsTcpSecureFunction() override; | 253 ~SocketsTcpSecureFunction() override; |
| 254 bool Prepare() override; | 254 bool Prepare() override; |
| 255 void AsyncWorkStart() override; | 255 void AsyncWorkStart() override; |
| 256 | 256 |
| 257 private: | 257 private: |
| 258 virtual void TlsConnectDone(scoped_ptr<extensions::TLSSocket> sock, | 258 virtual void TlsConnectDone(std::unique_ptr<extensions::TLSSocket> sock, |
| 259 int result); | 259 int result); |
| 260 | 260 |
| 261 bool paused_; | 261 bool paused_; |
| 262 bool persistent_; | 262 bool persistent_; |
| 263 scoped_ptr<sockets_tcp::Secure::Params> params_; | 263 std::unique_ptr<sockets_tcp::Secure::Params> params_; |
| 264 scoped_refptr<net::URLRequestContextGetter> url_request_getter_; | 264 scoped_refptr<net::URLRequestContextGetter> url_request_getter_; |
| 265 | 265 |
| 266 DISALLOW_COPY_AND_ASSIGN(SocketsTcpSecureFunction); | 266 DISALLOW_COPY_AND_ASSIGN(SocketsTcpSecureFunction); |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 } // namespace api | 269 } // namespace api |
| 270 } // namespace extensions | 270 } // namespace extensions |
| 271 | 271 |
| 272 #endif // EXTENSIONS_BROWSER_API_SOCKETS_TCP_SOCKETS_TCP_API_H_ | 272 #endif // EXTENSIONS_BROWSER_API_SOCKETS_TCP_SOCKETS_TCP_API_H_ |
| OLD | NEW |