Skip to content

Commit

Permalink
Add a new GetNegotiatedProtocol method to StreamSocket and implement …
Browse files Browse the repository at this point in the history
…in all subclasses.

BUG=120890

Review URL: https://chromiumcodereview.appspot.com/9958028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130388 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rch@chromium.org committed Apr 3, 2012
1 parent 10abb58 commit 33661e4
Show file tree
Hide file tree
Showing 42 changed files with 150 additions and 26 deletions.
5 changes: 5 additions & 0 deletions content/browser/renderer_host/p2p/socket_host_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class FakeSocket : public net::StreamSocket {
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE;

private:
bool read_pending_;
Expand Down Expand Up @@ -219,6 +220,10 @@ base::TimeDelta FakeSocket::GetConnectTimeMicros() const {
return base::TimeDelta::FromMicroseconds(-1);
}

net::NextProto FakeSocket::GetNegotiatedProtocol() const {
return net::kProtoUnknown;
}

void CreateRandomPacket(std::vector<char>* packet) {
size_t size = kStunHeaderSize + rand() % 1000;
packet->resize(size);
Expand Down
5 changes: 5 additions & 0 deletions jingle/glue/pseudotcp_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,11 @@ base::TimeDelta PseudoTcpAdapter::GetConnectTimeMicros() const {
return base::TimeDelta::FromMicroseconds(-1);
}

net::NextProto PseudoTcpAdapter::GetNegotiatedProtocol() const {
DCHECK(CalledOnValidThread());
return net::kProtoUnknown;
}

void PseudoTcpAdapter::SetAckDelay(int delay_ms) {
DCHECK(CalledOnValidThread());
core_->SetAckDelay(delay_ms);
Expand Down
3 changes: 2 additions & 1 deletion jingle/glue/pseudotcp_adapter.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.

Expand Down Expand Up @@ -51,6 +51,7 @@ class PseudoTcpAdapter : public net::StreamSocket, base::NonThreadSafe {
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE;

// Set the delay for sending ACK.
void SetAckDelay(int delay_ms);
Expand Down
6 changes: 5 additions & 1 deletion jingle/notifier/base/fake_ssl_client_socket.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.

Expand Down Expand Up @@ -338,4 +338,8 @@ base::TimeDelta FakeSSLClientSocket::GetConnectTimeMicros() const {
return transport_socket_->GetConnectTimeMicros();
}

net::NextProto FakeSSLClientSocket::GetNegotiatedProtocol() const {
return transport_socket_->GetNegotiatedProtocol();
}

} // namespace notifier
3 changes: 2 additions & 1 deletion jingle/notifier/base/fake_ssl_client_socket.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.
//
Expand Down Expand Up @@ -65,6 +65,7 @@ class FakeSSLClientSocket : public net::StreamSocket {
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE;

private:
enum HandshakeState {
Expand Down
1 change: 1 addition & 0 deletions jingle/notifier/base/fake_ssl_client_socket_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MockClientSocket : public net::StreamSocket {
MOCK_CONST_METHOD0(UsingTCPFastOpen, bool());
MOCK_CONST_METHOD0(NumBytesRead, int64());
MOCK_CONST_METHOD0(GetConnectTimeMicros, base::TimeDelta());
MOCK_CONST_METHOD0(GetNegotiatedProtocol, net::NextProto());
};

// Break up |data| into a bunch of chunked MockReads/Writes and push
Expand Down
7 changes: 7 additions & 0 deletions jingle/notifier/base/proxy_resolving_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ base::TimeDelta ProxyResolvingClientSocket::GetConnectTimeMicros() const {
return base::TimeDelta::FromMicroseconds(-1);
}

net::NextProto ProxyResolvingClientSocket::GetNegotiatedProtocol() const {
if (transport_.get() && transport_->socket())
return transport_->socket()->GetNegotiatedProtocol();
NOTREACHED();
return net::kProtoUnknown;
}

void ProxyResolvingClientSocket::CloseTransportSocket() {
if (transport_.get() && transport_->socket())
transport_->socket()->Disconnect();
Expand Down
3 changes: 2 additions & 1 deletion jingle/notifier/base/proxy_resolving_client_socket.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.
//
Expand Down Expand Up @@ -65,6 +65,7 @@ class ProxyResolvingClientSocket : public net::StreamSocket {
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE;

private:
// Proxy resolution and connection functions.
Expand Down
6 changes: 5 additions & 1 deletion net/curvecp/curvecp_client_socket.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.

Expand Down Expand Up @@ -96,6 +96,10 @@ base::TimeDelta CurveCPClientSocket::GetConnectTimeMicros() const {
return base::TimeDelta::FromMicroseconds(-1);
}

NextProto CurveCPClientSocket::GetNegotiatedProtocol() const {
return kProtoUnknown;
}

int CurveCPClientSocket::Read(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) {
Expand Down
3 changes: 2 additions & 1 deletion net/curvecp/curvecp_client_socket.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.

Expand Down Expand Up @@ -39,6 +39,7 @@ class CurveCPClientSocket : public StreamSocket {
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE;

// Socket methods:
virtual int Read(IOBuffer* buf,
Expand Down
8 changes: 8 additions & 0 deletions net/http/http_proxy_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ base::TimeDelta HttpProxyClientSocket::GetConnectTimeMicros() const {
return base::TimeDelta::FromMicroseconds(-1);
}

NextProto HttpProxyClientSocket::GetNegotiatedProtocol() const {
if (transport_.get() && transport_->socket()) {
return transport_->socket()->GetNegotiatedProtocol();
}
NOTREACHED();
return kProtoUnknown;
}

int HttpProxyClientSocket::Read(IOBuffer* buf, int buf_len,
const CompletionCallback& callback) {
DCHECK(user_callback_.is_null());
Expand Down
1 change: 1 addition & 0 deletions net/http/http_proxy_client_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class HttpProxyClientSocket : public ProxyClientSocket {
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual NextProto GetNegotiatedProtocol() const OVERRIDE;

// Socket implementation.
virtual int Read(IOBuffer* buf,
Expand Down
2 changes: 1 addition & 1 deletion net/http/http_proxy_client_socket_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ int HttpProxyConnectJob::DoSSLConnectComplete(int result) {
SSLClientSocket* ssl =
static_cast<SSLClientSocket*>(transport_socket_handle_->socket());
using_spdy_ = ssl->was_spdy_negotiated();
protocol_negotiated_ = ssl->protocol_negotiated();
protocol_negotiated_ = ssl->GetNegotiatedProtocol();

// Reset the timer to just the length of time allowed for HttpProxy handshake
// so that a fast SSL connection plus a slow HttpProxy failure doesn't take
Expand Down
4 changes: 4 additions & 0 deletions net/socket/buffered_write_stream_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ base::TimeDelta BufferedWriteStreamSocket::GetConnectTimeMicros() const {
return wrapped_socket_->GetConnectTimeMicros();
}

NextProto BufferedWriteStreamSocket::GetNegotiatedProtocol() const {
return wrapped_socket_->GetNegotiatedProtocol();
}

void BufferedWriteStreamSocket::DoDelayedWrite() {
int result = wrapped_socket_->Write(
io_buffer_, io_buffer_->RemainingCapacity(),
Expand Down
1 change: 1 addition & 0 deletions net/socket/buffered_write_stream_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class NET_EXPORT_PRIVATE BufferedWriteStreamSocket : public StreamSocket {
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual NextProto GetNegotiatedProtocol() const OVERRIDE;

private:
void DoDelayedWrite();
Expand Down
3 changes: 3 additions & 0 deletions net/socket/client_socket_pool_base_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class MockClientSocket : public StreamSocket {
base::TimeDelta::FromMicroseconds(10);
return kDummyConnectTimeMicros; // Dummy value.
}
virtual NextProto GetNegotiatedProtocol() const {
return kProtoUnknown;
}

private:
bool connected_;
Expand Down
2 changes: 1 addition & 1 deletion net/socket/socket_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ bool MockSSLClientSocket::set_was_npn_negotiated(bool negotiated) {
return new_npn_value_ = negotiated;
}

NextProto MockSSLClientSocket::protocol_negotiated() const {
NextProto MockSSLClientSocket::GetNegotiatedProtocol() const {
if (is_protocol_negotiated_set_)
return protocol_negotiated_;
return data_->protocol_negotiated;
Expand Down
2 changes: 1 addition & 1 deletion net/socket/socket_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,9 @@ class MockSSLClientSocket : public MockClientSocket, public AsyncSocket {
std::string* server_protos) OVERRIDE;
virtual bool was_npn_negotiated() const OVERRIDE;
virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE;
virtual NextProto protocol_negotiated() const OVERRIDE;
virtual void set_protocol_negotiated(
NextProto protocol_negotiated) OVERRIDE;
virtual NextProto GetNegotiatedProtocol() const OVERRIDE;

// This MockSocket does not implement the manual async IO feature.
virtual void OnReadComplete(const MockRead& data) OVERRIDE;
Expand Down
8 changes: 8 additions & 0 deletions net/socket/socks5_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ base::TimeDelta SOCKS5ClientSocket::GetConnectTimeMicros() const {
return base::TimeDelta::FromMicroseconds(-1);
}

NextProto SOCKS5ClientSocket::GetNegotiatedProtocol() const {
if (transport_.get() && transport_->socket()) {
return transport_->socket()->GetNegotiatedProtocol();
}
NOTREACHED();
return kProtoUnknown;
}

// Read is called by the transport layer above to read. This can only be done
// if the SOCKS handshake is complete.
int SOCKS5ClientSocket::Read(IOBuffer* buf, int buf_len,
Expand Down
3 changes: 2 additions & 1 deletion net/socket/socks5_client_socket.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.

Expand Down Expand Up @@ -62,6 +62,7 @@ class NET_EXPORT_PRIVATE SOCKS5ClientSocket : public StreamSocket {
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual NextProto GetNegotiatedProtocol() const OVERRIDE;

// Socket implementation.
virtual int Read(IOBuffer* buf,
Expand Down
8 changes: 8 additions & 0 deletions net/socket/socks_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ base::TimeDelta SOCKSClientSocket::GetConnectTimeMicros() const {
return base::TimeDelta::FromMicroseconds(-1);
}

NextProto SOCKSClientSocket::GetNegotiatedProtocol() const {
if (transport_.get() && transport_->socket()) {
return transport_->socket()->GetNegotiatedProtocol();
}
NOTREACHED();
return kProtoUnknown;
}

// Read is called by the transport layer above to read. This can only be done
// if the SOCKS handshake is complete.
int SOCKSClientSocket::Read(IOBuffer* buf, int buf_len,
Expand Down
3 changes: 2 additions & 1 deletion net/socket/socks_client_socket.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.

Expand Down Expand Up @@ -59,6 +59,7 @@ class NET_EXPORT_PRIVATE SOCKSClientSocket : public StreamSocket {
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual NextProto GetNegotiatedProtocol() const OVERRIDE;

// Socket implementation.
virtual int Read(IOBuffer* buf,
Expand Down
10 changes: 6 additions & 4 deletions net/socket/ssl_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SSLClientSocket::SSLClientSocket()
domain_bound_cert_type_(CLIENT_CERT_INVALID_TYPE) {
}

// static
NextProto SSLClientSocket::NextProtoFromString(
const std::string& proto_string) {
if (proto_string == "http1.1" || proto_string == "http/1.1") {
Expand All @@ -32,6 +33,7 @@ NextProto SSLClientSocket::NextProtoFromString(
}
}

// static
const char* SSLClientSocket::NextProtoToString(NextProto next_proto) {
switch (next_proto) {
case kProtoHTTP11:
Expand Down Expand Up @@ -79,6 +81,10 @@ std::string SSLClientSocket::ServerProtosToString(
return JoinString(server_protos_with_commas, ',');
}

NextProto SSLClientSocket::GetNegotiatedProtocol() const {
return protocol_negotiated_;
}

bool SSLClientSocket::IgnoreCertError(int error, int load_flags) {
if (error == OK || load_flags & LOAD_IGNORE_ALL_CERT_ERRORS)
return true;
Expand Down Expand Up @@ -114,10 +120,6 @@ bool SSLClientSocket::set_was_spdy_negotiated(bool negotiated) {
return was_spdy_negotiated_ = negotiated;
}

NextProto SSLClientSocket::protocol_negotiated() const {
return protocol_negotiated_;
}

void SSLClientSocket::set_protocol_negotiated(NextProto protocol_negotiated) {
protocol_negotiated_ = protocol_negotiated;
}
Expand Down
5 changes: 3 additions & 2 deletions net/socket/ssl_client_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class NET_EXPORT SSLClientSocket : public SSLSocket {
virtual void GetSSLCertRequestInfo(
SSLCertRequestInfo* cert_request_info) = 0;

// StreamSocket:
virtual NextProto GetNegotiatedProtocol() const OVERRIDE;

// Get the application level protocol that we negotiated with the server.
// *proto is set to the resulting protocol (n.b. that the string may have
// embedded NULs).
Expand Down Expand Up @@ -123,8 +126,6 @@ class NET_EXPORT SSLClientSocket : public SSLSocket {

virtual bool set_was_spdy_negotiated(bool negotiated);

virtual NextProto protocol_negotiated() const;

virtual void set_protocol_negotiated(NextProto protocol_negotiated);

// Returns the ServerBoundCertService used by this socket, or NULL if
Expand Down
5 changes: 5 additions & 0 deletions net/socket/ssl_server_socket_nss.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ base::TimeDelta SSLServerSocketNSS::GetConnectTimeMicros() const {
return transport_socket_->GetConnectTimeMicros();
}

NextProto SSLServerSocketNSS::GetNegotiatedProtocol() const {
// NPN is not supported by this class.
return kProtoUnknown;
}

int SSLServerSocketNSS::InitializeSSLOptions() {
// Transport connected, now hook it up to nss
// TODO(port): specify rx and tx buffer sizes separately
Expand Down
1 change: 1 addition & 0 deletions net/socket/ssl_server_socket_nss.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class SSLServerSocketNSS : public SSLServerSocket {
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual NextProto GetNegotiatedProtocol() const OVERRIDE;

private:
enum State {
Expand Down
4 changes: 4 additions & 0 deletions net/socket/ssl_server_socket_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ class FakeSocket : public StreamSocket {
return base::TimeDelta::FromMicroseconds(-1);
}

virtual NextProto GetNegotiatedProtocol() const {
return kProtoUnknown;
}

private:
net::BoundNetLog net_log_;
FakeDataChannel* incoming_;
Expand Down
4 changes: 4 additions & 0 deletions net/socket/stream_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class NET_EXPORT_PRIVATE StreamSocket : public Socket {
// Returns the connection setup time of this socket.
virtual base::TimeDelta GetConnectTimeMicros() const = 0;

// Returns the protocol negotiated via NPN for this socket, or
// kProtoUnknown will be returned if NPN is not applicable.
virtual NextProto GetNegotiatedProtocol() const = 0;

protected:
// The following class is only used to gather statistics about the history of
// a socket. It is only instantiated and used in basic sockets, such as
Expand Down
6 changes: 5 additions & 1 deletion net/socket/tcp_client_socket_libevent.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.

Expand Down Expand Up @@ -733,4 +733,8 @@ base::TimeDelta TCPClientSocketLibevent::GetConnectTimeMicros() const {
return connect_time_micros_;
}

NextProto TCPClientSocketLibevent::GetNegotiatedProtocol() const {
return kProtoUnknown;
}

} // namespace net
Loading

0 comments on commit 33661e4

Please sign in to comment.