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

Side by Side Diff: base/message_pump_win.cc

Issue 10831271: [Chromoting] Adding uiAccess='true' to the remoting_me2me_host.exe's manifest as it is required to … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased + a couple of merge fixes. Created 8 years, 4 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
« no previous file with comments | « base/message_pump_win.h ('k') | remoting/base/stoppable.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 "base/message_pump_win.h" 5 #include "base/message_pump_win.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 468
469 void MessagePumpForIO::ScheduleDelayedWork(const TimeTicks& delayed_work_time) { 469 void MessagePumpForIO::ScheduleDelayedWork(const TimeTicks& delayed_work_time) {
470 // We know that we can't be blocked right now since this method can only be 470 // We know that we can't be blocked right now since this method can only be
471 // called on the same thread as Run, so we only need to update our record of 471 // called on the same thread as Run, so we only need to update our record of
472 // how long to sleep when we do sleep. 472 // how long to sleep when we do sleep.
473 delayed_work_time_ = delayed_work_time; 473 delayed_work_time_ = delayed_work_time;
474 } 474 }
475 475
476 void MessagePumpForIO::RegisterIOHandler(HANDLE file_handle, 476 void MessagePumpForIO::RegisterIOHandler(HANDLE file_handle,
477 IOHandler* handler) { 477 IOHandler* handler) {
478 ULONG_PTR key = reinterpret_cast<ULONG_PTR>(handler); 478 ULONG_PTR key = HandlerToKey(handler, true);
479 HANDLE port = CreateIoCompletionPort(file_handle, port_, key, 1); 479 HANDLE port = CreateIoCompletionPort(file_handle, port_, key, 1);
480 DPCHECK(port); 480 DPCHECK(port);
481 } 481 }
482 482
483 bool MessagePumpForIO::RegisterJobObject(HANDLE job_handle,
484 IOHandler* handler) {
485 // Job object notifications use the OVERLAPPED pointer to carry the message
486 // data. Mark the completion key correspondingly, so we will not try to
487 // convert OVERLAPPED* to IOContext*.
488 ULONG_PTR key = HandlerToKey(handler, false);
489 JOBOBJECT_ASSOCIATE_COMPLETION_PORT info;
490 info.CompletionKey = reinterpret_cast<void*>(key);
491 info.CompletionPort = port_;
492 return SetInformationJobObject(job_handle,
493 JobObjectAssociateCompletionPortInformation,
494 &info,
495 sizeof(info)) != FALSE;
496 }
497
483 //----------------------------------------------------------------------------- 498 //-----------------------------------------------------------------------------
484 // MessagePumpForIO private: 499 // MessagePumpForIO private:
485 500
486 void MessagePumpForIO::DoRunLoop() { 501 void MessagePumpForIO::DoRunLoop() {
487 for (;;) { 502 for (;;) {
488 // If we do any work, we may create more messages etc., and more work may 503 // If we do any work, we may create more messages etc., and more work may
489 // possibly be waiting in another task group. When we (for example) 504 // possibly be waiting in another task group. When we (for example)
490 // WaitForIOCompletion(), there is a good chance there are still more 505 // WaitForIOCompletion(), there is a good chance there are still more
491 // messages waiting. On the other hand, when any of these methods return 506 // messages waiting. On the other hand, when any of these methods return
492 // having done no work, then it is pretty unlikely that calling them 507 // having done no work, then it is pretty unlikely that calling them
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 IOItem item; 554 IOItem item;
540 if (completed_io_.empty() || !MatchCompletedIOItem(filter, &item)) { 555 if (completed_io_.empty() || !MatchCompletedIOItem(filter, &item)) {
541 // We have to ask the system for another IO completion. 556 // We have to ask the system for another IO completion.
542 if (!GetIOItem(timeout, &item)) 557 if (!GetIOItem(timeout, &item))
543 return false; 558 return false;
544 559
545 if (ProcessInternalIOItem(item)) 560 if (ProcessInternalIOItem(item))
546 return true; 561 return true;
547 } 562 }
548 563
549 if (item.context->handler) { 564 // If |item.has_valid_io_context| is false then |item.context| does not point
565 // to a context structure, and so should not be dereferenced, although it may
566 // still hold valid non-pointer data.
567 if (!item.has_valid_io_context || item.context->handler) {
550 if (filter && item.handler != filter) { 568 if (filter && item.handler != filter) {
551 // Save this item for later 569 // Save this item for later
552 completed_io_.push_back(item); 570 completed_io_.push_back(item);
553 } else { 571 } else {
554 DCHECK_EQ(item.context->handler, item.handler); 572 DCHECK(!item.has_valid_io_context ||
573 (item.context->handler == item.handler));
555 WillProcessIOEvent(); 574 WillProcessIOEvent();
556 item.handler->OnIOCompleted(item.context, item.bytes_transfered, 575 item.handler->OnIOCompleted(item.context, item.bytes_transfered,
557 item.error); 576 item.error);
558 DidProcessIOEvent(); 577 DidProcessIOEvent();
559 } 578 }
560 } else { 579 } else {
561 // The handler must be gone by now, just cleanup the mess. 580 // The handler must be gone by now, just cleanup the mess.
562 delete item.context; 581 delete item.context;
563 } 582 }
564 return true; 583 return true;
565 } 584 }
566 585
567 // Asks the OS for another IO completion result. 586 // Asks the OS for another IO completion result.
568 bool MessagePumpForIO::GetIOItem(DWORD timeout, IOItem* item) { 587 bool MessagePumpForIO::GetIOItem(DWORD timeout, IOItem* item) {
569 memset(item, 0, sizeof(*item)); 588 memset(item, 0, sizeof(*item));
570 ULONG_PTR key = NULL; 589 ULONG_PTR key = NULL;
571 OVERLAPPED* overlapped = NULL; 590 OVERLAPPED* overlapped = NULL;
572 if (!GetQueuedCompletionStatus(port_.Get(), &item->bytes_transfered, &key, 591 if (!GetQueuedCompletionStatus(port_.Get(), &item->bytes_transfered, &key,
573 &overlapped, timeout)) { 592 &overlapped, timeout)) {
574 if (!overlapped) 593 if (!overlapped)
575 return false; // Nothing in the queue. 594 return false; // Nothing in the queue.
576 item->error = GetLastError(); 595 item->error = GetLastError();
577 item->bytes_transfered = 0; 596 item->bytes_transfered = 0;
578 } 597 }
579 598
580 item->handler = reinterpret_cast<IOHandler*>(key); 599 item->handler = KeyToHandler(key, &item->has_valid_io_context);
581 item->context = reinterpret_cast<IOContext*>(overlapped); 600 item->context = reinterpret_cast<IOContext*>(overlapped);
582 return true; 601 return true;
583 } 602 }
584 603
585 bool MessagePumpForIO::ProcessInternalIOItem(const IOItem& item) { 604 bool MessagePumpForIO::ProcessInternalIOItem(const IOItem& item) {
586 if (this == reinterpret_cast<MessagePumpForIO*>(item.context) && 605 if (this == reinterpret_cast<MessagePumpForIO*>(item.context) &&
587 this == reinterpret_cast<MessagePumpForIO*>(item.handler)) { 606 this == reinterpret_cast<MessagePumpForIO*>(item.handler)) {
588 // This is our internal completion. 607 // This is our internal completion.
589 DCHECK(!item.bytes_transfered); 608 DCHECK(!item.bytes_transfered);
590 InterlockedExchange(&have_work_, 0); 609 InterlockedExchange(&have_work_, 0);
(...skipping 25 matching lines...) Expand all
616 } 635 }
617 636
618 void MessagePumpForIO::WillProcessIOEvent() { 637 void MessagePumpForIO::WillProcessIOEvent() {
619 FOR_EACH_OBSERVER(IOObserver, io_observers_, WillProcessIOEvent()); 638 FOR_EACH_OBSERVER(IOObserver, io_observers_, WillProcessIOEvent());
620 } 639 }
621 640
622 void MessagePumpForIO::DidProcessIOEvent() { 641 void MessagePumpForIO::DidProcessIOEvent() {
623 FOR_EACH_OBSERVER(IOObserver, io_observers_, DidProcessIOEvent()); 642 FOR_EACH_OBSERVER(IOObserver, io_observers_, DidProcessIOEvent());
624 } 643 }
625 644
645 // static
646 ULONG_PTR MessagePumpForIO::HandlerToKey(IOHandler* handler,
647 bool has_valid_io_context) {
648 ULONG_PTR key = reinterpret_cast<ULONG_PTR>(handler);
649
650 // |IOHandler| is at least pointer-size aligned, so the lowest two bits are
651 // always cleared. We use the lowest bit to distinguish completion keys with
652 // and without the associated |IOContext|.
653 DCHECK((key & 1) == 0);
654
655 // Mark the completion key as context-less.
656 if (!has_valid_io_context)
657 key = key | 1;
658 return key;
659 }
660
661 // static
662 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler(
663 ULONG_PTR key,
664 bool* has_valid_io_context) {
665 *has_valid_io_context = ((key & 1) == 0);
666 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1));
667 }
668
626 } // namespace base 669 } // namespace base
OLDNEW
« no previous file with comments | « base/message_pump_win.h ('k') | remoting/base/stoppable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698