summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-02 16:09:01 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-02 16:09:01 +0000
commit0f873e8291deea212112dc7d6b48b0f0450522c2 (patch)
treed888b57c8ff0e55d322e450d9df2d1f5eb36d283
parenteb7ce94497639ec1e9a7a1549dc941d8e28e98ba (diff)
downloadchromium_src-0f873e8291deea212112dc7d6b48b0f0450522c2.zip
chromium_src-0f873e8291deea212112dc7d6b48b0f0450522c2.tar.gz
chromium_src-0f873e8291deea212112dc7d6b48b0f0450522c2.tar.bz2
Fix ClientSocketHandle reuse_type(). Correctly track socket use.
In particular, we used to consider that a socket had been used whenever it got returned to the ClientSocketPool. But, with preconnect, that is no longer true. Luckily, we now have UseHistory in the transport sockets. So, I create a WasEverUsed() method in ClientSocket, plumb this into all sockets, and use that in ClientSocketPoolBaseHelper instead of tracking whether or not the socket had been returned to the client or not. This ultimately will have two implications. We will record the correct values in Net.HttpSocketType histograms and we will use the correct timeout for preconnect sockets in ClientSocketPoolBaseHelper::CleanupIdleSockets(). BUG=none TEST=none Review URL: http://codereview.chromium.org/3353004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58363 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--jingle/notifier/base/fake_ssl_client_socket.cc4
-rw-r--r--jingle/notifier/base/fake_ssl_client_socket.h1
-rw-r--r--jingle/notifier/base/fake_ssl_client_socket_unittest.cc2
-rw-r--r--jingle/notifier/communicator/ssl_socket_adapter.cc15
-rw-r--r--jingle/notifier/communicator/ssl_socket_adapter.h3
-rw-r--r--net/http/http_proxy_client_socket.cc8
-rw-r--r--net/http/http_proxy_client_socket.h1
-rw-r--r--net/socket/client_socket.cc6
-rw-r--r--net/socket/client_socket.h9
-rw-r--r--net/socket/client_socket_pool_base.cc21
-rw-r--r--net/socket/client_socket_pool_base.h8
-rw-r--r--net/socket/client_socket_pool_base_unittest.cc11
-rw-r--r--net/socket/socket_test_util.cc21
-rw-r--r--net/socket/socket_test_util.h29
-rw-r--r--net/socket/socks5_client_socket.cc8
-rw-r--r--net/socket/socks5_client_socket.h1
-rw-r--r--net/socket/socks_client_socket.cc8
-rw-r--r--net/socket/socks_client_socket.h1
-rw-r--r--net/socket/ssl_client_socket_mac.cc8
-rw-r--r--net/socket/ssl_client_socket_mac.h1
-rw-r--r--net/socket/ssl_client_socket_nss.cc8
-rw-r--r--net/socket/ssl_client_socket_nss.h1
-rw-r--r--net/socket/ssl_client_socket_win.cc8
-rw-r--r--net/socket/ssl_client_socket_win.h1
-rw-r--r--net/socket/tcp_client_socket_libevent.cc4
-rw-r--r--net/socket/tcp_client_socket_libevent.h1
-rw-r--r--net/socket/tcp_client_socket_pool_unittest.cc3
-rw-r--r--net/socket/tcp_client_socket_win.cc4
-rw-r--r--net/socket/tcp_client_socket_win.h1
29 files changed, 165 insertions, 32 deletions
diff --git a/jingle/notifier/base/fake_ssl_client_socket.cc b/jingle/notifier/base/fake_ssl_client_socket.cc
index a89a594..cd5d5f5 100644
--- a/jingle/notifier/base/fake_ssl_client_socket.cc
+++ b/jingle/notifier/base/fake_ssl_client_socket.cc
@@ -324,4 +324,8 @@ void FakeSSLClientSocket::SetOmniboxSpeculation() {
transport_socket_->SetOmniboxSpeculation();
}
+bool FakeSSLClientSocket::WasEverUsed() const {
+ return transport_socket_->WasEverUsed();
+}
+
} // namespace notifier
diff --git a/jingle/notifier/base/fake_ssl_client_socket.h b/jingle/notifier/base/fake_ssl_client_socket.h
index bcf09f8..d70d4d3 100644
--- a/jingle/notifier/base/fake_ssl_client_socket.h
+++ b/jingle/notifier/base/fake_ssl_client_socket.h
@@ -59,6 +59,7 @@ class FakeSSLClientSocket : public net::ClientSocket {
virtual const net::BoundNetLog& NetLog() const;
virtual void SetSubresourceSpeculation();
virtual void SetOmniboxSpeculation();
+ virtual bool WasEverUsed() const;
private:
enum HandshakeState {
diff --git a/jingle/notifier/base/fake_ssl_client_socket_unittest.cc b/jingle/notifier/base/fake_ssl_client_socket_unittest.cc
index 2ca3adf..3b7aa50 100644
--- a/jingle/notifier/base/fake_ssl_client_socket_unittest.cc
+++ b/jingle/notifier/base/fake_ssl_client_socket_unittest.cc
@@ -59,6 +59,7 @@ class MockClientSocket : public net::ClientSocket {
MOCK_CONST_METHOD0(NetLog, const net::BoundNetLog&());
MOCK_METHOD0(SetSubresourceSpeculation, void());
MOCK_METHOD0(SetOmniboxSpeculation, void());
+ MOCK_CONST_METHOD0(WasEverUsed, bool());
};
// Break up |data| into a bunch of chunked MockReads/Writes and push
@@ -336,4 +337,3 @@ TEST_F(FakeSSLClientSocketTest, MalformedServerHello) {
} // namespace
} // namespace notifier
-
diff --git a/jingle/notifier/communicator/ssl_socket_adapter.cc b/jingle/notifier/communicator/ssl_socket_adapter.cc
index 30d28fe..cac3041 100644
--- a/jingle/notifier/communicator/ssl_socket_adapter.cc
+++ b/jingle/notifier/communicator/ssl_socket_adapter.cc
@@ -220,7 +220,8 @@ TransportSocket::TransportSocket(talk_base::AsyncSocket* socket,
write_callback_(NULL),
read_buffer_len_(0),
write_buffer_len_(0),
- socket_(socket) {
+ socket_(socket),
+ was_used_to_convey_data_(false) {
socket_->SignalReadEvent.connect(this, &TransportSocket::OnReadEvent);
socket_->SignalWriteEvent.connect(this, &TransportSocket::OnWriteEvent);
}
@@ -276,6 +277,12 @@ void TransportSocket::SetOmniboxSpeculation() {
NOTREACHED();
}
+bool TransportSocket::WasEverUsed() const {
+ // We don't use this in ClientSocketPools, so this should never be used.
+ NOTREACHED();
+ return was_used_to_convey_data_;
+}
+
int TransportSocket::Read(net::IOBuffer* buf, int buf_len,
net::CompletionCallback* callback) {
DCHECK(buf);
@@ -290,6 +297,8 @@ int TransportSocket::Read(net::IOBuffer* buf, int buf_len,
read_buffer_len_ = buf_len;
}
}
+ if (result != net::ERR_IO_PENDING)
+ was_used_to_convey_data_ = true;
return result;
}
@@ -307,6 +316,8 @@ int TransportSocket::Write(net::IOBuffer* buf, int buf_len,
write_buffer_len_ = buf_len;
}
}
+ if (result != net::ERR_IO_PENDING)
+ was_used_to_convey_data_ = true;
return result;
}
@@ -341,6 +352,7 @@ void TransportSocket::OnReadEvent(talk_base::AsyncSocket* socket) {
return;
}
}
+ was_used_to_convey_data_ = true;
callback->RunWithParams(Tuple1<int>(result));
}
}
@@ -366,6 +378,7 @@ void TransportSocket::OnWriteEvent(talk_base::AsyncSocket* socket) {
return;
}
}
+ was_used_to_convey_data_ = true;
callback->RunWithParams(Tuple1<int>(result));
}
}
diff --git a/jingle/notifier/communicator/ssl_socket_adapter.h b/jingle/notifier/communicator/ssl_socket_adapter.h
index 42b20a8..cdbc94e 100644
--- a/jingle/notifier/communicator/ssl_socket_adapter.h
+++ b/jingle/notifier/communicator/ssl_socket_adapter.h
@@ -45,6 +45,7 @@ class TransportSocket : public net::ClientSocket, public sigslot::has_slots<> {
virtual const net::BoundNetLog& NetLog() const { return net_log_; }
virtual void SetSubresourceSpeculation();
virtual void SetOmniboxSpeculation();
+ virtual bool WasEverUsed() const;
// net::Socket implementation
@@ -74,6 +75,8 @@ class TransportSocket : public net::ClientSocket, public sigslot::has_slots<> {
talk_base::AsyncSocket *socket_;
talk_base::SocketAddress addr_;
+ bool was_used_to_convey_data_;
+
DISALLOW_COPY_AND_ASSIGN(TransportSocket);
};
diff --git a/net/http/http_proxy_client_socket.cc b/net/http/http_proxy_client_socket.cc
index eccd652..7d768d2 100644
--- a/net/http/http_proxy_client_socket.cc
+++ b/net/http/http_proxy_client_socket.cc
@@ -197,6 +197,14 @@ void HttpProxyClientSocket::SetOmniboxSpeculation() {
}
}
+bool HttpProxyClientSocket::WasEverUsed() const {
+ if (transport_.get() && transport_->socket()) {
+ return transport_->socket()->WasEverUsed();
+ }
+ NOTREACHED();
+ return false;
+}
+
int HttpProxyClientSocket::Read(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
DCHECK(!user_callback_);
diff --git a/net/http/http_proxy_client_socket.h b/net/http/http_proxy_client_socket.h
index adfcc11..4702118 100644
--- a/net/http/http_proxy_client_socket.h
+++ b/net/http/http_proxy_client_socket.h
@@ -72,6 +72,7 @@ class HttpProxyClientSocket : public ClientSocket {
virtual const BoundNetLog& NetLog() const { return net_log_; }
virtual void SetSubresourceSpeculation();
virtual void SetOmniboxSpeculation();
+ virtual bool WasEverUsed() const;
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
diff --git a/net/socket/client_socket.cc b/net/socket/client_socket.cc
index aba0366..0edee70 100644
--- a/net/socket/client_socket.cc
+++ b/net/socket/client_socket.cc
@@ -93,5 +93,9 @@ void ClientSocket::UseHistory::set_omnibox_speculation() {
omnibox_speculation_ = true;
}
-} // namespace net
+bool ClientSocket::UseHistory::was_used_to_convey_data() const {
+ DCHECK(!was_used_to_convey_data_ || was_ever_connected_);
+ return was_used_to_convey_data_;
+}
+} // namespace net
diff --git a/net/socket/client_socket.h b/net/socket/client_socket.h
index 6a4fb31..1a48a11 100644
--- a/net/socket/client_socket.h
+++ b/net/socket/client_socket.h
@@ -58,11 +58,16 @@ class ClientSocket : public Socket {
virtual const BoundNetLog& NetLog() const = 0;
// Set the annotation to indicate this socket was created for speculative
- // reasons. This call is generally fowarded to a basic TCPClientSocket*,
+ // reasons. This call is generally forwarded to a basic TCPClientSocket*,
// where a UseHistory can be updated.
virtual void SetSubresourceSpeculation() = 0;
virtual void SetOmniboxSpeculation() = 0;
+ // Returns true if the underlying transport socket ever had any reads or
+ // writes. ClientSockets layered on top of transport sockets should forward
+ // this call to the transport socket.
+ virtual bool WasEverUsed() 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
@@ -84,6 +89,8 @@ class ClientSocket : public Socket {
void set_subresource_speculation();
void set_omnibox_speculation();
+ bool was_used_to_convey_data() const;
+
private:
// Summarize the statistics for this socket.
void EmitPreconnectionHistograms() const;
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index beb79ae..b982aa0 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -286,8 +286,8 @@ bool ClientSocketPoolBaseHelper::AssignIdleSocketToGroup(
base::TimeDelta idle_time =
base::TimeTicks::Now() - idle_socket.start_time;
HandOutSocket(
- idle_socket.socket, idle_socket.used, request->handle(), idle_time,
- group, request->net_log());
+ idle_socket.socket, idle_socket.socket->WasEverUsed(),
+ request->handle(), idle_time, group, request->net_log());
return true;
}
delete idle_socket.socket;
@@ -447,8 +447,11 @@ bool ClientSocketPoolBaseHelper::IdleSocket::ShouldCleanup(
base::TimeTicks now,
base::TimeDelta timeout) const {
bool timed_out = (now - start_time) >= timeout;
- return timed_out ||
- !(used ? socket->IsConnectedAndIdle() : socket->IsConnected());
+ if (timed_out)
+ return true;
+ if (socket->WasEverUsed())
+ return !socket->IsConnectedAndIdle();
+ return !socket->IsConnected();
}
void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) {
@@ -474,7 +477,8 @@ void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) {
std::deque<IdleSocket>::iterator j = group->mutable_idle_sockets()->begin();
while (j != group->idle_sockets().end()) {
base::TimeDelta timeout =
- j->used ? used_idle_socket_timeout_ : unused_idle_socket_timeout_;
+ j->socket->WasEverUsed() ?
+ used_idle_socket_timeout_ : unused_idle_socket_timeout_;
if (force || j->ShouldCleanup(now, timeout)) {
delete j->socket;
j = group->mutable_idle_sockets()->erase(j);
@@ -553,7 +557,7 @@ void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name,
id == pool_generation_number_;
if (can_reuse) {
// Add it to the idle list.
- AddIdleSocket(socket, true /* used socket */, group);
+ AddIdleSocket(socket, group);
OnAvailableSocketSlot(group_name, group);
} else {
delete socket;
@@ -651,7 +655,7 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete(
r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL);
InvokeUserCallbackLater(r->handle(), r->callback(), result);
} else {
- AddIdleSocket(socket.release(), false /* unused socket */, group);
+ AddIdleSocket(socket.release(), group);
OnAvailableSocketSlot(group_name, group);
CheckForStalledSocketGroups();
}
@@ -771,12 +775,11 @@ void ClientSocketPoolBaseHelper::HandOutSocket(
}
void ClientSocketPoolBaseHelper::AddIdleSocket(
- ClientSocket* socket, bool used, Group* group) {
+ ClientSocket* socket, Group* group) {
DCHECK(socket);
IdleSocket idle_socket;
idle_socket.socket = socket;
idle_socket.start_time = base::TimeTicks::Now();
- idle_socket.used = used;
group->mutable_idle_sockets()->push_back(idle_socket);
IncrementIdleCount();
diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h
index 2540fde..11540b2 100644
--- a/net/socket/client_socket_pool_base.h
+++ b/net/socket/client_socket_pool_base.h
@@ -252,10 +252,9 @@ class ClientSocketPoolBaseHelper
// Entry for a persistent socket which became idle at time |start_time|.
struct IdleSocket {
- IdleSocket() : socket(NULL), used(false) {}
+ IdleSocket() : socket(NULL) {}
ClientSocket* socket;
base::TimeTicks start_time;
- bool used; // Indicates whether or not the socket has been used yet.
// An idle socket should be removed if it can't be reused, or has been idle
// for too long. |now| is the current time value (TimeTicks::Now()).
@@ -396,9 +395,8 @@ class ClientSocketPoolBaseHelper
Group* group,
const BoundNetLog& net_log);
- // Adds |socket| to the list of idle sockets for |group|. |used| indicates
- // whether or not the socket has previously been used.
- void AddIdleSocket(ClientSocket* socket, bool used, Group* group);
+ // Adds |socket| to the list of idle sockets for |group|.
+ void AddIdleSocket(ClientSocket* socket, Group* group);
// Iterates through |group_map_|, canceling all ConnectJobs and deleting
// groups if they are no longer needed.
diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc
index 006d4e81..b196168 100644
--- a/net/socket/client_socket_pool_base_unittest.cc
+++ b/net/socket/client_socket_pool_base_unittest.cc
@@ -42,7 +42,7 @@ typedef ClientSocketPoolBase<TestSocketParams> TestClientSocketPoolBase;
class MockClientSocket : public ClientSocket {
public:
- MockClientSocket() : connected_(false) {}
+ MockClientSocket() : connected_(false), was_used_to_convey_data_(false) {}
// Socket methods:
virtual int Read(
@@ -51,8 +51,9 @@ class MockClientSocket : public ClientSocket {
}
virtual int Write(
- IOBuffer* /* buf */, int /* len */, CompletionCallback* /* callback */) {
- return ERR_UNEXPECTED;
+ IOBuffer* /* buf */, int len, CompletionCallback* /* callback */) {
+ was_used_to_convey_data_ = true;
+ return len;
}
virtual bool SetReceiveBufferSize(int32 size) { return true; }
virtual bool SetSendBufferSize(int32 size) { return true; }
@@ -78,10 +79,12 @@ class MockClientSocket : public ClientSocket {
virtual void SetSubresourceSpeculation() {}
virtual void SetOmniboxSpeculation() {}
+ virtual bool WasEverUsed() const { return was_used_to_convey_data_; }
private:
bool connected_;
BoundNetLog net_log_;
+ bool was_used_to_convey_data_;
DISALLOW_COPY_AND_ASSIGN(MockClientSocket);
};
@@ -1669,6 +1672,8 @@ TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) {
req.handle()->Reset();
EXPECT_EQ(OK, req2.WaitForResult());
+ // Use the socket.
+ EXPECT_EQ(1, req2.handle()->socket()->Write(NULL, 1, NULL));
req2.handle()->Reset();
// We post all of our delayed tasks with a 2ms delay. I.e. they don't
diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc
index bd47f7c..440c790 100644
--- a/net/socket/socket_test_util.cc
+++ b/net/socket/socket_test_util.cc
@@ -178,7 +178,8 @@ MockTCPClientSocket::MockTCPClientSocket(const net::AddressList& addresses,
peer_closed_connection_(false),
pending_buf_(NULL),
pending_buf_len_(0),
- pending_callback_(NULL) {
+ pending_callback_(NULL),
+ was_used_to_convey_data_(false) {
DCHECK(data_);
data_->Reset();
}
@@ -248,10 +249,13 @@ int MockTCPClientSocket::Write(net::IOBuffer* buf, int buf_len,
std::string data(buf->data(), buf_len);
net::MockWriteResult write_result = data_->OnWrite(data);
+ was_used_to_convey_data_ = true;
+
if (write_result.async) {
RunCallbackAsync(callback, write_result.result);
return net::ERR_IO_PENDING;
}
+
return write_result.result;
}
@@ -279,6 +283,8 @@ int MockTCPClientSocket::CompleteRead() {
DCHECK(pending_buf_);
DCHECK(pending_buf_len_ > 0);
+ was_used_to_convey_data_ = true;
+
// Save the pending async IO data and reset our |pending_| state.
net::IOBuffer* buf = pending_buf_;
int buf_len = pending_buf_len_;
@@ -323,7 +329,8 @@ DeterministicMockTCPClientSocket::DeterministicMockTCPClientSocket(
read_buf_len_(0),
read_pending_(false),
read_callback_(NULL),
- data_(data) {}
+ data_(data),
+ was_used_to_convey_data_(false) {}
void DeterministicMockTCPClientSocket::OnReadComplete(const MockRead& data) {}
@@ -366,6 +373,8 @@ int DeterministicMockTCPClientSocket::Write(
write_pending_ = true;
return net::ERR_IO_PENDING;
}
+
+ was_used_to_convey_data_ = true;
write_pending_ = false;
return write_result.result;
}
@@ -390,10 +399,12 @@ int DeterministicMockTCPClientSocket::Read(
return ERR_IO_PENDING;
}
+ was_used_to_convey_data_ = true;
return CompleteRead();
}
void DeterministicMockTCPClientSocket::CompleteWrite(){
+ was_used_to_convey_data_ = true;
write_pending_ = false;
write_callback_->Run(write_result_);
}
@@ -403,6 +414,8 @@ int DeterministicMockTCPClientSocket::CompleteRead() {
DCHECK_LE(read_data_.data_len, read_buf_len_);
DCHECK(read_buf_);
+ was_used_to_convey_data_ = true;
+
if (read_data_.result == ERR_IO_PENDING)
read_data_ = data_->GetNextRead();
DCHECK_NE(ERR_IO_PENDING, read_data_.result);
@@ -497,6 +510,10 @@ bool MockSSLClientSocket::IsConnected() const {
return transport_->socket()->IsConnected();
}
+bool MockSSLClientSocket::WasEverUsed() const {
+ return transport_->socket()->WasEverUsed();
+}
+
int MockSSLClientSocket::Read(net::IOBuffer* buf, int buf_len,
net::CompletionCallback* callback) {
return transport_->socket()->Read(buf, buf_len, callback);
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index aaa514e..7cc6f84 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -564,6 +564,7 @@ class MockTCPClientSocket : public MockClientSocket {
virtual void Disconnect();
virtual bool IsConnected() const;
virtual bool IsConnectedAndIdle() const { return IsConnected(); }
+ virtual bool WasEverUsed() const { return was_used_to_convey_data_; }
// Socket methods:
virtual int Read(net::IOBuffer* buf, int buf_len,
@@ -594,6 +595,7 @@ class MockTCPClientSocket : public MockClientSocket {
net::IOBuffer* pending_buf_;
int pending_buf_len_;
net::CompletionCallback* pending_callback_;
+ bool was_used_to_convey_data_;
};
class DeterministicMockTCPClientSocket : public MockClientSocket,
@@ -601,20 +603,26 @@ class DeterministicMockTCPClientSocket : public MockClientSocket,
public:
DeterministicMockTCPClientSocket(net::NetLog* net_log,
net::DeterministicSocketData* data);
- virtual int Write(net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* callback);
- virtual int Read(net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* callback);
- virtual void CompleteWrite();
- virtual int CompleteRead();
- virtual void OnReadComplete(const MockRead& data);
+ // ClientSocket methods:
virtual int Connect(net::CompletionCallback* callback);
virtual void Disconnect();
virtual bool IsConnected() const;
virtual bool IsConnectedAndIdle() const { return IsConnected(); }
- bool write_pending() { return write_pending_; }
- bool read_pending() { return read_pending_; }
+ virtual bool WasEverUsed() const { return was_used_to_convey_data_; }
+
+ // Socket methods:
+ virtual int Write(net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback);
+ virtual int Read(net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback);
+
+ bool write_pending() const { return write_pending_; }
+ bool read_pending() const { return read_pending_; }
+
+ void CompleteWrite();
+ int CompleteRead();
+ void OnReadComplete(const MockRead& data);
private:
bool write_pending_;
@@ -628,6 +636,7 @@ class DeterministicMockTCPClientSocket : public MockClientSocket,
bool read_pending_;
net::CompletionCallback* read_callback_;
net::DeterministicSocketData* data_;
+ bool was_used_to_convey_data_;
};
class MockSSLClientSocket : public MockClientSocket {
@@ -643,6 +652,7 @@ class MockSSLClientSocket : public MockClientSocket {
virtual int Connect(net::CompletionCallback* callback);
virtual void Disconnect();
virtual bool IsConnected() const;
+ virtual bool WasEverUsed() const;
// Socket methods:
virtual int Read(net::IOBuffer* buf, int buf_len,
@@ -666,6 +676,7 @@ class MockSSLClientSocket : public MockClientSocket {
net::SSLSocketDataProvider* data_;
bool is_npn_state_set_;
bool new_npn_value_;
+ bool was_used_to_convey_data_;
};
class TestSocketRequest : public CallbackRunner< Tuple1<int> > {
diff --git a/net/socket/socks5_client_socket.cc b/net/socket/socks5_client_socket.cc
index 0af7b9b..0b8f08f 100644
--- a/net/socket/socks5_client_socket.cc
+++ b/net/socket/socks5_client_socket.cc
@@ -122,6 +122,14 @@ void SOCKS5ClientSocket::SetOmniboxSpeculation() {
}
}
+bool SOCKS5ClientSocket::WasEverUsed() const {
+ if (transport_.get() && transport_->socket()) {
+ return transport_->socket()->WasEverUsed();
+ }
+ NOTREACHED();
+ return false;
+}
+
// 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,
diff --git a/net/socket/socks5_client_socket.h b/net/socket/socks5_client_socket.h
index 63e3e6a..72e27db 100644
--- a/net/socket/socks5_client_socket.h
+++ b/net/socket/socks5_client_socket.h
@@ -58,6 +58,7 @@ class SOCKS5ClientSocket : public ClientSocket {
virtual const BoundNetLog& NetLog() const { return net_log_; }
virtual void SetSubresourceSpeculation();
virtual void SetOmniboxSpeculation();
+ virtual bool WasEverUsed() const;
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
diff --git a/net/socket/socks_client_socket.cc b/net/socket/socks_client_socket.cc
index c38021f..8e9e675 100644
--- a/net/socket/socks_client_socket.cc
+++ b/net/socket/socks_client_socket.cc
@@ -157,6 +157,14 @@ void SOCKSClientSocket::SetOmniboxSpeculation() {
}
}
+bool SOCKSClientSocket::WasEverUsed() const {
+ if (transport_.get() && transport_->socket()) {
+ return transport_->socket()->WasEverUsed();
+ }
+ NOTREACHED();
+ return false;
+}
+
// 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,
diff --git a/net/socket/socks_client_socket.h b/net/socket/socks_client_socket.h
index 3ac8f62..e9e9695 100644
--- a/net/socket/socks_client_socket.h
+++ b/net/socket/socks_client_socket.h
@@ -55,6 +55,7 @@ class SOCKSClientSocket : public ClientSocket {
virtual const BoundNetLog& NetLog() const { return net_log_; }
virtual void SetSubresourceSpeculation();
virtual void SetOmniboxSpeculation();
+ virtual bool WasEverUsed() const;
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
diff --git a/net/socket/ssl_client_socket_mac.cc b/net/socket/ssl_client_socket_mac.cc
index 6fdd2e9..284937a 100644
--- a/net/socket/ssl_client_socket_mac.cc
+++ b/net/socket/ssl_client_socket_mac.cc
@@ -607,6 +607,14 @@ void SSLClientSocketMac::SetOmniboxSpeculation() {
}
}
+bool SSLClientSocketMac::WasEverUsed() const {
+ if (transport_.get() && transport_->socket()) {
+ return transport_->socket()->WasEverUsed();
+ }
+ NOTREACHED();
+ return false;
+}
+
int SSLClientSocketMac::Read(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
DCHECK(completed_handshake_);
diff --git a/net/socket/ssl_client_socket_mac.h b/net/socket/ssl_client_socket_mac.h
index 26a270c..05b9735 100644
--- a/net/socket/ssl_client_socket_mac.h
+++ b/net/socket/ssl_client_socket_mac.h
@@ -49,6 +49,7 @@ class SSLClientSocketMac : public SSLClientSocket {
virtual const BoundNetLog& NetLog() const { return net_log_; }
virtual void SetSubresourceSpeculation();
virtual void SetOmniboxSpeculation();
+ virtual bool WasEverUsed() const;
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc
index d69d202..f46bfcc 100644
--- a/net/socket/ssl_client_socket_nss.cc
+++ b/net/socket/ssl_client_socket_nss.cc
@@ -677,6 +677,14 @@ void SSLClientSocketNSS::SetOmniboxSpeculation() {
}
}
+bool SSLClientSocketNSS::WasEverUsed() const {
+ if (transport_.get() && transport_->socket()) {
+ return transport_->socket()->WasEverUsed();
+ }
+ NOTREACHED();
+ return false;
+}
+
int SSLClientSocketNSS::Read(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
EnterFunction(buf_len);
diff --git a/net/socket/ssl_client_socket_nss.h b/net/socket/ssl_client_socket_nss.h
index dabe5c4..c43b718 100644
--- a/net/socket/ssl_client_socket_nss.h
+++ b/net/socket/ssl_client_socket_nss.h
@@ -58,6 +58,7 @@ class SSLClientSocketNSS : public SSLClientSocket {
virtual const BoundNetLog& NetLog() const { return net_log_; }
virtual void SetSubresourceSpeculation();
virtual void SetOmniboxSpeculation();
+ virtual bool WasEverUsed() const;
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
diff --git a/net/socket/ssl_client_socket_win.cc b/net/socket/ssl_client_socket_win.cc
index 1bf704c..99c9322 100644
--- a/net/socket/ssl_client_socket_win.cc
+++ b/net/socket/ssl_client_socket_win.cc
@@ -646,6 +646,14 @@ void SSLClientSocketWin::SetOmniboxSpeculation() {
}
}
+bool SSLClientSocketWin::WasEverUsed() const {
+ if (transport_.get() && transport_->socket()) {
+ return transport_->socket()->WasEverUsed();
+ }
+ NOTREACHED();
+ return false;
+}
+
int SSLClientSocketWin::Read(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
DCHECK(completed_handshake());
diff --git a/net/socket/ssl_client_socket_win.h b/net/socket/ssl_client_socket_win.h
index 44a5374..38cdb32 100644
--- a/net/socket/ssl_client_socket_win.h
+++ b/net/socket/ssl_client_socket_win.h
@@ -53,6 +53,7 @@ class SSLClientSocketWin : public SSLClientSocket {
virtual const BoundNetLog& NetLog() const { return net_log_; }
virtual void SetSubresourceSpeculation();
virtual void SetOmniboxSpeculation();
+ virtual bool WasEverUsed() const;
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index a63528b..15c3738 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -541,4 +541,8 @@ void TCPClientSocketLibevent::SetOmniboxSpeculation() {
use_history_.set_subresource_speculation();
}
+bool TCPClientSocketLibevent::WasEverUsed() const {
+ return use_history_.was_used_to_convey_data();
+}
+
} // namespace net
diff --git a/net/socket/tcp_client_socket_libevent.h b/net/socket/tcp_client_socket_libevent.h
index 8d68bff..980e4cd 100644
--- a/net/socket/tcp_client_socket_libevent.h
+++ b/net/socket/tcp_client_socket_libevent.h
@@ -42,6 +42,7 @@ class TCPClientSocketLibevent : public ClientSocket, NonThreadSafe {
virtual const BoundNetLog& NetLog() const { return net_log_; }
virtual void SetSubresourceSpeculation();
virtual void SetOmniboxSpeculation();
+ virtual bool WasEverUsed() const;
// Socket methods:
// Multiple outstanding requests are not supported.
diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc
index 5bcf7e1..ddcd5bf 100644
--- a/net/socket/tcp_client_socket_pool_unittest.cc
+++ b/net/socket/tcp_client_socket_pool_unittest.cc
@@ -52,6 +52,7 @@ class MockClientSocket : public ClientSocket {
virtual void SetSubresourceSpeculation() {}
virtual void SetOmniboxSpeculation() {}
+ virtual bool WasEverUsed() const { return false; }
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len,
@@ -96,6 +97,7 @@ class MockFailingClientSocket : public ClientSocket {
virtual void SetSubresourceSpeculation() {}
virtual void SetOmniboxSpeculation() {}
+ virtual bool WasEverUsed() const { return false; }
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len,
@@ -153,6 +155,7 @@ class MockPendingClientSocket : public ClientSocket {
virtual void SetSubresourceSpeculation() {}
virtual void SetOmniboxSpeculation() {}
+ virtual bool WasEverUsed() const { return false; }
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len,
diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc
index ed2cccb..1a1f308 100644
--- a/net/socket/tcp_client_socket_win.cc
+++ b/net/socket/tcp_client_socket_win.cc
@@ -524,6 +524,10 @@ void TCPClientSocketWin::SetOmniboxSpeculation() {
use_history_.set_subresource_speculation();
}
+bool TCPClientSocketWin::WasEverUsed() const {
+ return use_history_.was_used_to_convey_data();
+}
+
int TCPClientSocketWin::Read(IOBuffer* buf,
int buf_len,
CompletionCallback* callback) {
diff --git a/net/socket/tcp_client_socket_win.h b/net/socket/tcp_client_socket_win.h
index bd31960..be25157 100644
--- a/net/socket/tcp_client_socket_win.h
+++ b/net/socket/tcp_client_socket_win.h
@@ -39,6 +39,7 @@ class TCPClientSocketWin : public ClientSocket, NonThreadSafe {
virtual const BoundNetLog& NetLog() const { return net_log_; }
virtual void SetSubresourceSpeculation();
virtual void SetOmniboxSpeculation();
+ virtual bool WasEverUsed() const;
// Socket methods:
// Multiple outstanding requests are not supported.