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

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: Another round of responses to Renaud. Created 7 years 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
14 namespace net {
15 class Socket;
16 }
17
18 namespace extensions {
19 class TLSSocket;
20 typedef base::Callback<void(TLSSocket*, int)> SecureCallback;
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. We override methods to prevent
26 // behavioral leakage from the underlying implementation.
Ryan Sleevi 2013/12/17 00:37:40 style nit: single space after a period, not double
lally 2014/01/09 18:47:16 Fixed, with a re-written last sentence.
27 class TLSSocket : public ResumableTCPSocket {
28 public:
29 TLSSocket(net::StreamSocket* tls_socket,
30 const std::string& owner_extension_id);
31
32 virtual ~TLSSocket();
33
34 // Most of these methods either fail or forward the method call on to the
35 // inner net::StreamSocket. The remaining few do actual TLS work.
36
37 // Fails.
38 virtual void Connect(const std::string& address,
39 int port,
40 const CompletionCallback& callback) OVERRIDE;
Ryan Sleevi 2013/12/17 00:37:40 This still heavily rankles my design sentiments, b
lally 2014/01/09 18:47:16 I don't know how to get around this issue without
41 // Forwards.
42 virtual void Disconnect() OVERRIDE;
43
44 // The |callback| will be called with the number of bytes read into the
45 // buffer, or a negative number if an error occurred. Does TLS work.
46 virtual void Read(int count,
47 const ReadCompletionCallback& callback) OVERRIDE;
48
49 // Fails. This should have been called on the TCP socket before secure() was
50 // invoked.
51 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE;
52
53 // Fails. This should have been called on the TCP socket before secure() was
54 // invoked.
55 virtual bool SetNoDelay(bool no_delay) OVERRIDE;
56
57 // Fails. TLSSocket is only a client.
58 virtual int Listen(const std::string& address, int port, int backlog,
59 std::string* error_msg) OVERRIDE;
60 // Fails. TLSSocket is only a client.
61 virtual void Accept(const AcceptCompletionCallback &callback) OVERRIDE;
62
63 // Forwards.
64 virtual bool IsConnected() OVERRIDE;
65
66 // Forwards.
67 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE;
68 // Forwards.
69 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE;
70
71 // Returns TYPE_TLS.
72 virtual SocketType GetSocketType() const OVERRIDE;
73
74 // Convert the given |socket| to a TLS socket. Works only for TCP sockets.
75 // Must be invoked in the IO thread. |callback| will always be invoked.
76 // Note: |callback| may get invoked before SecureTCPSocket returns.
77 static void SecureTCPSocket(
78 Socket* socket,
79 Profile* profile,
80 net::URLRequestContextGetter* url_request_getter,
81 const std::string& extension_id,
82 api::socket::SecureOptions* options,
83 SecureCallback callback);
Ryan Sleevi 2013/12/17 00:37:40 style nit: four space indent comment nit: Explain
lally 2014/01/09 18:47:16 I chose UpgradeSocketToTLS, to avoid having Socket
84
85 private:
86 virtual int WriteImpl(net::IOBuffer* io_buffer, int io_buffer_size,
87 const net::CompletionCallback& callback) OVERRIDE;
Ryan Sleevi 2013/12/17 00:37:40 style: line breaks - http://www.chromium.org/devel
lally 2014/01/09 18:47:16 Done.
88 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result);
Ryan Sleevi 2013/12/17 00:37:40 style nit: "scoped_refptr<net::IOBuffer>" -> "cons
lally 2014/01/09 18:47:16 Done.
89
90 scoped_ptr<net::StreamSocket> tls_socket_;
91
92 ReadCompletionCallback read_callback_;
93 };
94
95 } // namespace extensions
96
97 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698