| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/socket/client_socket_handle.h" | 5 #include "net/socket/client_socket_handle.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/socket/client_socket_pool.h" | 13 #include "net/socket/client_socket_pool.h" |
| 14 #include "net/socket/client_socket_pool_histograms.h" | |
| 15 | 14 |
| 16 namespace net { | 15 namespace net { |
| 17 | 16 |
| 18 ClientSocketHandle::ClientSocketHandle() | 17 ClientSocketHandle::ClientSocketHandle() |
| 19 : is_initialized_(false), | 18 : is_initialized_(false), |
| 20 pool_(NULL), | 19 pool_(NULL), |
| 21 higher_pool_(NULL), | 20 higher_pool_(NULL), |
| 22 reuse_type_(ClientSocketHandle::UNUSED), | 21 reuse_type_(ClientSocketHandle::UNUSED), |
| 23 callback_(base::Bind(&ClientSocketHandle::OnIOComplete, | 22 callback_(base::Bind(&ClientSocketHandle::OnIOComplete, |
| 24 base::Unretained(this))), | 23 base::Unretained(this))), |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 HandleInitCompletion(result); | 141 HandleInitCompletion(result); |
| 143 callback.Run(result); | 142 callback.Run(result); |
| 144 } | 143 } |
| 145 | 144 |
| 146 scoped_ptr<StreamSocket> ClientSocketHandle::PassSocket() { | 145 scoped_ptr<StreamSocket> ClientSocketHandle::PassSocket() { |
| 147 return socket_.Pass(); | 146 return socket_.Pass(); |
| 148 } | 147 } |
| 149 | 148 |
| 150 void ClientSocketHandle::HandleInitCompletion(int result) { | 149 void ClientSocketHandle::HandleInitCompletion(int result) { |
| 151 CHECK_NE(ERR_IO_PENDING, result); | 150 CHECK_NE(ERR_IO_PENDING, result); |
| 152 ClientSocketPoolHistograms* histograms = pool_->histograms(); | |
| 153 histograms->AddErrorCode(result); | |
| 154 if (result != OK) { | 151 if (result != OK) { |
| 155 if (!socket_.get()) | 152 if (!socket_.get()) |
| 156 ResetInternal(false); // Nothing to cancel since the request failed. | 153 ResetInternal(false); // Nothing to cancel since the request failed. |
| 157 else | 154 else |
| 158 is_initialized_ = true; | 155 is_initialized_ = true; |
| 159 return; | 156 return; |
| 160 } | 157 } |
| 161 is_initialized_ = true; | 158 is_initialized_ = true; |
| 162 CHECK_NE(-1, pool_id_) << "Pool should have set |pool_id_| to a valid value."; | 159 CHECK_NE(-1, pool_id_) << "Pool should have set |pool_id_| to a valid value."; |
| 163 setup_time_ = base::TimeTicks::Now() - init_time_; | 160 setup_time_ = base::TimeTicks::Now() - init_time_; |
| 164 | 161 |
| 165 histograms->AddSocketType(reuse_type()); | |
| 166 switch (reuse_type()) { | |
| 167 case ClientSocketHandle::UNUSED: | |
| 168 histograms->AddRequestTime(setup_time()); | |
| 169 break; | |
| 170 case ClientSocketHandle::UNUSED_IDLE: | |
| 171 histograms->AddUnusedIdleTime(idle_time()); | |
| 172 break; | |
| 173 case ClientSocketHandle::REUSED_IDLE: | |
| 174 histograms->AddReusedIdleTime(idle_time()); | |
| 175 break; | |
| 176 default: | |
| 177 NOTREACHED(); | |
| 178 break; | |
| 179 } | |
| 180 | |
| 181 // Broadcast that the socket has been acquired. | 162 // Broadcast that the socket has been acquired. |
| 182 // TODO(eroman): This logging is not complete, in particular set_socket() and | 163 // TODO(eroman): This logging is not complete, in particular set_socket() and |
| 183 // release() socket. It ends up working though, since those methods are being | 164 // release() socket. It ends up working though, since those methods are being |
| 184 // used to layer sockets (and the destination sources are the same). | 165 // used to layer sockets (and the destination sources are the same). |
| 185 DCHECK(socket_.get()); | 166 DCHECK(socket_.get()); |
| 186 socket_->NetLog().BeginEvent( | 167 socket_->NetLog().BeginEvent( |
| 187 NetLog::TYPE_SOCKET_IN_USE, | 168 NetLog::TYPE_SOCKET_IN_USE, |
| 188 requesting_source_.ToEventParametersCallback()); | 169 requesting_source_.ToEventParametersCallback()); |
| 189 } | 170 } |
| 190 | 171 |
| 191 } // namespace net | 172 } // namespace net |
| OLD | NEW |