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 typedef base::Callback<void(Socket*, int)> SecureCallback; | |
rpaquay
2013/12/09 23:02:03
Should "Socket*" be "TLSSocket*"?
lally
2013/12/12 02:31:39
Done.
| |
20 | |
21 // TLS Sockets from the chrome.socket API. A regular TCPSocket is converted | |
22 // to a TLSSocket via chrome.socket.secure() or chrome.sockets.tcp.secure(). | |
23 // The inheritance here is for interface API compatibility, not for | |
24 // implementation that comes with it. We override methods to prevent | |
25 // behavioral leakage from the underlying implementation. | |
26 class TLSSocket : public ResumableTCPSocket { | |
27 public: | |
28 TLSSocket(net::StreamSocket* tls_socket, | |
29 const std::string& owner_extension_id); | |
30 | |
31 virtual ~TLSSocket(); | |
32 | |
33 // Most of these methods either fail or forward the method call on to the | |
34 // inner net::StreamSocket. The remaining few do actual TLS work. | |
35 | |
36 // Fails. | |
37 virtual void Connect(const std::string& address, | |
38 int port, | |
39 const CompletionCallback& callback) OVERRIDE; | |
40 // Forwards. | |
41 virtual void Disconnect() OVERRIDE; | |
42 | |
43 // The |callback| will be called with the number of bytes read into the | |
44 // buffer, or a negative number if an error occurred. Does TLS work. | |
45 virtual void Read(int count, | |
46 const ReadCompletionCallback& callback) OVERRIDE; | |
47 | |
48 // Fails. This should have been called on the TCP socket before secure() was | |
49 // invoked. | |
50 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; | |
51 | |
52 // Fails. This should have been called on the TCP socket before secure() was | |
53 // invoked. | |
54 virtual bool SetNoDelay(bool no_delay) OVERRIDE; | |
55 | |
56 // Fails. TLSSocket is only a client. | |
57 virtual int Listen(const std::string& address, int port, int backlog, | |
58 std::string* error_msg) OVERRIDE; | |
59 // Fails. TLSSocket is only a client. | |
60 virtual void Accept(const AcceptCompletionCallback &callback) OVERRIDE; | |
61 | |
62 // Forwards. | |
63 virtual bool IsConnected() OVERRIDE; | |
64 | |
65 // Forwards. | |
66 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; | |
67 // Forwards. | |
68 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; | |
69 | |
70 // Returns TYPE_TLS. | |
71 virtual SocketType GetSocketType() const OVERRIDE; | |
72 | |
73 // Convert the given |socket| to a TLS socket. Works only for TCP sockets. | |
74 // Must be invoked in the IO thread. Returns an error string upon error | |
75 // (which also mutates |*result|), or NULL if the final result will come | |
76 // from an invocation to |callback|. Note: |callback| may get invoked | |
77 // before SecureTCPSocket returns. | |
78 static const char* SecureTCPSocket( | |
79 Socket* socket, | |
80 Profile* profile, | |
81 net::URLRequestContextGetter* url_request_getter, | |
82 const std::string& extension_id, | |
83 api::socket::SecureOptions* options, | |
84 SecureCallback callback, | |
85 base::Value** result); | |
86 | |
87 private: | |
88 virtual int WriteImpl(net::IOBuffer* io_buffer, int io_buffer_size, | |
89 const net::CompletionCallback& callback) OVERRIDE; | |
90 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result); | |
91 | |
92 scoped_ptr<net::StreamSocket> tls_socket_; | |
93 | |
94 ReadCompletionCallback read_callback_; | |
95 }; | |
96 | |
97 } // namespace extensions | |
98 | |
99 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_ | |
OLD | NEW |