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

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

Issue 1545233002: Convert Pass()→std::move() in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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_factory.cc ('k') | net/socket/client_socket_pool_base.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) 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>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
12 #include "net/socket/client_socket_pool.h" 14 #include "net/socket/client_socket_pool.h"
13 15
14 namespace net { 16 namespace net {
15 17
16 ClientSocketHandle::ClientSocketHandle() 18 ClientSocketHandle::ClientSocketHandle()
(...skipping 19 matching lines...) Expand all
36 void ClientSocketHandle::ResetInternal(bool cancel) { 38 void ClientSocketHandle::ResetInternal(bool cancel) {
37 // Was Init called? 39 // Was Init called?
38 if (!group_name_.empty()) { 40 if (!group_name_.empty()) {
39 // If so, we must have a pool. 41 // If so, we must have a pool.
40 CHECK(pool_); 42 CHECK(pool_);
41 if (is_initialized()) { 43 if (is_initialized()) {
42 if (socket_) { 44 if (socket_) {
43 socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE); 45 socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE);
44 // Release the socket back to the ClientSocketPool so it can be 46 // Release the socket back to the ClientSocketPool so it can be
45 // deleted or reused. 47 // deleted or reused.
46 pool_->ReleaseSocket(group_name_, socket_.Pass(), pool_id_); 48 pool_->ReleaseSocket(group_name_, std::move(socket_), pool_id_);
47 } else { 49 } else {
48 // If the handle has been initialized, we should still have a 50 // If the handle has been initialized, we should still have a
49 // socket. 51 // socket.
50 NOTREACHED(); 52 NOTREACHED();
51 } 53 }
52 } else if (cancel) { 54 } else if (cancel) {
53 // 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
54 // request pending, cancel it. 56 // request pending, cancel it.
55 pool_->CancelRequest(group_name_, this); 57 pool_->CancelRequest(group_name_, this);
56 } 58 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 129
128 // No times if the socket is reused. 130 // No times if the socket is reused.
129 if (is_reused) 131 if (is_reused)
130 return true; 132 return true;
131 133
132 load_timing_info->connect_timing = connect_timing_; 134 load_timing_info->connect_timing = connect_timing_;
133 return true; 135 return true;
134 } 136 }
135 137
136 void ClientSocketHandle::SetSocket(scoped_ptr<StreamSocket> s) { 138 void ClientSocketHandle::SetSocket(scoped_ptr<StreamSocket> s) {
137 socket_ = s.Pass(); 139 socket_ = std::move(s);
138 } 140 }
139 141
140 void ClientSocketHandle::OnIOComplete(int result) { 142 void ClientSocketHandle::OnIOComplete(int result) {
141 CompletionCallback callback = user_callback_; 143 CompletionCallback callback = user_callback_;
142 user_callback_.Reset(); 144 user_callback_.Reset();
143 HandleInitCompletion(result); 145 HandleInitCompletion(result);
144 callback.Run(result); 146 callback.Run(result);
145 } 147 }
146 148
147 scoped_ptr<StreamSocket> ClientSocketHandle::PassSocket() { 149 scoped_ptr<StreamSocket> ClientSocketHandle::PassSocket() {
148 return socket_.Pass(); 150 return std::move(socket_);
149 } 151 }
150 152
151 void ClientSocketHandle::HandleInitCompletion(int result) { 153 void ClientSocketHandle::HandleInitCompletion(int result) {
152 CHECK_NE(ERR_IO_PENDING, result); 154 CHECK_NE(ERR_IO_PENDING, result);
153 if (result != OK) { 155 if (result != OK) {
154 if (!socket_.get()) 156 if (!socket_.get())
155 ResetInternal(false); // Nothing to cancel since the request failed. 157 ResetInternal(false); // Nothing to cancel since the request failed.
156 else 158 else
157 is_initialized_ = true; 159 is_initialized_ = true;
158 return; 160 return;
159 } 161 }
160 is_initialized_ = true; 162 is_initialized_ = true;
161 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.";
162 setup_time_ = base::TimeTicks::Now() - init_time_; 164 setup_time_ = base::TimeTicks::Now() - init_time_;
163 165
164 // Broadcast that the socket has been acquired. 166 // Broadcast that the socket has been acquired.
165 // 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
166 // 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
167 // used to layer sockets (and the destination sources are the same). 169 // used to layer sockets (and the destination sources are the same).
168 DCHECK(socket_.get()); 170 DCHECK(socket_.get());
169 socket_->NetLog().BeginEvent( 171 socket_->NetLog().BeginEvent(
170 NetLog::TYPE_SOCKET_IN_USE, 172 NetLog::TYPE_SOCKET_IN_USE,
171 requesting_source_.ToEventParametersCallback()); 173 requesting_source_.ToEventParametersCallback());
172 } 174 }
173 175
174 } // namespace net 176 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_factory.cc ('k') | net/socket/client_socket_pool_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698