Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 EXTENSIONS_BROWSER_API_SOCKET_PASSTHROUGH_H_ | |
| 6 #define EXTENSIONS_BROWSER_API_SOCKET_PASSTHROUGH_H_ | |
| 7 | |
| 8 #include "net/socket/stream_socket.h" | |
| 9 | |
| 10 namespace extensions { | |
| 11 | |
| 12 // Specialize this template to initialize Base when it doesn't have a default | |
| 13 // constructor. | |
| 14 template <class Base> | |
| 15 class DefaultInitializer : public Base { | |
| 16 public: | |
| 17 DefaultInitializer() : Base() {} | |
| 18 }; | |
| 19 | |
| 20 // An implementation of net::StreamSocket's API that passes all calls to an | |
| 21 // instance given at initialization. BaseSocket must be net::StreamSocket or | |
| 22 // have it as an ancestor. | |
| 23 template <class BaseSocket> | |
| 24 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
| |
| 25 public: | |
| 26 explicit Passthrough(scoped_ptr<BaseSocket> impl) | |
| 27 : base_socket_(impl.Pass()) {} | |
|
Ken Rockot(use gerrit already)
2015/12/15 17:17:48
nit: (everywhere) New code should use std::move in
| |
| 28 | |
| 29 ~Passthrough() override {} | |
| 30 | |
| 31 // net::StreamSocket pass-through implementation. | |
| 32 int Connect(const CompletionCallback& callback) override { | |
| 33 return base_socket_->Connect(callback); | |
| 34 } | |
| 35 | |
| 36 void Disconnect() override { base_socket_->Disconnect(); } | |
| 37 | |
| 38 bool IsConnected() const override { return base_socket_->IsConnected(); } | |
| 39 | |
| 40 bool IsConnectedAndIdle() const override { | |
| 41 return base_socket_->IsConnectedAndIdle(); | |
| 42 } | |
| 43 | |
| 44 int GetPeerAddress(net::IPEndPoint* address) const override { | |
| 45 return base_socket_->GetPeerAddress(address); | |
| 46 } | |
| 47 | |
| 48 int GetLocalAddress(net::IPEndPoint* address) const override { | |
| 49 return base_socket_->GetLocalAddress(address); | |
| 50 } | |
| 51 | |
| 52 // Gets the NetLog for this socket. | |
| 53 const net::BoundNetLog& NetLog() const override { | |
| 54 return base_socket_->NetLog(); | |
| 55 } | |
| 56 | |
| 57 void SetSubresourceSpeculation() override { | |
| 58 return base_socket_->SetSubresourceSpeculation(); | |
| 59 } | |
| 60 | |
| 61 void SetOmniboxSpeculation() override { | |
| 62 base_socket_->SetOmniboxSpeculation(); | |
| 63 } | |
| 64 | |
| 65 bool WasEverUsed() const override { return base_socket_->WasEverUsed(); } | |
| 66 | |
| 67 bool UsingTCPFastOpen() const override { | |
| 68 return base_socket_->UsingTCPFastOpen(); | |
| 69 } | |
| 70 | |
| 71 void EnableTCPFastOpenIfSupported() override { | |
| 72 base_socket_->EnableTCPFastOpenIfSupported(); | |
| 73 } | |
| 74 | |
| 75 bool WasNpnNegotiated() const override { | |
| 76 return base_socket_->WasNpnNegotiated(); | |
| 77 } | |
| 78 | |
| 79 net::NextProto GetNegotiatedProtocol() const override { | |
| 80 return base_socket_->GetNegotiatedProtocol(); | |
| 81 } | |
| 82 | |
| 83 bool GetSSLInfo(net::SSLInfo* ssl_info) override { | |
| 84 return base_socket_->GetSSLInfo(ssl_info); | |
| 85 } | |
| 86 | |
| 87 void GetConnectionAttempts(net::ConnectionAttempts* out) const override { | |
| 88 base_socket_->GetConnectionAttempts(out); | |
| 89 } | |
| 90 | |
| 91 void ClearConnectionAttempts() override { | |
| 92 base_socket_->ClearConnectionAttempts(); | |
| 93 } | |
| 94 | |
| 95 void AddConnectionAttempts(const net::ConnectionAttempts& attempts) override { | |
| 96 base_socket_->AddConnectionAttempts(attempts); | |
| 97 } | |
| 98 | |
| 99 // net::Socket pass-through implementation | |
| 100 int Read(net::IOBuffer* buf, | |
| 101 int buf_len, | |
| 102 const CompletionCallback& callback) override { | |
| 103 return base_socket_->Read(buf, buf_len, callback); | |
| 104 } | |
| 105 | |
| 106 int Write(net::IOBuffer* buf, | |
| 107 int buf_len, | |
| 108 const CompletionCallback& callback) override { | |
| 109 return base_socket_->Write(buf, buf_len, callback); | |
| 110 } | |
| 111 | |
| 112 int SetReceiveBufferSize(int32 size) override { | |
| 113 return base_socket_->SetReceiveBufferSize(size); | |
| 114 } | |
| 115 | |
| 116 int SetSendBufferSize(int32 size) override { | |
| 117 return base_socket_->SetSendBufferSize(size); | |
| 118 } | |
| 119 | |
| 120 protected: | |
| 121 BaseSocket* base_socket() { return base_socket_.get(); } | |
| 122 | |
| 123 private: | |
| 124 scoped_ptr<BaseSocket> base_socket_; | |
| 125 }; | |
| 126 | |
| 127 } // namespace extensions | |
| 128 | |
| 129 #endif // EXTENSIONS_BROWSER_API_SOCKET_PASSTHROUGH_H_ | |
| OLD | NEW |