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

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: After Renaud's comments. Added a secure() to sockets.tcp. 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.
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;
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 // |url_request_getter| is Released() in this call. Note: |callback| may
rpaquay 2013/12/16 20:18:46 It is not clear to me why "url_request_getter" nee
lally 2013/12/16 22:20:07 Good point. I've moved the Release() call to the
77 // get invoked before SecureTCPSocket returns.
78 static void 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
86 private:
87 virtual int WriteImpl(net::IOBuffer* io_buffer, int io_buffer_size,
88 const net::CompletionCallback& callback) OVERRIDE;
89 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result);
90
91 scoped_ptr<net::StreamSocket> tls_socket_;
92
93 ReadCompletionCallback read_callback_;
94 };
95
96 } // namespace extensions
97
98 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698