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

Side by Side Diff: ipc/ipc_channel_win.cc

Issue 14383024: ipc: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
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 "ipc/ipc_channel_win.h" 5 #include "ipc/ipc_channel_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Closing the handle at this point prevents us from issuing more requests 63 // Closing the handle at this point prevents us from issuing more requests
64 // form OnIOCompleted(). 64 // form OnIOCompleted().
65 if (pipe_ != INVALID_HANDLE_VALUE) { 65 if (pipe_ != INVALID_HANDLE_VALUE) {
66 CloseHandle(pipe_); 66 CloseHandle(pipe_);
67 pipe_ = INVALID_HANDLE_VALUE; 67 pipe_ = INVALID_HANDLE_VALUE;
68 } 68 }
69 69
70 // Make sure all IO has completed. 70 // Make sure all IO has completed.
71 base::Time start = base::Time::Now(); 71 base::Time start = base::Time::Now();
72 while (input_state_.is_pending || output_state_.is_pending) { 72 while (input_state_.is_pending || output_state_.is_pending) {
73 MessageLoopForIO::current()->WaitForIOCompletion(INFINITE, this); 73 base::MessageLoopForIO::current()->WaitForIOCompletion(INFINITE, this);
74 } 74 }
75 75
76 while (!output_queue_.empty()) { 76 while (!output_queue_.empty()) {
77 Message* m = output_queue_.front(); 77 Message* m = output_queue_.front();
78 output_queue_.pop(); 78 output_queue_.pop();
79 delete m; 79 delete m;
80 } 80 }
81 } 81 }
82 82
83 bool Channel::ChannelImpl::Send(Message* message) { 83 bool Channel::ChannelImpl::Send(Message* message) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 287
288 bool Channel::ChannelImpl::Connect() { 288 bool Channel::ChannelImpl::Connect() {
289 DLOG_IF(WARNING, thread_check_.get()) << "Connect called more than once"; 289 DLOG_IF(WARNING, thread_check_.get()) << "Connect called more than once";
290 290
291 if (!thread_check_.get()) 291 if (!thread_check_.get())
292 thread_check_.reset(new base::ThreadChecker()); 292 thread_check_.reset(new base::ThreadChecker());
293 293
294 if (pipe_ == INVALID_HANDLE_VALUE) 294 if (pipe_ == INVALID_HANDLE_VALUE)
295 return false; 295 return false;
296 296
297 MessageLoopForIO::current()->RegisterIOHandler(pipe_, this); 297 base::MessageLoopForIO::current()->RegisterIOHandler(pipe_, this);
298 298
299 // Check to see if there is a client connected to our pipe... 299 // Check to see if there is a client connected to our pipe...
300 if (waiting_connect_) 300 if (waiting_connect_)
301 ProcessConnection(); 301 ProcessConnection();
302 302
303 if (!input_state_.is_pending) { 303 if (!input_state_.is_pending) {
304 // Complete setup asynchronously. By not setting input_state_.is_pending 304 // Complete setup asynchronously. By not setting input_state_.is_pending
305 // to true, we indicate to OnIOCompleted that this is the special 305 // to true, we indicate to OnIOCompleted that this is the special
306 // initialization signal. 306 // initialization signal.
307 MessageLoopForIO::current()->PostTask( 307 base::MessageLoopForIO::current()->PostTask(
308 FROM_HERE, base::Bind(&Channel::ChannelImpl::OnIOCompleted, 308 FROM_HERE,
309 weak_factory_.GetWeakPtr(), &input_state_.context, 309 base::Bind(&Channel::ChannelImpl::OnIOCompleted,
310 0, 0)); 310 weak_factory_.GetWeakPtr(),
311 &input_state_.context,
312 0,
313 0));
311 } 314 }
312 315
313 if (!waiting_connect_) 316 if (!waiting_connect_)
314 ProcessOutgoingMessages(NULL, 0); 317 ProcessOutgoingMessages(NULL, 0);
315 return true; 318 return true;
316 } 319 }
317 320
318 bool Channel::ChannelImpl::ProcessConnection() { 321 bool Channel::ChannelImpl::ProcessConnection() {
319 DCHECK(thread_check_->CalledOnValidThread()); 322 DCHECK(thread_check_->CalledOnValidThread());
320 if (input_state_.is_pending) 323 if (input_state_.is_pending)
(...skipping 25 matching lines...) Expand all
346 return false; 349 return false;
347 default: 350 default:
348 NOTREACHED(); 351 NOTREACHED();
349 return false; 352 return false;
350 } 353 }
351 354
352 return true; 355 return true;
353 } 356 }
354 357
355 bool Channel::ChannelImpl::ProcessOutgoingMessages( 358 bool Channel::ChannelImpl::ProcessOutgoingMessages(
356 MessageLoopForIO::IOContext* context, 359 base::MessageLoopForIO::IOContext* context,
357 DWORD bytes_written) { 360 DWORD bytes_written) {
358 DCHECK(!waiting_connect_); // Why are we trying to send messages if there's 361 DCHECK(!waiting_connect_); // Why are we trying to send messages if there's
359 // no connection? 362 // no connection?
360 DCHECK(thread_check_->CalledOnValidThread()); 363 DCHECK(thread_check_->CalledOnValidThread());
361 364
362 if (output_state_.is_pending) { 365 if (output_state_.is_pending) {
363 DCHECK(context); 366 DCHECK(context);
364 output_state_.is_pending = false; 367 output_state_.is_pending = false;
365 if (!context || bytes_written == 0) { 368 if (!context || bytes_written == 0) {
366 DWORD err = GetLastError(); 369 DWORD err = GetLastError();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 return false; 405 return false;
403 } 406 }
404 407
405 DVLOG(2) << "sent message @" << m << " on channel @" << this 408 DVLOG(2) << "sent message @" << m << " on channel @" << this
406 << " with type " << m->type(); 409 << " with type " << m->type();
407 410
408 output_state_.is_pending = true; 411 output_state_.is_pending = true;
409 return true; 412 return true;
410 } 413 }
411 414
412 void Channel::ChannelImpl::OnIOCompleted(MessageLoopForIO::IOContext* context, 415 void Channel::ChannelImpl::OnIOCompleted(
413 DWORD bytes_transfered, 416 base::MessageLoopForIO::IOContext* context,
414 DWORD error) { 417 DWORD bytes_transfered,
418 DWORD error) {
415 bool ok = true; 419 bool ok = true;
416 DCHECK(thread_check_->CalledOnValidThread()); 420 DCHECK(thread_check_->CalledOnValidThread());
417 if (context == &input_state_.context) { 421 if (context == &input_state_.context) {
418 if (waiting_connect_) { 422 if (waiting_connect_) {
419 if (!ProcessConnection()) 423 if (!ProcessConnection())
420 return; 424 return;
421 // We may have some messages queued up to send... 425 // We may have some messages queued up to send...
422 if (!output_queue_.empty() && !output_state_.is_pending) 426 if (!output_queue_.empty() && !output_state_.is_pending)
423 ProcessOutgoingMessages(NULL, 0); 427 ProcessOutgoingMessages(NULL, 0);
424 if (input_state_.is_pending) 428 if (input_state_.is_pending)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 int secret; 508 int secret;
505 do { // Guarantee we get a non-zero value. 509 do { // Guarantee we get a non-zero value.
506 secret = base::RandInt(0, std::numeric_limits<int>::max()); 510 secret = base::RandInt(0, std::numeric_limits<int>::max());
507 } while (secret == 0); 511 } while (secret == 0);
508 512
509 id.append(GenerateUniqueRandomChannelID()); 513 id.append(GenerateUniqueRandomChannelID());
510 return id.append(base::StringPrintf("\\%d", secret)); 514 return id.append(base::StringPrintf("\\%d", secret));
511 } 515 }
512 516
513 } // namespace IPC 517 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698