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

Unified Diff: base/debug/trace_event_impl.cc

Issue 369703003: Reduce usage of MessageLoopProxy in base/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Explicit Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: base/debug/trace_event_impl.cc
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index 3c12453e54cb60dff35a837df9bd3c1a8781a7a3..6bb833d2170420d115d7d01972550991998a37bc 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -19,6 +19,7 @@
#include "base/memory/singleton.h"
#include "base/message_loop/message_loop.h"
#include "base/process/process_metrics.h"
+#include "base/sequenced_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
@@ -30,6 +31,7 @@
#include "base/synchronization/waitable_event.h"
#include "base/sys_info.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
+#include "base/thread_task_runner_handle.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_id_name_manager.h"
#include "base/time/time.h"
@@ -1329,7 +1331,7 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter,
AutoLock lock(lock_);
// Can't enable tracing when Flush() is in progress.
- DCHECK(!flush_message_loop_proxy_.get());
+ DCHECK(!flush_task_runner_.get());
Options old_options = trace_options();
@@ -1554,7 +1556,7 @@ void TraceLog::SetEventCallbackDisabled() {
// Flush() works as the following:
// 1. Flush() is called in threadA whose message loop is saved in
-// flush_message_loop_proxy_;
+// flush_task_runner_;
// 2. If thread_message_loops_ is not empty, threadA posts task to each message
// loop to flush the thread local buffers; otherwise finish the flush;
// 3. FlushCurrentThread() deletes the thread local event buffer:
@@ -1578,9 +1580,11 @@ void TraceLog::Flush(const TraceLog::OutputCallback& cb) {
int generation = this->generation();
{
AutoLock lock(lock_);
- DCHECK(!flush_message_loop_proxy_.get());
- flush_message_loop_proxy_ = MessageLoopProxy::current();
- DCHECK(!thread_message_loops_.size() || flush_message_loop_proxy_.get());
+ DCHECK(!flush_task_runner_.get());
+ // In unit tests, there may not be a task runner set
+ if (ThreadTaskRunnerHandle::IsSet())
+ flush_task_runner_ = ThreadTaskRunnerHandle::Get();
+ DCHECK(!thread_message_loops_.size() || flush_task_runner_.get());
flush_output_callback_ = cb;
if (thread_shared_chunk_) {
@@ -1596,7 +1600,7 @@ void TraceLog::Flush(const TraceLog::OutputCallback& cb) {
FROM_HERE,
Bind(&TraceLog::FlushCurrentThread, Unretained(this), generation));
}
- flush_message_loop_proxy_->PostDelayedTask(
+ flush_task_runner_->PostDelayedTask(
FROM_HERE,
Bind(&TraceLog::OnFlushTimeout, Unretained(this), generation),
TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs));
@@ -1652,7 +1656,7 @@ void TraceLog::FinishFlush(int generation) {
UseNextTraceBuffer();
thread_message_loops_.clear();
- flush_message_loop_proxy_ = NULL;
+ flush_task_runner_ = NULL;
flush_output_callback = flush_output_callback_;
flush_output_callback_.Reset();
}
@@ -1665,7 +1669,7 @@ void TraceLog::FinishFlush(int generation) {
void TraceLog::FlushCurrentThread(int generation) {
{
AutoLock lock(lock_);
- if (!CheckGeneration(generation) || !flush_message_loop_proxy_) {
+ if (!CheckGeneration(generation) || !flush_task_runner_) {
// This is late. The corresponding flush has finished.
return;
}
@@ -1675,19 +1679,18 @@ void TraceLog::FlushCurrentThread(int generation) {
delete thread_local_event_buffer_.Get();
AutoLock lock(lock_);
- if (!CheckGeneration(generation) || !flush_message_loop_proxy_ ||
+ if (!CheckGeneration(generation) || !flush_task_runner_ ||
thread_message_loops_.size())
return;
- flush_message_loop_proxy_->PostTask(
- FROM_HERE,
- Bind(&TraceLog::FinishFlush, Unretained(this), generation));
+ flush_task_runner_->PostTask(
+ FROM_HERE, Bind(&TraceLog::FinishFlush, Unretained(this), generation));
}
void TraceLog::OnFlushTimeout(int generation) {
{
AutoLock lock(lock_);
- if (!CheckGeneration(generation) || !flush_message_loop_proxy_) {
+ if (!CheckGeneration(generation) || !flush_task_runner_) {
// Flush has finished before timeout.
return;
}

Powered by Google App Engine
This is Rietveld 408576698