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

Unified 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: Fixing another cross-platform build issue (try 2) Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/socket/tls_socket.h
diff --git a/chrome/browser/extensions/api/socket/tls_socket.h b/chrome/browser/extensions/api/socket/tls_socket.h
new file mode 100644
index 0000000000000000000000000000000000000000..fa5efcd1ac9916d42562e37f2a6d85ef2b0e38b2
--- /dev/null
+++ b/chrome/browser/extensions/api/socket/tls_socket.h
@@ -0,0 +1,93 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_
+#define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_
+
+#include <string>
+
+#include "chrome/browser/extensions/api/socket/socket.h"
+
+namespace net {
+class Socket;
+}
+
+namespace extensions {
+
+// TLS Sockets from the chrome.socket API. A regular TCPSocket is converted
+// to a TLSSocket via chrome.socket.secure().
+class TLSSocket : public Socket {
+ public:
+ TLSSocket(net::StreamSocket* tls_socket,
+ net::TCPClientSocket* underlying_tcp_socket,
+ const std::string& owner_extension_id);
+
+ virtual ~TLSSocket();
+
+ // Most of these methods either fail or forward the method call on to the
+ // inner net::StreamSocket. The remaining few do actual TLS work.
Ryan Sleevi 2013/11/25 17:30:13 This definitely violates the SOLID design of is-a
Lally Singh 2013/12/05 17:07:12 No disagreement here, but this is an artifact of s
+
+ // Fails.
+ virtual void Connect(const std::string& address,
+ int port,
+ const CompletionCallback& callback) OVERRIDE;
+ // Forwards.
+ virtual void Disconnect() OVERRIDE;
+
+ // Fails.
+ virtual int Bind(const std::string& address, int port) OVERRIDE;
+
+ // The |callback| will be called with the number of bytes read into the
+ // buffer, or a negative number if an error occurred. Does TLS work.
+ virtual void Read(int count,
+ const ReadCompletionCallback& callback) OVERRIDE;
+
+ // Fails.
+ virtual void RecvFrom(int count,
+ const RecvFromCompletionCallback& callback) OVERRIDE;
+ // Fails.
+ virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer,
+ int byte_count,
+ const std::string& address,
+ int port,
+ const CompletionCallback& callback) OVERRIDE;
+
+ // Forwards.
+ virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE;
+
+ // Forwards.
+ virtual bool SetNoDelay(bool no_delay) OVERRIDE;
+
+ // Fails.
+ virtual int Listen(const std::string& address, int port, int backlog,
+ std::string* error_msg) OVERRIDE;
+ // Fails.
+ virtual void Accept(const AcceptCompletionCallback &callback) OVERRIDE;
+
+ // Forwards.
+ virtual bool IsConnected() OVERRIDE;
+
+ // Forwards.
+ virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE;
+ // Forwards.
+ virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE;
+
+ // Forwards.
+ virtual SocketType GetSocketType() const OVERRIDE;
+
+ private:
+ virtual int WriteImpl(net::IOBuffer* io_buffer, int io_buffer_size,
+ const net::CompletionCallback& callback) OVERRIDE;
+ void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer,
+ int result);
+
+ scoped_ptr<net::StreamSocket> tls_socket_;
+ scoped_ptr<net::TCPClientSocket> underlying_socket_;
+
+ ReadCompletionCallback read_callback_;
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TLS_SOCKET_H_

Powered by Google App Engine
This is Rietveld 408576698