OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "net/socket/client_socket_pool.h" | 11 #include "net/socket/client_socket_pool.h" |
12 #include "net/socket/client_socket_pool_histograms.h" | 12 #include "net/socket/client_socket_pool_histograms.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 | 15 |
16 ClientSocketHandle::ClientSocketHandle() | 16 ClientSocketHandle::ClientSocketHandle() |
17 : socket_(NULL), | 17 : socket_(NULL), |
18 is_reused_(false), | 18 is_reused_(false), |
19 ALLOW_THIS_IN_INITIALIZER_LIST( | 19 ALLOW_THIS_IN_INITIALIZER_LIST( |
20 callback_(this, &ClientSocketHandle::OnIOComplete)) {} | 20 callback_(this, &ClientSocketHandle::OnIOComplete)), |
| 21 is_ssl_error_(false) {} |
21 | 22 |
22 ClientSocketHandle::~ClientSocketHandle() { | 23 ClientSocketHandle::~ClientSocketHandle() { |
23 Reset(); | 24 Reset(); |
24 } | 25 } |
25 | 26 |
26 void ClientSocketHandle::Reset() { | 27 void ClientSocketHandle::Reset() { |
27 ResetInternal(true); | 28 ResetInternal(true); |
| 29 ResetErrorState(); |
28 } | 30 } |
29 | 31 |
30 void ClientSocketHandle::ResetInternal(bool cancel) { | 32 void ClientSocketHandle::ResetInternal(bool cancel) { |
31 if (group_name_.empty()) // Was Init called? | 33 if (group_name_.empty()) // Was Init called? |
32 return; | 34 return; |
33 if (socket_.get()) { | 35 if (socket_.get()) { |
34 // Because of http://crbug.com/37810 we may not have a pool, but have | 36 // Because of http://crbug.com/37810 we may not have a pool, but have |
35 // just a raw socket. | 37 // just a raw socket. |
36 socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE, NULL); | 38 socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE, NULL); |
37 if (pool_) | 39 if (pool_) |
38 // If we've still got a socket, release it back to the ClientSocketPool so | 40 // If we've still got a socket, release it back to the ClientSocketPool so |
39 // it can be deleted or reused. | 41 // it can be deleted or reused. |
40 pool_->ReleaseSocket(group_name_, release_socket(), pool_id_); | 42 pool_->ReleaseSocket(group_name_, release_socket(), pool_id_); |
41 } else if (cancel) { | 43 } else if (cancel) { |
42 // If we did not get initialized yet, so we've got a socket request pending. | 44 // If we did not get initialized yet, so we've got a socket request pending. |
43 // Cancel it. | 45 // Cancel it. |
44 pool_->CancelRequest(group_name_, this); | 46 pool_->CancelRequest(group_name_, this); |
45 } | 47 } |
46 group_name_.clear(); | 48 group_name_.clear(); |
47 is_reused_ = false; | 49 is_reused_ = false; |
48 user_callback_ = NULL; | 50 user_callback_ = NULL; |
49 pool_ = NULL; | 51 pool_ = NULL; |
50 idle_time_ = base::TimeDelta(); | 52 idle_time_ = base::TimeDelta(); |
51 init_time_ = base::TimeTicks(); | 53 init_time_ = base::TimeTicks(); |
52 setup_time_ = base::TimeDelta(); | 54 setup_time_ = base::TimeDelta(); |
53 pool_id_ = -1; | 55 pool_id_ = -1; |
54 } | 56 } |
55 | 57 |
| 58 void ClientSocketHandle::ResetErrorState() { |
| 59 is_ssl_error_ = false; |
| 60 tunnel_auth_response_info_ = HttpResponseInfo(); |
| 61 } |
| 62 |
56 LoadState ClientSocketHandle::GetLoadState() const { | 63 LoadState ClientSocketHandle::GetLoadState() const { |
57 CHECK(!is_initialized()); | 64 CHECK(!is_initialized()); |
58 CHECK(!group_name_.empty()); | 65 CHECK(!group_name_.empty()); |
59 // Because of http://crbug.com/37810 we may not have a pool, but have | 66 // Because of http://crbug.com/37810 we may not have a pool, but have |
60 // just a raw socket. | 67 // just a raw socket. |
61 if (!pool_) | 68 if (!pool_) |
62 return LOAD_STATE_IDLE; | 69 return LOAD_STATE_IDLE; |
63 return pool_->GetLoadState(group_name_, this); | 70 return pool_->GetLoadState(group_name_, this); |
64 } | 71 } |
65 | 72 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // TODO(eroman): This logging is not complete, in particular set_socket() and | 108 // TODO(eroman): This logging is not complete, in particular set_socket() and |
102 // release() socket. It ends up working though, since those methods are being | 109 // release() socket. It ends up working though, since those methods are being |
103 // used to layer sockets (and the destination sources are the same). | 110 // used to layer sockets (and the destination sources are the same). |
104 DCHECK(socket_.get()); | 111 DCHECK(socket_.get()); |
105 socket_->NetLog().BeginEvent( | 112 socket_->NetLog().BeginEvent( |
106 NetLog::TYPE_SOCKET_IN_USE, | 113 NetLog::TYPE_SOCKET_IN_USE, |
107 new NetLogSourceParameter("source_dependency", requesting_source_)); | 114 new NetLogSourceParameter("source_dependency", requesting_source_)); |
108 } | 115 } |
109 | 116 |
110 } // namespace net | 117 } // namespace net |
OLD | NEW |