Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "chrome/browser/extensions/api/socket/socket.h" | |
| 11 #include "chrome/browser/extensions/api/socket/socket_api.h" | |
| 12 #include "chrome/browser/extensions/api/socket/tcp_socket.h" | |
| 13 | |
| 14 namespace net { | |
| 15 class Socket; | |
| 16 } | |
| 17 | |
| 18 namespace extensions { | |
| 19 class TLSSocket; | |
| 20 typedef base::Callback<void(TLSSocket*, int)> SecureCallback; | |
|
Ryan Sleevi
2014/01/14 01:32:06
Does this make more sense as "scoped_ptr<TLSSocket
lally
2014/01/29 23:57:45
Yes, yes it does. Done.
| |
| 21 | |
| 22 // TLS Sockets from the chrome.socket API. A regular TCPSocket is converted | |
| 23 // to a TLSSocket via chrome.socket.secure() or chrome.sockets.tcp.secure(). | |
| 24 // The inheritance here is for interface API compatibility, not for | |
| 25 // implementation that comes with it. TLSSocket does not use its superclass's | |
| 26 // socket state, so all methods are overridden here to prevent any access of | |
| 27 // ResumableTCPSocket's socket state. | |
| 28 class TLSSocket : public ResumableTCPSocket { | |
| 29 public: | |
| 30 TLSSocket(net::StreamSocket* tls_socket, | |
| 31 const std::string& owner_extension_id); | |
| 32 | |
| 33 virtual ~TLSSocket(); | |
| 34 | |
| 35 // Most of these methods either fail or forward the method call on to the | |
| 36 // inner net::StreamSocket. The remaining few do actual TLS work. | |
| 37 | |
| 38 // Fails. | |
| 39 virtual void Connect(const std::string& address, | |
| 40 int port, | |
| 41 const CompletionCallback& callback) OVERRIDE; | |
| 42 // Forwards. | |
| 43 virtual void Disconnect() OVERRIDE; | |
| 44 | |
| 45 // The |callback| will be called with the number of bytes read into the | |
| 46 // buffer, or a negative number if an error occurred. Does TLS work. | |
| 47 virtual void Read(int count, | |
| 48 const ReadCompletionCallback& callback) OVERRIDE; | |
| 49 | |
| 50 // Fails. This should have been called on the TCP socket before secure() was | |
| 51 // invoked. | |
| 52 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; | |
| 53 | |
| 54 // Fails. This should have been called on the TCP socket before secure() was | |
| 55 // invoked. | |
| 56 virtual bool SetNoDelay(bool no_delay) OVERRIDE; | |
| 57 | |
| 58 // Fails. TLSSocket is only a client. | |
| 59 virtual int Listen(const std::string& address, int port, int backlog, | |
| 60 std::string* error_msg) OVERRIDE; | |
| 61 // Fails. TLSSocket is only a client. | |
| 62 virtual void Accept(const AcceptCompletionCallback &callback) OVERRIDE; | |
| 63 | |
| 64 // Forwards. | |
| 65 virtual bool IsConnected() OVERRIDE; | |
| 66 | |
| 67 // Forwards. | |
| 68 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; | |
| 69 // Forwards. | |
| 70 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; | |
| 71 | |
| 72 // Returns TYPE_TLS. | |
| 73 virtual SocketType GetSocketType() const OVERRIDE; | |
| 74 | |
| 75 // Convert the given |socket| to a TLS socket. Works only for TCP sockets. | |
| 76 // Must be invoked in the IO thread. |callback| will always be invoked. | |
| 77 // |profile| and |url_request_getter| must live at least until |callback| | |
| 78 // is invoked. |callback| is always invoked. Note: |callback| may get | |
|
Ryan Sleevi
2014/01/14 01:32:06
nit: unnecessary extra space ;)
"Note: |callback|
lally
2014/01/29 23:57:45
Note: |callback| may be invoked, synchronously, be
| |
| 79 // invoked before UpgradeSocketToTLS returns. | |
| 80 static void UpgradeSocketToTLS( | |
| 81 Socket* socket, | |
| 82 Profile* profile, | |
| 83 net::URLRequestContextGetter* url_request_getter, | |
| 84 const std::string& extension_id, | |
| 85 api::socket::SecureOptions* options, | |
| 86 const SecureCallback& callback); | |
| 87 | |
| 88 private: | |
| 89 virtual int WriteImpl(net::IOBuffer* io_buffer, | |
| 90 int io_buffer_size, | |
| 91 const net::CompletionCallback& callback) OVERRIDE; | |
| 92 void OnReadComplete(const scoped_refptr<net::IOBuffer>& io_buffer, | |
| 93 int result); | |
| 94 | |
| 95 static void TlsConnectDone(net::SSLClientSocket* ssl_socket, | |
| 96 const std::string& extension_id, | |
| 97 const SecureCallback& callback, | |
| 98 int result); | |
| 99 | |
| 100 scoped_ptr<net::StreamSocket> tls_socket_; | |
| 101 ReadCompletionCallback read_callback_; | |
| 102 }; | |
| 103 | |
| 104 } // namespace extensions | |
| 105 | |
| 106 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_ | |
| OLD | NEW |