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

Side by Side Diff: extensions/browser/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: Tiny, tiny, tiny changes to clean up the diffs post-rebase. 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 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 "extensions/browser/api/socket/socket.h"
11 #include "extensions/browser/api/socket/socket_api.h"
12 #include "extensions/browser/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 and chrome.socket.tcp APIs. A regular
24 // TCPSocket is converted to a TLSSocket via chrome.socket.secure() or
25 // chrome.sockets.tcp.secure(). The inheritance here is for interface API
26 // compatibility, not for the implementation that comes with it. TLSSocket
27 // does not use its superclass's socket state, so all methods are overridden
28 // here to prevent any access of ResumableTCPSocket's socket state. Except
29 // for the implementation of a write queue in Socket::Write() (a super-super
30 // class of ResumableTCPSocket). That implementation only queues and
31 // serializes invocations to WriteImpl(), implemented here, and does not
32 // touch any socket state.
33 class TLSSocket : public ResumableTCPSocket {
34 public:
35 TLSSocket(scoped_ptr<net::StreamSocket> tls_socket,
36 const std::string& owner_extension_id);
37
38 virtual ~TLSSocket();
39
40 // Most of these methods either fail or forward the method call on to the
41 // inner net::StreamSocket. The remaining few do actual TLS work.
42
43 // Fails.
44 virtual void Connect(const std::string& address,
45 int port,
46 const CompletionCallback& callback) OVERRIDE;
47 // Forwards.
48 virtual void Disconnect() OVERRIDE;
49
50 // The |callback| will be called with the number of bytes read into the
51 // buffer, or a negative number if an error occurred. Does TLS work.
52 virtual void Read(int count, const ReadCompletionCallback& callback) OVERRIDE;
53
54 // Fails. This should have been called on the TCP socket before secure() was
55 // invoked.
56 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE;
57
58 // Fails. This should have been called on the TCP socket before secure() was
59 // invoked.
60 virtual bool SetNoDelay(bool no_delay) OVERRIDE;
61
62 // Fails. TLSSocket is only a client.
63 virtual int Listen(const std::string& address,
64 int port,
65 int backlog,
66 std::string* error_msg) OVERRIDE;
67
68 // Fails. TLSSocket is only a client.
69 virtual void Accept(const AcceptCompletionCallback& callback) OVERRIDE;
70
71 // Forwards.
72 virtual bool IsConnected() OVERRIDE;
73
74 // Forwards.
75 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE;
76 // Forwards.
77 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE;
78
79 // Returns TYPE_TLS.
80 virtual SocketType GetSocketType() const OVERRIDE;
81
82 // Convert |socket| to a TLS socket. |socket| must be an open TCP client
83 // socket. |socket| must not have a pending read. UpgradeSocketToTLS() must
84 // be invoked in the IO thread. |callback| will always be invoked. |options|
85 // may be NULL. Note: |callback| may be synchronously invoked before
86 // UpgradeSocketToTLS() returns. Currently using the older chrome.socket
87 // version of SecureOptions, to avoid having the older API implementation
88 // depend on the newer one.
89 static void UpgradeSocketToTLS(
90 Socket* socket,
91 scoped_refptr<net::SSLConfigService> config_service,
92 scoped_refptr<net::URLRequestContextGetter> url_request_getter,
Ryan Sleevi 2014/03/26 19:57:40 DESIGN: Apologies that I just now noticed this (th
lally 2014/03/28 16:22:51 No worries; Done. In the future I'll have to start
93 const std::string& extension_id,
94 core_api::socket::SecureOptions* options,
95 const SecureCallback& callback);
96
97 private:
98 virtual int WriteImpl(net::IOBuffer* io_buffer,
99 int io_buffer_size,
100 const net::CompletionCallback& callback) OVERRIDE;
101
102 void OnReadComplete(const scoped_refptr<net::IOBuffer>& io_buffer,
103 int result);
104
105 static void TlsConnectDone(scoped_ptr<net::SSLClientSocket> ssl_socket,
106 const std::string& extension_id,
107 const SecureCallback& callback,
108 int result);
109
110 scoped_ptr<net::StreamSocket> tls_socket_;
111 ReadCompletionCallback read_callback_;
112 };
113
114 } // namespace extensions
115
116 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/socket/tcp_socket.cc ('k') | extensions/browser/api/socket/tls_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698