Index: extensions/browser/api/socket/passthrough.h |
diff --git a/extensions/browser/api/socket/passthrough.h b/extensions/browser/api/socket/passthrough.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4577b9fa117e73a563d61da99fa87bb484818a60 |
--- /dev/null |
+++ b/extensions/browser/api/socket/passthrough.h |
@@ -0,0 +1,129 @@ |
+// Copyright 2015 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 EXTENSIONS_BROWSER_API_SOCKET_PASSTHROUGH_H_ |
+#define EXTENSIONS_BROWSER_API_SOCKET_PASSTHROUGH_H_ |
+ |
+#include "net/socket/stream_socket.h" |
+ |
+namespace extensions { |
+ |
+// Specialize this template to initialize Base when it doesn't have a default |
+// constructor. |
+template <class Base> |
+class DefaultInitializer : public Base { |
+ public: |
+ DefaultInitializer() : Base() {} |
+}; |
+ |
+// An implementation of net::StreamSocket's API that passes all calls to an |
+// instance given at initialization. BaseSocket must be net::StreamSocket or |
+// have it as an ancestor. |
+template <class BaseSocket> |
+class Passthrough : public DefaultInitializer<BaseSocket> { |
Ken Rockot(use gerrit already)
2015/12/15 17:17:48
I am generally not happy with this approach. It sa
|
+ public: |
+ explicit Passthrough(scoped_ptr<BaseSocket> impl) |
+ : base_socket_(impl.Pass()) {} |
Ken Rockot(use gerrit already)
2015/12/15 17:17:48
nit: (everywhere) New code should use std::move in
|
+ |
+ ~Passthrough() override {} |
+ |
+ // net::StreamSocket pass-through implementation. |
+ int Connect(const CompletionCallback& callback) override { |
+ return base_socket_->Connect(callback); |
+ } |
+ |
+ void Disconnect() override { base_socket_->Disconnect(); } |
+ |
+ bool IsConnected() const override { return base_socket_->IsConnected(); } |
+ |
+ bool IsConnectedAndIdle() const override { |
+ return base_socket_->IsConnectedAndIdle(); |
+ } |
+ |
+ int GetPeerAddress(net::IPEndPoint* address) const override { |
+ return base_socket_->GetPeerAddress(address); |
+ } |
+ |
+ int GetLocalAddress(net::IPEndPoint* address) const override { |
+ return base_socket_->GetLocalAddress(address); |
+ } |
+ |
+ // Gets the NetLog for this socket. |
+ const net::BoundNetLog& NetLog() const override { |
+ return base_socket_->NetLog(); |
+ } |
+ |
+ void SetSubresourceSpeculation() override { |
+ return base_socket_->SetSubresourceSpeculation(); |
+ } |
+ |
+ void SetOmniboxSpeculation() override { |
+ base_socket_->SetOmniboxSpeculation(); |
+ } |
+ |
+ bool WasEverUsed() const override { return base_socket_->WasEverUsed(); } |
+ |
+ bool UsingTCPFastOpen() const override { |
+ return base_socket_->UsingTCPFastOpen(); |
+ } |
+ |
+ void EnableTCPFastOpenIfSupported() override { |
+ base_socket_->EnableTCPFastOpenIfSupported(); |
+ } |
+ |
+ bool WasNpnNegotiated() const override { |
+ return base_socket_->WasNpnNegotiated(); |
+ } |
+ |
+ net::NextProto GetNegotiatedProtocol() const override { |
+ return base_socket_->GetNegotiatedProtocol(); |
+ } |
+ |
+ bool GetSSLInfo(net::SSLInfo* ssl_info) override { |
+ return base_socket_->GetSSLInfo(ssl_info); |
+ } |
+ |
+ void GetConnectionAttempts(net::ConnectionAttempts* out) const override { |
+ base_socket_->GetConnectionAttempts(out); |
+ } |
+ |
+ void ClearConnectionAttempts() override { |
+ base_socket_->ClearConnectionAttempts(); |
+ } |
+ |
+ void AddConnectionAttempts(const net::ConnectionAttempts& attempts) override { |
+ base_socket_->AddConnectionAttempts(attempts); |
+ } |
+ |
+ // net::Socket pass-through implementation |
+ int Read(net::IOBuffer* buf, |
+ int buf_len, |
+ const CompletionCallback& callback) override { |
+ return base_socket_->Read(buf, buf_len, callback); |
+ } |
+ |
+ int Write(net::IOBuffer* buf, |
+ int buf_len, |
+ const CompletionCallback& callback) override { |
+ return base_socket_->Write(buf, buf_len, callback); |
+ } |
+ |
+ int SetReceiveBufferSize(int32 size) override { |
+ return base_socket_->SetReceiveBufferSize(size); |
+ } |
+ |
+ int SetSendBufferSize(int32 size) override { |
+ return base_socket_->SetSendBufferSize(size); |
+ } |
+ |
+ protected: |
+ BaseSocket* base_socket() { return base_socket_.get(); } |
+ |
+ private: |
+ scoped_ptr<BaseSocket> base_socket_; |
+}; |
+ |
+} // namespace extensions |
+ |
+#endif // EXTENSIONS_BROWSER_API_SOCKET_PASSTHROUGH_H_ |