summaryrefslogtreecommitdiffstats
path: root/net/socket
diff options
context:
space:
mode:
Diffstat (limited to 'net/socket')
-rw-r--r--net/socket/client_socket_handle.cc4
-rw-r--r--net/socket/client_socket_handle.h16
-rw-r--r--net/socket/client_socket_pool_base.cc24
-rw-r--r--net/socket/client_socket_pool_base.h3
4 files changed, 23 insertions, 24 deletions
diff --git a/net/socket/client_socket_handle.cc b/net/socket/client_socket_handle.cc
index e42e9fc..53bcd77 100644
--- a/net/socket/client_socket_handle.cc
+++ b/net/socket/client_socket_handle.cc
@@ -19,7 +19,7 @@ ClientSocketHandle::ClientSocketHandle()
: is_initialized_(false),
pool_(NULL),
higher_pool_(NULL),
- is_reused_(false),
+ reuse_type_(ClientSocketHandle::UNUSED),
callback_(base::Bind(&ClientSocketHandle::OnIOComplete,
base::Unretained(this))),
is_ssl_error_(false) {}
@@ -58,7 +58,7 @@ void ClientSocketHandle::ResetInternal(bool cancel) {
is_initialized_ = false;
socket_.reset();
group_name_.clear();
- is_reused_ = false;
+ reuse_type_ = ClientSocketHandle::UNUSED;
user_callback_.Reset();
if (higher_pool_)
RemoveHigherLayeredPool(higher_pool_);
diff --git a/net/socket/client_socket_handle.h b/net/socket/client_socket_handle.h
index 30b7c03..0899d9a 100644
--- a/net/socket/client_socket_handle.h
+++ b/net/socket/client_socket_handle.h
@@ -126,7 +126,7 @@ class NET_EXPORT ClientSocketHandle {
// SetSocket() may also be used if this handle is used as simply for
// socket storage (e.g., http://crbug.com/37810).
void SetSocket(scoped_ptr<StreamSocket> s);
- void set_is_reused(bool is_reused) { is_reused_ = is_reused; }
+ void set_reuse_type(SocketReuseType reuse_type) { reuse_type_ = reuse_type; }
void set_idle_time(base::TimeDelta idle_time) { idle_time_ = idle_time; }
void set_pool_id(int id) { pool_id_ = id; }
void set_is_ssl_error(bool is_ssl_error) { is_ssl_error_ = is_ssl_error; }
@@ -161,17 +161,9 @@ class NET_EXPORT ClientSocketHandle {
// These may only be used if is_initialized() is true.
const std::string& group_name() const { return group_name_; }
int id() const { return pool_id_; }
- bool is_reused() const { return is_reused_; }
+ bool is_reused() const { return reuse_type_ == REUSED_IDLE; }
base::TimeDelta idle_time() const { return idle_time_; }
- SocketReuseType reuse_type() const {
- if (is_reused()) {
- return REUSED_IDLE;
- } else if (idle_time() == base::TimeDelta()) {
- return UNUSED;
- } else {
- return UNUSED_IDLE;
- }
- }
+ SocketReuseType reuse_type() const { return reuse_type_; }
const LoadTimingInfo::ConnectTiming& connect_timing() const {
return connect_timing_;
}
@@ -200,7 +192,7 @@ class NET_EXPORT ClientSocketHandle {
HigherLayeredPool* higher_pool_;
scoped_ptr<StreamSocket> socket_;
std::string group_name_;
- bool is_reused_;
+ SocketReuseType reuse_type_;
CompletionCallback callback_;
CompletionCallback user_callback_;
base::TimeDelta idle_time_;
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index 1c79923..e20b355 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -15,7 +15,6 @@
#include "base/values.h"
#include "net/base/net_errors.h"
#include "net/base/net_log.h"
-#include "net/socket/client_socket_handle.h"
using base::TimeDelta;
@@ -401,7 +400,7 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
if (rv == OK) {
LogBoundConnectJobToRequest(connect_job->net_log().source(), request);
if (!preconnecting) {
- HandOutSocket(connect_job->PassSocket(), false /* not reused */,
+ HandOutSocket(connect_job->PassSocket(), ClientSocketHandle::UNUSED,
connect_job->connect_timing(), handle, base::TimeDelta(),
group, request.net_log());
} else {
@@ -427,7 +426,7 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
error_socket = connect_job->PassSocket();
}
if (error_socket) {
- HandOutSocket(error_socket.Pass(), false /* not reused */,
+ HandOutSocket(error_socket.Pass(), ClientSocketHandle::UNUSED,
connect_job->connect_timing(), handle, base::TimeDelta(),
group, request.net_log());
} else if (group->IsEmpty()) {
@@ -476,9 +475,16 @@ bool ClientSocketPoolBaseHelper::AssignIdleSocketToRequest(
base::TimeTicks::Now() - idle_socket_it->start_time;
IdleSocket idle_socket = *idle_socket_it;
idle_sockets->erase(idle_socket_it);
+ // TODO(davidben): If |idle_time| is under some low watermark, consider
+ // treating as UNUSED rather than UNUSED_IDLE. This will avoid
+ // HttpNetworkTransaction retrying on some errors.
+ ClientSocketHandle::SocketReuseType reuse_type =
+ idle_socket.socket->WasEverUsed() ?
+ ClientSocketHandle::REUSED_IDLE :
+ ClientSocketHandle::UNUSED_IDLE;
HandOutSocket(
scoped_ptr<StreamSocket>(idle_socket.socket),
- idle_socket.socket->WasEverUsed(),
+ reuse_type,
LoadTimingInfo::ConnectTiming(),
request.handle(),
idle_time,
@@ -878,7 +884,7 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete(
if (request) {
LogBoundConnectJobToRequest(job_log.source(), *request);
HandOutSocket(
- socket.Pass(), false /* unused socket */, connect_timing,
+ socket.Pass(), ClientSocketHandle::UNUSED, connect_timing,
request->handle(), base::TimeDelta(), group, request->net_log());
request->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL);
InvokeUserCallbackLater(request->handle(), request->callback(), result);
@@ -898,7 +904,7 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete(
RemoveConnectJob(job, group);
if (socket.get()) {
handed_out_socket = true;
- HandOutSocket(socket.Pass(), false /* unused socket */,
+ HandOutSocket(socket.Pass(), ClientSocketHandle::UNUSED,
connect_timing, request->handle(), base::TimeDelta(),
group, request->net_log());
}
@@ -963,7 +969,7 @@ void ClientSocketPoolBaseHelper::ProcessPendingRequest(
void ClientSocketPoolBaseHelper::HandOutSocket(
scoped_ptr<StreamSocket> socket,
- bool reused,
+ ClientSocketHandle::SocketReuseType reuse_type,
const LoadTimingInfo::ConnectTiming& connect_timing,
ClientSocketHandle* handle,
base::TimeDelta idle_time,
@@ -971,12 +977,12 @@ void ClientSocketPoolBaseHelper::HandOutSocket(
const BoundNetLog& net_log) {
DCHECK(socket);
handle->SetSocket(socket.Pass());
- handle->set_is_reused(reused);
+ handle->set_reuse_type(reuse_type);
handle->set_idle_time(idle_time);
handle->set_pool_id(pool_generation_number_);
handle->set_connect_timing(connect_timing);
- if (reused) {
+ if (handle->is_reused()) {
net_log.AddEvent(
NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET,
NetLog::IntegerCallback(
diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h
index 2c2ddb5..8a0a1f3 100644
--- a/net/socket/client_socket_pool_base.h
+++ b/net/socket/client_socket_pool_base.h
@@ -46,6 +46,7 @@
#include "net/base/network_change_notifier.h"
#include "net/base/priority_queue.h"
#include "net/base/request_priority.h"
+#include "net/socket/client_socket_handle.h"
#include "net/socket/client_socket_pool.h"
#include "net/socket/stream_socket.h"
@@ -528,7 +529,7 @@ class NET_EXPORT_PRIVATE ClientSocketPoolBaseHelper
// Assigns |socket| to |handle| and updates |group|'s counters appropriately.
void HandOutSocket(scoped_ptr<StreamSocket> socket,
- bool reused,
+ ClientSocketHandle::SocketReuseType reuse_type,
const LoadTimingInfo::ConnectTiming& connect_timing,
ClientSocketHandle* handle,
base::TimeDelta time_idle,