Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Side by Side Diff: net/socket/client_socket_handle.cc

Issue 2647003: Do not attempt to reuse active sockets after a socket pool flush (usually a network change). (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Address eroman comments. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/socket/client_socket_handle.h ('k') | net/socket/client_socket_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 19 matching lines...) Expand all
30 void ClientSocketHandle::ResetInternal(bool cancel) { 30 void ClientSocketHandle::ResetInternal(bool cancel) {
31 if (group_name_.empty()) // Was Init called? 31 if (group_name_.empty()) // Was Init called?
32 return; 32 return;
33 if (socket_.get()) { 33 if (socket_.get()) {
34 // Because of http://crbug.com/37810 we may not have a pool, but have 34 // Because of http://crbug.com/37810 we may not have a pool, but have
35 // just a raw socket. 35 // just a raw socket.
36 socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE, NULL); 36 socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE, NULL);
37 if (pool_) 37 if (pool_)
38 // If we've still got a socket, release it back to the ClientSocketPool so 38 // If we've still got a socket, release it back to the ClientSocketPool so
39 // it can be deleted or reused. 39 // it can be deleted or reused.
40 pool_->ReleaseSocket(group_name_, release_socket()); 40 pool_->ReleaseSocket(group_name_, release_socket(), pool_id_);
41 } else if (cancel) { 41 } else if (cancel) {
42 // If we did not get initialized yet, so we've got a socket request pending. 42 // If we did not get initialized yet, so we've got a socket request pending.
43 // Cancel it. 43 // Cancel it.
44 pool_->CancelRequest(group_name_, this); 44 pool_->CancelRequest(group_name_, this);
45 } 45 }
46 group_name_.clear(); 46 group_name_.clear();
47 is_reused_ = false; 47 is_reused_ = false;
48 user_callback_ = NULL; 48 user_callback_ = NULL;
49 pool_ = NULL; 49 pool_ = NULL;
50 idle_time_ = base::TimeDelta(); 50 idle_time_ = base::TimeDelta();
51 init_time_ = base::TimeTicks(); 51 init_time_ = base::TimeTicks();
52 setup_time_ = base::TimeDelta(); 52 setup_time_ = base::TimeDelta();
53 pool_id_ = -1;
53 } 54 }
54 55
55 LoadState ClientSocketHandle::GetLoadState() const { 56 LoadState ClientSocketHandle::GetLoadState() const {
56 CHECK(!is_initialized()); 57 CHECK(!is_initialized());
57 CHECK(!group_name_.empty()); 58 CHECK(!group_name_.empty());
58 // Because of http://crbug.com/37810 we may not have a pool, but have 59 // Because of http://crbug.com/37810 we may not have a pool, but have
59 // just a raw socket. 60 // just a raw socket.
60 if (!pool_) 61 if (!pool_)
61 return LOAD_STATE_IDLE; 62 return LOAD_STATE_IDLE;
62 return pool_->GetLoadState(group_name_, this); 63 return pool_->GetLoadState(group_name_, this);
63 } 64 }
64 65
65 void ClientSocketHandle::OnIOComplete(int result) { 66 void ClientSocketHandle::OnIOComplete(int result) {
66 CompletionCallback* callback = user_callback_; 67 CompletionCallback* callback = user_callback_;
67 user_callback_ = NULL; 68 user_callback_ = NULL;
68 HandleInitCompletion(result); 69 HandleInitCompletion(result);
69 callback->Run(result); 70 callback->Run(result);
70 } 71 }
71 72
72 void ClientSocketHandle::HandleInitCompletion(int result) { 73 void ClientSocketHandle::HandleInitCompletion(int result) {
73 CHECK_NE(ERR_IO_PENDING, result); 74 CHECK_NE(ERR_IO_PENDING, result);
74 if (result != OK) { 75 if (result != OK) {
75 ResetInternal(false); // The request failed, so there's nothing to cancel. 76 ResetInternal(false); // The request failed, so there's nothing to cancel.
76 return; 77 return;
77 } 78 }
79 CHECK_NE(-1, pool_id_) << "Pool should have set |pool_id_| to a valid value.";
78 setup_time_ = base::TimeTicks::Now() - init_time_; 80 setup_time_ = base::TimeTicks::Now() - init_time_;
79 81
80 scoped_refptr<ClientSocketPoolHistograms> histograms = pool_->histograms(); 82 scoped_refptr<ClientSocketPoolHistograms> histograms = pool_->histograms();
81 histograms->AddSocketType(reuse_type()); 83 histograms->AddSocketType(reuse_type());
82 switch (reuse_type()) { 84 switch (reuse_type()) {
83 case ClientSocketHandle::UNUSED: 85 case ClientSocketHandle::UNUSED:
84 histograms->AddRequestTime(setup_time()); 86 histograms->AddRequestTime(setup_time());
85 break; 87 break;
86 case ClientSocketHandle::UNUSED_IDLE: 88 case ClientSocketHandle::UNUSED_IDLE:
87 histograms->AddUnusedIdleTime(idle_time()); 89 histograms->AddUnusedIdleTime(idle_time());
(...skipping 10 matching lines...) Expand all
98 // TODO(eroman): This logging is not complete, in particular set_socket() and 100 // TODO(eroman): This logging is not complete, in particular set_socket() and
99 // release() socket. It ends up working though, since those methods are being 101 // release() socket. It ends up working though, since those methods are being
100 // used to layer sockets (and the destination sources are the same). 102 // used to layer sockets (and the destination sources are the same).
101 DCHECK(socket_.get()); 103 DCHECK(socket_.get());
102 socket_->NetLog().BeginEvent( 104 socket_->NetLog().BeginEvent(
103 NetLog::TYPE_SOCKET_IN_USE, 105 NetLog::TYPE_SOCKET_IN_USE,
104 new NetLogSourceParameter("source_dependency", requesting_source_)); 106 new NetLogSourceParameter("source_dependency", requesting_source_));
105 } 107 }
106 108
107 } // namespace net 109 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_handle.h ('k') | net/socket/client_socket_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698