summaryrefslogtreecommitdiffstats
path: root/chromium/base/message_loop/message_loop.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-01-04 14:17:57 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-01-05 10:05:06 +0000
commit39d357e3248f80abea0159765ff39554affb40db (patch)
treeaba0e6bfb76de0244bba0f5fdbd64b830dd6e621 /chromium/base/message_loop/message_loop.cc
parent87778abf5a1f89266f37d1321b92a21851d8244d (diff)
BASELINE: Update Chromium to 55.0.2883.105
And updates ninja to 1.7.2 Change-Id: I20d43c737f82764d857ada9a55586901b18b9243 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/base/message_loop/message_loop.cc')
-rw-r--r--chromium/base/message_loop/message_loop.cc181
1 files changed, 35 insertions, 146 deletions
diff --git a/chromium/base/message_loop/message_loop.cc b/chromium/base/message_loop/message_loop.cc
index 9d3769169cf..74287b148e6 100644
--- a/chromium/base/message_loop/message_loop.cc
+++ b/chromium/base/message_loop/message_loop.cc
@@ -5,7 +5,6 @@
#include "base/message_loop/message_loop.h"
#include <algorithm>
-#include <memory>
#include <utility>
#include "base/bind.h"
@@ -14,17 +13,12 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_pump_default.h"
-#include "base/metrics/histogram.h"
-#include "base/metrics/statistics_recorder.h"
#include "base/run_loop.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/thread_id_name_manager.h"
#include "base/threading/thread_local.h"
#include "base/threading/thread_task_runner_handle.h"
-#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
-#include "base/tracked_objects.h"
-#include "build/build_config.h"
#if defined(OS_MACOSX)
#include "base/message_loop/message_pump_mac.h"
@@ -48,47 +42,6 @@ namespace {
LazyInstance<base::ThreadLocalPointer<MessageLoop> >::Leaky lazy_tls_ptr =
LAZY_INSTANCE_INITIALIZER;
-// Logical events for Histogram profiling. Run with --message-loop-histogrammer
-// to get an accounting of messages and actions taken on each thread.
-const int kTaskRunEvent = 0x1;
-#if !defined(OS_NACL)
-const int kTimerEvent = 0x2;
-
-// Provide range of message IDs for use in histogramming and debug display.
-const int kLeastNonZeroMessageId = 1;
-const int kMaxMessageId = 1099;
-const int kNumberOfDistinctMessagesDisplayed = 1100;
-
-// Provide a macro that takes an expression (such as a constant, or macro
-// constant) and creates a pair to initialize an array of pairs. In this case,
-// our pair consists of the expressions value, and the "stringized" version
-// of the expression (i.e., the expression put in quotes). For example, if
-// we have:
-// #define FOO 2
-// #define BAR 5
-// then the following:
-// VALUE_TO_NUMBER_AND_NAME(FOO + BAR)
-// will expand to:
-// {7, "FOO + BAR"}
-// We use the resulting array as an argument to our histogram, which reads the
-// number as a bucket identifier, and proceeds to use the corresponding name
-// in the pair (i.e., the quoted string) when printing out a histogram.
-#define VALUE_TO_NUMBER_AND_NAME(name) {name, #name},
-
-const LinearHistogram::DescriptionPair event_descriptions_[] = {
- // Provide some pretty print capability in our histogram for our internal
- // messages.
-
- // A few events we handle (kindred to messages), and used to profile actions.
- VALUE_TO_NUMBER_AND_NAME(kTaskRunEvent)
- VALUE_TO_NUMBER_AND_NAME(kTimerEvent)
-
- {-1, NULL} // The list must be null-terminated, per API to histogram.
-};
-#endif // !defined(OS_NACL)
-
-bool enable_histogrammer_ = false;
-
MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL;
#if defined(OS_IOS)
@@ -196,11 +149,6 @@ MessageLoop* MessageLoop::current() {
}
// static
-void MessageLoop::EnableHistogrammer(bool enable) {
- enable_histogrammer_ = enable;
-}
-
-// static
bool MessageLoop::InitMessagePumpForUIFactory(MessagePumpFactory* factory) {
if (message_pump_for_ui_factory_)
return false;
@@ -214,7 +162,7 @@ std::unique_ptr<MessagePump> MessageLoop::CreateMessagePumpForType(Type type) {
// TODO(rvargas): Get rid of the OS guards.
#if defined(USE_GLIB) && !defined(OS_NACL)
typedef MessagePumpGlib MessagePumpForUI;
-#elif defined(OS_LINUX) && !defined(OS_NACL)
+#elif (defined(OS_LINUX) && !defined(OS_NACL)) || defined(OS_BSD)
typedef MessagePumpLibevent MessagePumpForUI;
#endif
@@ -276,31 +224,6 @@ void MessageLoop::RemoveNestingObserver(NestingObserver* observer) {
nesting_observers_.RemoveObserver(observer);
}
-void MessageLoop::PostTask(
- const tracked_objects::Location& from_here,
- const Closure& task) {
- task_runner_->PostTask(from_here, task);
-}
-
-void MessageLoop::PostDelayedTask(
- const tracked_objects::Location& from_here,
- const Closure& task,
- TimeDelta delay) {
- task_runner_->PostDelayedTask(from_here, task, delay);
-}
-
-void MessageLoop::Run() {
- DCHECK(pump_);
- RunLoop run_loop;
- run_loop.Run();
-}
-
-void MessageLoop::RunUntilIdle() {
- DCHECK(pump_);
- RunLoop run_loop;
- run_loop.RunUntilIdle();
-}
-
void MessageLoop::QuitWhenIdle() {
DCHECK_EQ(this, current());
if (run_loop_) {
@@ -391,7 +314,6 @@ MessageLoop::MessageLoop(Type type, MessagePumpFactoryCallback pump_factory)
#endif
nestable_tasks_allowed_(true),
pump_factory_(pump_factory),
- message_histogram_(NULL),
run_loop_(NULL),
incoming_task_queue_(new internal::IncomingTaskQueue(this)),
unbound_task_runner_(
@@ -416,21 +338,13 @@ void MessageLoop::BindToCurrentThread() {
unbound_task_runner_->BindToCurrentThread();
unbound_task_runner_ = nullptr;
SetThreadTaskRunnerHandle();
- {
- // Save the current thread's ID for potential use by other threads
- // later from GetThreadName().
- thread_id_ = PlatformThread::CurrentId();
- subtle::MemoryBarrier();
- }
+ thread_id_ = PlatformThread::CurrentId();
}
std::string MessageLoop::GetThreadName() const {
- if (thread_id_ == kInvalidThreadId) {
- // |thread_id_| may already have been initialized but this thread might not
- // have received the update yet.
- subtle::MemoryBarrier();
- DCHECK_NE(kInvalidThreadId, thread_id_);
- }
+ DCHECK_NE(kInvalidThreadId, thread_id_)
+ << "GetThreadName() must only be called after BindToCurrentThread()'s "
+ << "side-effects have been synchronized with this thread.";
return ThreadIdNameManager::GetInstance()->GetName(thread_id_);
}
@@ -453,7 +367,6 @@ void MessageLoop::SetThreadTaskRunnerHandle() {
void MessageLoop::RunHandler() {
DCHECK_EQ(this, current());
- StartHistogrammer();
pump_->Run(this);
}
@@ -464,7 +377,8 @@ bool MessageLoop::ProcessNextDelayedNonNestableTask() {
if (deferred_non_nestable_work_queue_.empty())
return false;
- PendingTask pending_task = deferred_non_nestable_work_queue_.front();
+ PendingTask pending_task =
+ std::move(deferred_non_nestable_work_queue_.front());
deferred_non_nestable_work_queue_.pop();
RunTask(pending_task);
@@ -484,8 +398,6 @@ void MessageLoop::RunTask(const PendingTask& pending_task) {
// Execute the task and assume the worst: It is probably not reentrant.
nestable_tasks_allowed_ = false;
- HistogramEvent(kTaskRunEvent);
-
TRACE_TASK_EXECUTION("MessageLoop::RunTask", pending_task);
FOR_EACH_OBSERVER(TaskObserver, task_observers_,
@@ -497,7 +409,7 @@ void MessageLoop::RunTask(const PendingTask& pending_task) {
nestable_tasks_allowed_ = true;
}
-bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) {
+bool MessageLoop::DeferOrRunPendingTask(PendingTask pending_task) {
if (pending_task.nestable || run_loop_->run_depth_ == 1) {
RunTask(pending_task);
// Show that we ran a task (Note: a new one might arrive as a
@@ -507,25 +419,25 @@ bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) {
// We couldn't run the task now because we're in a nested message loop
// and the task isn't nestable.
- deferred_non_nestable_work_queue_.push(pending_task);
+ deferred_non_nestable_work_queue_.push(std::move(pending_task));
return false;
}
-void MessageLoop::AddToDelayedWorkQueue(const PendingTask& pending_task) {
+void MessageLoop::AddToDelayedWorkQueue(PendingTask pending_task) {
// Move to the delayed work queue.
- delayed_work_queue_.push(pending_task);
+ delayed_work_queue_.push(std::move(pending_task));
}
bool MessageLoop::DeletePendingTasks() {
bool did_work = !work_queue_.empty();
while (!work_queue_.empty()) {
- PendingTask pending_task = work_queue_.front();
+ PendingTask pending_task = std::move(work_queue_.front());
work_queue_.pop();
if (!pending_task.delayed_run_time.is_null()) {
// We want to delete delayed tasks in the same order in which they would
// normally be deleted in case of any funny dependencies between delayed
// tasks.
- AddToDelayedWorkQueue(pending_task);
+ AddToDelayedWorkQueue(std::move(pending_task));
}
}
did_work |= !deferred_non_nestable_work_queue_.empty();
@@ -570,31 +482,6 @@ bool MessageLoop::MessagePumpWasSignaled() {
}
#endif
-//------------------------------------------------------------------------------
-// Method and data for histogramming events and actions taken by each instance
-// on each thread.
-
-void MessageLoop::StartHistogrammer() {
-#if !defined(OS_NACL) // NaCl build has no metrics code.
- if (enable_histogrammer_ && !message_histogram_
- && StatisticsRecorder::IsActive()) {
- std::string thread_name = GetThreadName();
- DCHECK(!thread_name.empty());
- message_histogram_ = LinearHistogram::FactoryGetWithRangeDescription(
- "MsgLoop:" + thread_name, kLeastNonZeroMessageId, kMaxMessageId,
- kNumberOfDistinctMessagesDisplayed,
- HistogramBase::kHexRangePrintingFlag, event_descriptions_);
- }
-#endif
-}
-
-void MessageLoop::HistogramEvent(int event) {
-#if !defined(OS_NACL)
- if (message_histogram_)
- message_histogram_->Add(event);
-#endif
-}
-
void MessageLoop::NotifyBeginNestedLoop() {
FOR_EACH_OBSERVER(NestingObserver, nesting_observers_,
OnBeginNestedMessageLoop());
@@ -613,15 +500,17 @@ bool MessageLoop::DoWork() {
// Execute oldest task.
do {
- PendingTask pending_task = work_queue_.front();
+ PendingTask pending_task = std::move(work_queue_.front());
work_queue_.pop();
if (!pending_task.delayed_run_time.is_null()) {
- AddToDelayedWorkQueue(pending_task);
+ int sequence_num = pending_task.sequence_num;
+ TimeTicks delayed_run_time = pending_task.delayed_run_time;
+ AddToDelayedWorkQueue(std::move(pending_task));
// If we changed the topmost task, then it is time to reschedule.
- if (delayed_work_queue_.top().task.Equals(pending_task.task))
- pump_->ScheduleDelayedWork(pending_task.delayed_run_time);
+ if (delayed_work_queue_.top().sequence_num == sequence_num)
+ pump_->ScheduleDelayedWork(delayed_run_time);
} else {
- if (DeferOrRunPendingTask(pending_task))
+ if (DeferOrRunPendingTask(std::move(pending_task)))
return true;
}
} while (!work_queue_.empty());
@@ -653,13 +542,14 @@ bool MessageLoop::DoDelayedWork(TimeTicks* next_delayed_work_time) {
}
}
- PendingTask pending_task = delayed_work_queue_.top();
+ PendingTask pending_task =
+ std::move(const_cast<PendingTask&>(delayed_work_queue_.top()));
delayed_work_queue_.pop();
if (!delayed_work_queue_.empty())
*next_delayed_work_time = delayed_work_queue_.top().delayed_run_time;
- return DeferOrRunPendingTask(pending_task);
+ return DeferOrRunPendingTask(std::move(pending_task));
}
bool MessageLoop::DoIdleWork() {
@@ -684,19 +574,6 @@ bool MessageLoop::DoIdleWork() {
return false;
}
-void MessageLoop::DeleteSoonInternal(const tracked_objects::Location& from_here,
- void(*deleter)(const void*),
- const void* object) {
- task_runner()->PostNonNestableTask(from_here, Bind(deleter, object));
-}
-
-void MessageLoop::ReleaseSoonInternal(
- const tracked_objects::Location& from_here,
- void(*releaser)(const void*),
- const void* object) {
- task_runner()->PostNonNestableTask(from_here, Bind(releaser, object));
-}
-
#if !defined(OS_NACL)
//------------------------------------------------------------------------------
// MessageLoopForUI
@@ -709,6 +586,18 @@ void MessageLoopForUI::Start() {
// No Histogram support for UI message loop as it is managed by Java side
static_cast<MessagePumpForUI*>(pump_.get())->Start(this);
}
+
+void MessageLoopForUI::StartForTesting(
+ base::android::JavaMessageHandlerFactory* factory,
+ WaitableEvent* test_done_event) {
+ // No Histogram support for UI message loop as it is managed by Java side
+ static_cast<MessagePumpForUI*>(pump_.get())
+ ->StartForUnitTest(this, factory, test_done_event);
+}
+
+void MessageLoopForUI::Abort() {
+ static_cast<MessagePumpForUI*>(pump_.get())->Abort();
+}
#endif
#if defined(OS_IOS)