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

Side by Side Diff: jingle/glue/chrome_async_socket.cc

Issue 2082353002: Remove calls to deprecated MessageLoop methods in jingle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use ThreadTaskRunnerHandle Created 4 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 | « no previous file | jingle/glue/proxy_resolving_client_socket_unittest.cc » ('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 "jingle/glue/chrome_async_socket.h" 5 #include "jingle/glue/chrome_async_socket.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <cstdlib> 9 #include <cstdlib>
10 #include <cstring> 10 #include <cstring>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "jingle/glue/resolving_client_socket_factory.h" 17 #include "jingle/glue/resolving_client_socket_factory.h"
18 #include "net/base/address_list.h" 18 #include "net/base/address_list.h"
19 #include "net/base/host_port_pair.h" 19 #include "net/base/host_port_pair.h"
20 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
21 #include "net/socket/client_socket_handle.h" 21 #include "net/socket/client_socket_handle.h"
22 #include "net/socket/ssl_client_socket.h" 22 #include "net/socket/ssl_client_socket.h"
23 #include "net/socket/tcp_client_socket.h" 23 #include "net/socket/tcp_client_socket.h"
24 #include "net/ssl/ssl_config_service.h" 24 #include "net/ssl/ssl_config_service.h"
25 #include "third_party/webrtc/base/socketaddress.h" 25 #include "third_party/webrtc/base/socketaddress.h"
26 26
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 resolving_client_socket_factory_->CreateTransportClientSocket( 110 resolving_client_socket_factory_->CreateTransportClientSocket(
111 dest_host_port_pair); 111 dest_host_port_pair);
112 int status = transport_socket_->Connect( 112 int status = transport_socket_->Connect(
113 base::Bind(&ChromeAsyncSocket::ProcessConnectDone, 113 base::Bind(&ChromeAsyncSocket::ProcessConnectDone,
114 weak_ptr_factory_.GetWeakPtr())); 114 weak_ptr_factory_.GetWeakPtr()));
115 if (status != net::ERR_IO_PENDING) { 115 if (status != net::ERR_IO_PENDING) {
116 // We defer execution of ProcessConnectDone instead of calling it 116 // We defer execution of ProcessConnectDone instead of calling it
117 // directly here as the caller may not expect an error/close to 117 // directly here as the caller may not expect an error/close to
118 // happen here. This is okay, as from the caller's point of view, 118 // happen here. This is okay, as from the caller's point of view,
119 // the connect always happens asynchronously. 119 // the connect always happens asynchronously.
120 base::MessageLoop* message_loop = base::MessageLoop::current(); 120 base::ThreadTaskRunnerHandle::Get()->PostTask(
121 CHECK(message_loop); 121 FROM_HERE, base::Bind(&ChromeAsyncSocket::ProcessConnectDone,
122 message_loop->PostTask( 122 weak_ptr_factory_.GetWeakPtr(), status));
123 FROM_HERE,
124 base::Bind(&ChromeAsyncSocket::ProcessConnectDone,
125 weak_ptr_factory_.GetWeakPtr(), status));
126 } 123 }
127 return true; 124 return true;
128 } 125 }
129 126
130 // STATE_CONNECTING -> STATE_OPEN 127 // STATE_CONNECTING -> STATE_OPEN
131 // read_state_ == IDLE -> read_state_ == POSTED (via PostDoRead()) 128 // read_state_ == IDLE -> read_state_ == POSTED (via PostDoRead())
132 129
133 void ChromeAsyncSocket::ProcessConnectDone(int status) { 130 void ChromeAsyncSocket::ProcessConnectDone(int status) {
134 DCHECK_NE(status, net::ERR_IO_PENDING); 131 DCHECK_NE(status, net::ERR_IO_PENDING);
135 DCHECK_EQ(read_state_, IDLE); 132 DCHECK_EQ(read_state_, IDLE);
(...skipping 11 matching lines...) Expand all
147 SignalConnected(); 144 SignalConnected();
148 } 145 }
149 146
150 // read_state_ == IDLE -> read_state_ == POSTED 147 // read_state_ == IDLE -> read_state_ == POSTED
151 148
152 void ChromeAsyncSocket::PostDoRead() { 149 void ChromeAsyncSocket::PostDoRead() {
153 DCHECK(IsOpen()); 150 DCHECK(IsOpen());
154 DCHECK_EQ(read_state_, IDLE); 151 DCHECK_EQ(read_state_, IDLE);
155 DCHECK_EQ(read_start_, 0U); 152 DCHECK_EQ(read_start_, 0U);
156 DCHECK_EQ(read_end_, 0U); 153 DCHECK_EQ(read_end_, 0U);
157 base::MessageLoop* message_loop = base::MessageLoop::current(); 154 base::ThreadTaskRunnerHandle::Get()->PostTask(
158 CHECK(message_loop);
159 message_loop->PostTask(
160 FROM_HERE, 155 FROM_HERE,
161 base::Bind(&ChromeAsyncSocket::DoRead, 156 base::Bind(&ChromeAsyncSocket::DoRead, weak_ptr_factory_.GetWeakPtr()));
162 weak_ptr_factory_.GetWeakPtr()));
163 read_state_ = POSTED; 157 read_state_ = POSTED;
164 } 158 }
165 159
166 // read_state_ == POSTED -> read_state_ == PENDING 160 // read_state_ == POSTED -> read_state_ == PENDING
167 161
168 void ChromeAsyncSocket::DoRead() { 162 void ChromeAsyncSocket::DoRead() {
169 DCHECK(IsOpen()); 163 DCHECK(IsOpen());
170 DCHECK_EQ(read_state_, POSTED); 164 DCHECK_EQ(read_state_, POSTED);
171 DCHECK_EQ(read_start_, 0U); 165 DCHECK_EQ(read_start_, 0U);
172 DCHECK_EQ(read_end_, 0U); 166 DCHECK_EQ(read_end_, 0U);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 275 }
282 return true; 276 return true;
283 } 277 }
284 278
285 // write_state_ == IDLE -> write_state_ == POSTED 279 // write_state_ == IDLE -> write_state_ == POSTED
286 280
287 void ChromeAsyncSocket::PostDoWrite() { 281 void ChromeAsyncSocket::PostDoWrite() {
288 DCHECK(IsOpen()); 282 DCHECK(IsOpen());
289 DCHECK_EQ(write_state_, IDLE); 283 DCHECK_EQ(write_state_, IDLE);
290 DCHECK_GT(write_end_, 0U); 284 DCHECK_GT(write_end_, 0U);
291 base::MessageLoop* message_loop = base::MessageLoop::current(); 285 base::ThreadTaskRunnerHandle::Get()->PostTask(
292 CHECK(message_loop);
293 message_loop->PostTask(
294 FROM_HERE, 286 FROM_HERE,
295 base::Bind(&ChromeAsyncSocket::DoWrite, 287 base::Bind(&ChromeAsyncSocket::DoWrite, weak_ptr_factory_.GetWeakPtr()));
296 weak_ptr_factory_.GetWeakPtr()));
297 write_state_ = POSTED; 288 write_state_ = POSTED;
298 } 289 }
299 290
300 // write_state_ == POSTED -> write_state_ == PENDING 291 // write_state_ == POSTED -> write_state_ == PENDING
301 292
302 void ChromeAsyncSocket::DoWrite() { 293 void ChromeAsyncSocket::DoWrite() {
303 DCHECK(IsOpen()); 294 DCHECK(IsOpen());
304 DCHECK_EQ(write_state_, POSTED); 295 DCHECK_EQ(write_state_, POSTED);
305 DCHECK_GT(write_end_, 0U); 296 DCHECK_GT(write_end_, 0U);
306 // Once we call Write(), we cannot call StartTls() until the write 297 // Once we call Write(), we cannot call StartTls() until the write
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 DCHECK(transport_socket_.get()); 395 DCHECK(transport_socket_.get());
405 std::unique_ptr<net::ClientSocketHandle> socket_handle( 396 std::unique_ptr<net::ClientSocketHandle> socket_handle(
406 new net::ClientSocketHandle()); 397 new net::ClientSocketHandle());
407 socket_handle->SetSocket(std::move(transport_socket_)); 398 socket_handle->SetSocket(std::move(transport_socket_));
408 transport_socket_ = resolving_client_socket_factory_->CreateSSLClientSocket( 399 transport_socket_ = resolving_client_socket_factory_->CreateSSLClientSocket(
409 std::move(socket_handle), net::HostPortPair(domain_name, 443)); 400 std::move(socket_handle), net::HostPortPair(domain_name, 443));
410 int status = transport_socket_->Connect( 401 int status = transport_socket_->Connect(
411 base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone, 402 base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone,
412 weak_ptr_factory_.GetWeakPtr())); 403 weak_ptr_factory_.GetWeakPtr()));
413 if (status != net::ERR_IO_PENDING) { 404 if (status != net::ERR_IO_PENDING) {
414 base::MessageLoop* message_loop = base::MessageLoop::current(); 405 base::ThreadTaskRunnerHandle::Get()->PostTask(
415 CHECK(message_loop); 406 FROM_HERE, base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone,
416 message_loop->PostTask( 407 weak_ptr_factory_.GetWeakPtr(), status));
417 FROM_HERE,
418 base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone,
419 weak_ptr_factory_.GetWeakPtr(), status));
420 } 408 }
421 return true; 409 return true;
422 } 410 }
423 411
424 // STATE_TLS_CONNECTING -> STATE_TLS_OPEN 412 // STATE_TLS_CONNECTING -> STATE_TLS_OPEN
425 // read_state_ == IDLE -> read_state_ == POSTED (via PostDoRead()) 413 // read_state_ == IDLE -> read_state_ == POSTED (via PostDoRead())
426 // (maybe) write_state_ == IDLE -> write_state_ == POSTED (via 414 // (maybe) write_state_ == IDLE -> write_state_ == POSTED (via
427 // PostDoWrite()) 415 // PostDoWrite())
428 416
429 void ChromeAsyncSocket::ProcessSSLConnectDone(int status) { 417 void ChromeAsyncSocket::ProcessSSLConnectDone(int status) {
(...skipping 10 matching lines...) Expand all
440 } 428 }
441 state_ = STATE_TLS_OPEN; 429 state_ = STATE_TLS_OPEN;
442 PostDoRead(); 430 PostDoRead();
443 if (write_end_ > 0U) { 431 if (write_end_ > 0U) {
444 PostDoWrite(); 432 PostDoWrite();
445 } 433 }
446 SignalSSLConnected(); 434 SignalSSLConnected();
447 } 435 }
448 436
449 } // namespace jingle_glue 437 } // namespace jingle_glue
OLDNEW
« no previous file with comments | « no previous file | jingle/glue/proxy_resolving_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698