Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: chrome/browser/extensions/api/socket/tls_socket.h

Issue 76403004: An implementation of chrome.socket.secure(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added a check on whether the socket to be TLS'd has a pending read. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "net/ssl/ssl_config_service.h"
14
15 namespace net {
16 class Socket;
17 }
18
19 namespace extensions {
20 class TLSSocket;
21 typedef base::Callback<void(scoped_ptr<TLSSocket>, int)> SecureCallback;
22
23 // TLS Sockets from the chrome.socket API. A regular TCPSocket is converted
24 // to a TLSSocket via chrome.socket.secure() or chrome.sockets.tcp.secure().
25 // The inheritance here is for interface API compatibility, not for
26 // implementation that comes with it. TLSSocket does not use its superclass's
27 // socket state, so all methods are overridden here to prevent any access of
28 // ResumableTCPSocket's socket state.
29 class TLSSocket : public ResumableTCPSocket {
30 public:
31 TLSSocket(scoped_ptr<net::StreamSocket> tls_socket,
32 const std::string& owner_extension_id);
33
34 virtual ~TLSSocket();
35
36 // Most of these methods either fail or forward the method call on to the
37 // inner net::StreamSocket. The remaining few do actual TLS work.
38
39 // Fails.
40 virtual void Connect(const std::string& address,
41 int port,
42 const CompletionCallback& callback) OVERRIDE;
43 // Forwards.
44 virtual void Disconnect() OVERRIDE;
45
46 // The |callback| will be called with the number of bytes read into the
47 // buffer, or a negative number if an error occurred. Does TLS work.
48 virtual void Read(int count, 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,
60 int port,
61 int backlog,
62 std::string* error_msg) OVERRIDE;
63 // Fails. TLSSocket is only a client.
64 virtual void Accept(const AcceptCompletionCallback& callback) OVERRIDE;
65
66 // Forwards.
67 virtual bool IsConnected() OVERRIDE;
68
69 // Forwards.
70 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE;
71 // Forwards.
72 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE;
73
74 // Returns TYPE_TLS.
75 virtual SocketType GetSocketType() const OVERRIDE;
76
77 // Convert the given |socket| to a TLS socket. Works only for TCP sockets.
78 // Must be invoked in the IO thread. |callback| will always be invoked.
79 // |profile| and |url_request_getter| must live at least until |callback|
80 // is invoked. |callback| is always invoked. Note: |callback| may be
81 // invoked, synchronously, before UpgradeSocketToTLS returns.
82 static void UpgradeSocketToTLS(
83 Socket* socket,
84 scoped_refptr<net::SSLConfigService> config_service,
85 scoped_refptr<net::URLRequestContextGetter> url_request_getter,
86 const std::string& extension_id,
87 api::socket::SecureOptions* options,
88 const SecureCallback& callback);
89
90 private:
91 virtual int WriteImpl(net::IOBuffer* io_buffer,
92 int io_buffer_size,
93 const net::CompletionCallback& callback) OVERRIDE;
94 void OnReadComplete(const scoped_refptr<net::IOBuffer>& io_buffer,
95 int result);
96
97 static void TlsConnectDone(scoped_ptr<net::SSLClientSocket> ssl_socket,
98 const std::string& extension_id,
99 const SecureCallback& callback,
100 int result);
101
102 scoped_ptr<net::StreamSocket> tls_socket_;
103 ReadCompletionCallback read_callback_;
104 };
105
106 } // namespace extensions
107
108 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698