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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
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_loop/message_loop_proxy_impl.h" 5 #include "base/message_loop/message_loop_proxy_impl.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/threading/thread_restrictions.h" 8 #include "base/threading/thread_restrictions.h"
9 9
10 namespace base { 10 namespace base {
11 11
12 MessageLoopProxyImpl::~MessageLoopProxyImpl() { 12 MessageLoopProxyImpl::~MessageLoopProxyImpl() {
13 } 13 }
14 14
15 bool MessageLoopProxyImpl::PostDelayedTask( 15 bool MessageLoopProxyImpl::PostDelayedTask(
16 const tracked_objects::Location& from_here, 16 const tracked_objects::Location& from_here,
17 const base::Closure& task, 17 const base::Closure& task,
18 base::TimeDelta delay) { 18 base::TimeDelta delay) {
19 return PostTaskHelper(from_here, task, delay, true); 19 DCHECK(!task.is_null()) << from_here.ToString();
20 return AddToIncomingQueue(from_here, task, delay, true);
20 } 21 }
21 22
22 bool MessageLoopProxyImpl::PostNonNestableDelayedTask( 23 bool MessageLoopProxyImpl::PostNonNestableDelayedTask(
23 const tracked_objects::Location& from_here, 24 const tracked_objects::Location& from_here,
24 const base::Closure& task, 25 const base::Closure& task,
25 base::TimeDelta delay) { 26 base::TimeDelta delay) {
26 return PostTaskHelper(from_here, task, delay, false); 27 DCHECK(!task.is_null()) << from_here.ToString();
28 return AddToIncomingQueue(from_here, task, delay, false);
27 } 29 }
28 30
29 bool MessageLoopProxyImpl::RunsTasksOnCurrentThread() const { 31 bool MessageLoopProxyImpl::RunsTasksOnCurrentThread() const {
30 // We shouldn't use MessageLoop::current() since it uses LazyInstance which 32 // We shouldn't use MessageLoop::current() since it uses LazyInstance which
31 // may be deleted by ~AtExitManager when a WorkerPool thread calls this 33 // may be deleted by ~AtExitManager when a WorkerPool thread calls this
32 // function. 34 // function.
33 // http://crbug.com/63678 35 // http://crbug.com/63678
34 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; 36 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton;
35 AutoLock lock(message_loop_lock_); 37 AutoLock lock(message_loop_lock_);
36 return (target_message_loop_ && 38 return (target_message_loop_ &&
(...skipping 22 matching lines...) Expand all
59 } 61 }
60 } 62 }
61 if (!delete_later) 63 if (!delete_later)
62 delete this; 64 delete this;
63 } 65 }
64 66
65 MessageLoopProxyImpl::MessageLoopProxyImpl() 67 MessageLoopProxyImpl::MessageLoopProxyImpl()
66 : target_message_loop_(MessageLoop::current()) { 68 : target_message_loop_(MessageLoop::current()) {
67 } 69 }
68 70
69 bool MessageLoopProxyImpl::PostTaskHelper( 71 bool MessageLoopProxyImpl::AddToIncomingQueue(
70 const tracked_objects::Location& from_here, const base::Closure& task, 72 const tracked_objects::Location& from_here,
71 base::TimeDelta delay, bool nestable) { 73 const Closure& task,
72 AutoLock lock(message_loop_lock_); 74 TimeDelta delay,
73 if (target_message_loop_) { 75 bool nestable) {
74 if (nestable) { 76 AutoLock locked(message_loop_lock_);
75 target_message_loop_->PostDelayedTask(from_here, task, delay); 77 if (!target_message_loop_) {
76 } else { 78 // Reset |task|.
77 target_message_loop_->PostNonNestableDelayedTask(from_here, task, delay); 79 Closure reset_task = task;
80 return false;
81 }
82
83 target_message_loop_->AddToIncomingQueue(from_here, task, delay, nestable);
84 return true;
85 }
86
87 bool MessageLoopProxyImpl::TryAddToIncomingQueue(
88 const tracked_objects::Location& from_here,
89 const Closure& task) {
90 if (message_loop_lock_.Try()) {
91 AutoLock locked(message_loop_lock_, AutoLock::AlreadyAcquired());
92 if (!target_message_loop_) {
93 // Reset |task|.
94 Closure reset_task = task;
95 return false;
78 } 96 }
97
98 target_message_loop_->AddToIncomingQueue(from_here, task, TimeDelta(),
99 true);
79 return true; 100 return true;
80 } 101 }
102
103 // Reset |task|.
104 Closure reset_task = task;
81 return false; 105 return false;
82 } 106 }
83 107
84 scoped_refptr<MessageLoopProxy> 108 scoped_refptr<MessageLoopProxy>
85 MessageLoopProxy::current() { 109 MessageLoopProxy::current() {
86 MessageLoop* cur_loop = MessageLoop::current(); 110 MessageLoop* cur_loop = MessageLoop::current();
87 if (!cur_loop) 111 if (!cur_loop)
88 return NULL; 112 return NULL;
89 return cur_loop->message_loop_proxy(); 113 return cur_loop->message_loop_proxy();
90 } 114 }
91 115
92 } // namespace base 116 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698