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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/log/net_log_event_type.h" |
15 #include "net/socket/client_socket_pool.h" | 16 #include "net/socket/client_socket_pool.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 ClientSocketHandle::ClientSocketHandle() | 20 ClientSocketHandle::ClientSocketHandle() |
20 : is_initialized_(false), | 21 : is_initialized_(false), |
21 pool_(NULL), | 22 pool_(NULL), |
22 higher_pool_(NULL), | 23 higher_pool_(NULL), |
23 reuse_type_(ClientSocketHandle::UNUSED), | 24 reuse_type_(ClientSocketHandle::UNUSED), |
24 callback_(base::Bind(&ClientSocketHandle::OnIOComplete, | 25 callback_(base::Bind(&ClientSocketHandle::OnIOComplete, |
25 base::Unretained(this))), | 26 base::Unretained(this))), |
26 is_ssl_error_(false) {} | 27 is_ssl_error_(false) {} |
27 | 28 |
28 ClientSocketHandle::~ClientSocketHandle() { | 29 ClientSocketHandle::~ClientSocketHandle() { |
29 Reset(); | 30 Reset(); |
30 } | 31 } |
31 | 32 |
32 void ClientSocketHandle::Reset() { | 33 void ClientSocketHandle::Reset() { |
33 ResetInternal(true); | 34 ResetInternal(true); |
34 ResetErrorState(); | 35 ResetErrorState(); |
35 } | 36 } |
36 | 37 |
37 void ClientSocketHandle::ResetInternal(bool cancel) { | 38 void ClientSocketHandle::ResetInternal(bool cancel) { |
38 // Was Init called? | 39 // Was Init called? |
39 if (!group_name_.empty()) { | 40 if (!group_name_.empty()) { |
40 // If so, we must have a pool. | 41 // If so, we must have a pool. |
41 CHECK(pool_); | 42 CHECK(pool_); |
42 if (is_initialized()) { | 43 if (is_initialized()) { |
43 if (socket_) { | 44 if (socket_) { |
44 socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE); | 45 socket_->NetLog().EndEvent(NetLogEventType::SOCKET_IN_USE); |
45 // Release the socket back to the ClientSocketPool so it can be | 46 // Release the socket back to the ClientSocketPool so it can be |
46 // deleted or reused. | 47 // deleted or reused. |
47 pool_->ReleaseSocket(group_name_, std::move(socket_), pool_id_); | 48 pool_->ReleaseSocket(group_name_, std::move(socket_), pool_id_); |
48 } else { | 49 } else { |
49 // If the handle has been initialized, we should still have a | 50 // If the handle has been initialized, we should still have a |
50 // socket. | 51 // socket. |
51 NOTREACHED(); | 52 NOTREACHED(); |
52 } | 53 } |
53 } else if (cancel) { | 54 } else if (cancel) { |
54 // If we did not get initialized yet and we have a socket | 55 // If we did not get initialized yet and we have a socket |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 161 } |
161 is_initialized_ = true; | 162 is_initialized_ = true; |
162 CHECK_NE(-1, pool_id_) << "Pool should have set |pool_id_| to a valid value."; | 163 CHECK_NE(-1, pool_id_) << "Pool should have set |pool_id_| to a valid value."; |
163 setup_time_ = base::TimeTicks::Now() - init_time_; | 164 setup_time_ = base::TimeTicks::Now() - init_time_; |
164 | 165 |
165 // Broadcast that the socket has been acquired. | 166 // Broadcast that the socket has been acquired. |
166 // TODO(eroman): This logging is not complete, in particular set_socket() and | 167 // TODO(eroman): This logging is not complete, in particular set_socket() and |
167 // release() socket. It ends up working though, since those methods are being | 168 // release() socket. It ends up working though, since those methods are being |
168 // used to layer sockets (and the destination sources are the same). | 169 // used to layer sockets (and the destination sources are the same). |
169 DCHECK(socket_.get()); | 170 DCHECK(socket_.get()); |
170 socket_->NetLog().BeginEvent( | 171 socket_->NetLog().BeginEvent(NetLogEventType::SOCKET_IN_USE, |
171 NetLog::TYPE_SOCKET_IN_USE, | 172 requesting_source_.ToEventParametersCallback()); |
172 requesting_source_.ToEventParametersCallback()); | |
173 } | 173 } |
174 | 174 |
175 } // namespace net | 175 } // namespace net |
OLD | NEW |