| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_loop.h" | 5 #include "base/message_loop.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" | 
| 11 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" | 
|  | 12 #include "base/debug/trace_event.h" | 
| 12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" | 
| 13 #include "base/logging.h" | 14 #include "base/logging.h" | 
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" | 
| 15 #include "base/message_loop_proxy_impl.h" | 16 #include "base/message_loop_proxy_impl.h" | 
| 16 #include "base/message_pump_default.h" | 17 #include "base/message_pump_default.h" | 
| 17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" | 
| 18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 19 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 
| 19 #include "base/threading/thread_local.h" | 20 #include "base/threading/thread_local.h" | 
| 20 #include "base/time.h" | 21 #include "base/time.h" | 
| 21 #include "base/tracked_objects.h" | 22 #include "base/tracked_objects.h" | 
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 451     return false; | 452     return false; | 
| 452 | 453 | 
| 453   PendingTask pending_task = deferred_non_nestable_work_queue_.front(); | 454   PendingTask pending_task = deferred_non_nestable_work_queue_.front(); | 
| 454   deferred_non_nestable_work_queue_.pop(); | 455   deferred_non_nestable_work_queue_.pop(); | 
| 455 | 456 | 
| 456   RunTask(pending_task); | 457   RunTask(pending_task); | 
| 457   return true; | 458   return true; | 
| 458 } | 459 } | 
| 459 | 460 | 
| 460 void MessageLoop::RunTask(const PendingTask& pending_task) { | 461 void MessageLoop::RunTask(const PendingTask& pending_task) { | 
|  | 462   UNSHIPPED_TRACE_EVENT2("task", "MessageLoop::RunTask", | 
|  | 463                          "src_file", pending_task.posted_from.file_name(), | 
|  | 464                          "src_func", pending_task.posted_from.function_name()); | 
| 461   DCHECK(nestable_tasks_allowed_); | 465   DCHECK(nestable_tasks_allowed_); | 
| 462   // Execute the task and assume the worst: It is probably not reentrant. | 466   // Execute the task and assume the worst: It is probably not reentrant. | 
| 463   nestable_tasks_allowed_ = false; | 467   nestable_tasks_allowed_ = false; | 
| 464 | 468 | 
| 465   // Before running the task, store the program counter where it was posted | 469   // Before running the task, store the program counter where it was posted | 
| 466   // and deliberately alias it to ensure it is on the stack if the task | 470   // and deliberately alias it to ensure it is on the stack if the task | 
| 467   // crashes. Be careful not to assume that the variable itself will have the | 471   // crashes. Be careful not to assume that the variable itself will have the | 
| 468   // expected value when displayed by the optimizer in an optimized build. | 472   // expected value when displayed by the optimizer in an optimized build. | 
| 469   // Look at a memory dump of the stack. | 473   // Look at a memory dump of the stack. | 
| 470   const void* program_counter = pending_task.birth_program_counter; | 474   const void* program_counter = | 
|  | 475       pending_task.posted_from.program_counter(); | 
| 471   base::debug::Alias(&program_counter); | 476   base::debug::Alias(&program_counter); | 
| 472 | 477 | 
| 473   HistogramEvent(kTaskRunEvent); | 478   HistogramEvent(kTaskRunEvent); | 
| 474   FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 479   FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 
| 475                     WillProcessTask(pending_task.time_posted)); | 480                     WillProcessTask(pending_task.time_posted)); | 
| 476   pending_task.task.Run(); | 481   pending_task.task.Run(); | 
| 477   FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 482   FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 
| 478                     DidProcessTask(pending_task.time_posted)); | 483                     DidProcessTask(pending_task.time_posted)); | 
| 479 | 484 | 
| 480 #if defined(TRACK_ALL_TASK_OBJECTS) | 485 #if defined(TRACK_ALL_TASK_OBJECTS) | 
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 758 // MessageLoop::PendingTask | 763 // MessageLoop::PendingTask | 
| 759 | 764 | 
| 760 MessageLoop::PendingTask::PendingTask( | 765 MessageLoop::PendingTask::PendingTask( | 
| 761     const base::Closure& task, | 766     const base::Closure& task, | 
| 762     const tracked_objects::Location& posted_from, | 767     const tracked_objects::Location& posted_from, | 
| 763     TimeTicks delayed_run_time, | 768     TimeTicks delayed_run_time, | 
| 764     bool nestable) | 769     bool nestable) | 
| 765     : task(task), | 770     : task(task), | 
| 766       time_posted(TimeTicks::Now()), | 771       time_posted(TimeTicks::Now()), | 
| 767       delayed_run_time(delayed_run_time), | 772       delayed_run_time(delayed_run_time), | 
|  | 773       posted_from(posted_from), | 
| 768       sequence_num(0), | 774       sequence_num(0), | 
| 769       nestable(nestable), | 775       nestable(nestable) { | 
| 770       birth_program_counter(posted_from.program_counter()) { |  | 
| 771 #if defined(TRACK_ALL_TASK_OBJECTS) | 776 #if defined(TRACK_ALL_TASK_OBJECTS) | 
| 772   post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); | 777   post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); | 
| 773 #endif  // defined(TRACK_ALL_TASK_OBJECTS) | 778 #endif  // defined(TRACK_ALL_TASK_OBJECTS) | 
| 774 } | 779 } | 
| 775 | 780 | 
| 776 MessageLoop::PendingTask::~PendingTask() { | 781 MessageLoop::PendingTask::~PendingTask() { | 
| 777 } | 782 } | 
| 778 | 783 | 
| 779 bool MessageLoop::PendingTask::operator<(const PendingTask& other) const { | 784 bool MessageLoop::PendingTask::operator<(const PendingTask& other) const { | 
| 780   // Since the top of a priority queue is defined as the "greatest" element, we | 785   // Since the top of a priority queue is defined as the "greatest" element, we | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 846                                            Watcher *delegate) { | 851                                            Watcher *delegate) { | 
| 847   return pump_libevent()->WatchFileDescriptor( | 852   return pump_libevent()->WatchFileDescriptor( | 
| 848       fd, | 853       fd, | 
| 849       persistent, | 854       persistent, | 
| 850       static_cast<base::MessagePumpLibevent::Mode>(mode), | 855       static_cast<base::MessagePumpLibevent::Mode>(mode), | 
| 851       controller, | 856       controller, | 
| 852       delegate); | 857       delegate); | 
| 853 } | 858 } | 
| 854 | 859 | 
| 855 #endif | 860 #endif | 
| OLD | NEW | 
|---|