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

Unified Diff: base/message_loop/message_loop_proxy_impl.cc

Issue 17567007: Made MessagePump a non-thread safe class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 7 years, 6 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/message_loop/message_loop_proxy_impl.cc
diff --git a/base/message_loop/message_loop_proxy_impl.cc b/base/message_loop/message_loop_proxy_impl.cc
index 7dc8caa9f4c047f93cf7366c2e373ad1eebdd0fb..38cc10426604d2ec1ca2c7d63cdd83840bec69c7 100644
--- a/base/message_loop/message_loop_proxy_impl.cc
+++ b/base/message_loop/message_loop_proxy_impl.cc
@@ -16,14 +16,16 @@ bool MessageLoopProxyImpl::PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
- return PostTaskHelper(from_here, task, delay, true);
+ DCHECK(!task.is_null()) << from_here.ToString();
+ return AddToIncomingQueue(from_here, task, delay, true);
}
bool MessageLoopProxyImpl::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
- return PostTaskHelper(from_here, task, delay, false);
+ DCHECK(!task.is_null()) << from_here.ToString();
+ return AddToIncomingQueue(from_here, task, delay, false);
}
bool MessageLoopProxyImpl::RunsTasksOnCurrentThread() const {
@@ -66,18 +68,40 @@ MessageLoopProxyImpl::MessageLoopProxyImpl()
: target_message_loop_(MessageLoop::current()) {
}
-bool MessageLoopProxyImpl::PostTaskHelper(
- const tracked_objects::Location& from_here, const base::Closure& task,
- base::TimeDelta delay, bool nestable) {
- AutoLock lock(message_loop_lock_);
- if (target_message_loop_) {
- if (nestable) {
- target_message_loop_->PostDelayedTask(from_here, task, delay);
- } else {
- target_message_loop_->PostNonNestableDelayedTask(from_here, task, delay);
+bool MessageLoopProxyImpl::AddToIncomingQueue(
+ const tracked_objects::Location& from_here,
+ const Closure& task,
+ TimeDelta delay,
+ bool nestable) {
+ AutoLock locked(message_loop_lock_);
+ if (!target_message_loop_) {
+ // Reset |task|.
+ Closure reset_task = task;
+ return false;
+ }
+
+ target_message_loop_->AddToIncomingQueue(from_here, task, delay, nestable);
+ return true;
+}
+
+bool MessageLoopProxyImpl::TryAddToIncomingQueue(
+ const tracked_objects::Location& from_here,
+ const Closure& task) {
+ if (message_loop_lock_.Try()) {
+ AutoLock locked(message_loop_lock_, AutoLock::AlreadyAcquired());
+ if (!target_message_loop_) {
+ // Reset |task|.
+ Closure reset_task = task;
+ return false;
}
+
+ target_message_loop_->AddToIncomingQueue(from_here, task, TimeDelta(),
+ true);
return true;
}
+
+ // Reset |task|.
+ Closure reset_task = task;
return false;
}

Powered by Google App Engine
This is Rietveld 408576698