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

Unified Diff: base/message_loop/message_loop.h

Issue 17567007: Made MessagePump a non-thread safe class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 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
« no previous file with comments | « no previous file | base/message_loop/message_loop.cc » ('j') | base/message_loop/message_loop_proxy_impl.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop/message_loop.h
diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h
index 846cc8d3577cad7014d7e90e8d3b65d8ad14f401..f49b9437797c1ac9e13e1bc13a51e21d563acc61 100644
--- a/base/message_loop/message_loop.h
+++ b/base/message_loop/message_loop.h
@@ -13,6 +13,7 @@
#include "base/callback_forward.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/message_loop/message_pump.h"
#include "base/observer_list.h"
@@ -282,9 +283,7 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
const std::string& thread_name() const { return thread_name_; }
// Gets the message loop proxy associated with this message loop.
- scoped_refptr<MessageLoopProxy> message_loop_proxy() {
DaleCurtis 2013/07/10 17:31:08 OOC, why? This is a simple getter. Per style guide
alexeypa (please no reviews) 2013/07/10 19:39:59 Including message_loop_proxy_impl.h to message_loo
DaleCurtis 2013/07/10 19:52:43 This is because you've defined ProxyImpl as a nest
alexeypa (please no reviews) 2013/07/10 20:05:27 No, it is because ProxyImpl (and MessageLoopProxyI
alexeypa (please no reviews) 2013/07/10 21:01:13 We discussed this issue offline and it seems that
- return message_loop_proxy_.get();
- }
+ scoped_refptr<MessageLoopProxy> message_loop_proxy();
// Enables or disables the recursive task processing. This happens in the case
// of recursive message loops. Some unwanted message loop may occurs when
@@ -359,23 +358,10 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
void AddTaskObserver(TaskObserver* task_observer);
void RemoveTaskObserver(TaskObserver* task_observer);
- // Returns true if the message loop has high resolution timers enabled.
- // Provided for testing.
- bool high_resolution_timers_enabled() {
-#if defined(OS_WIN)
- return !high_resolution_timer_expiration_.is_null();
-#else
- return true;
-#endif
- }
-
// When we go into high resolution timer mode, we will stay in hi-res mode
// for at least 1s.
static const int kHighResolutionTimerModeLeaseTimeMs = 1000;
- // Asserts that the MessageLoop is "idle".
- void AssertIdle() const;
-
#if defined(OS_WIN)
void set_os_modal_loop(bool os_modal_loop) {
os_modal_loop_ = os_modal_loop;
@@ -389,6 +375,13 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
// Can only be called from the thread that owns the MessageLoop.
bool is_running() const;
+ // Returns true if the message loop has high resolution timers enabled.
+ // Provided for testing.
+ bool IsHishResolutionTimersEnabledForTest();
DaleCurtis 2013/07/10 17:31:08 s/Hish/High/ s/Timers/Timer/ ?
alexeypa (please no reviews) 2013/07/10 19:39:59 Done.
+
+ // Returns true if the message loop is "idle". Provided for testing.
+ bool IsIdleForTest();
+
//----------------------------------------------------------------------------
protected:
@@ -402,11 +395,14 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
}
#endif
- scoped_refptr<MessagePump> pump_;
+ scoped_ptr<MessagePump> pump_;
private:
- friend class RunLoop;
+ class ProxyImpl;
+
friend class MessageLoopLockTest;
+ friend class ProxyImpl;
+ friend class RunLoop;
// A function to encapsulate all the exception handling capability in the
// stacks around the running of a main message loop. It will run the message
@@ -436,34 +432,23 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
// Adds the pending task to delayed_work_queue_.
void AddToDelayedWorkQueue(const PendingTask& pending_task);
- // This function attempts to add pending task to our incoming_queue_.
- // The append can only possibly fail when |use_try_lock| is true.
- //
- // When |use_try_lock| is true, then this call will avoid blocking if
- // the related lock is already held, and will in that case (when the
- // lock is contended) fail to perform the append, and will return false.
- //
- // If the call succeeds to append to the queue, then this call
- // will return true.
- //
- // In all cases, the caller retains ownership of |pending_task|, but this
- // function will reset the value of pending_task->task. This is needed to
- // ensure that the posting call stack does not retain pending_task->task
- // beyond this function call.
- bool AddToIncomingQueue(PendingTask* pending_task, bool use_try_lock);
-
- // Load tasks from the incoming_queue_ into work_queue_ if the latter is
- // empty. The former requires a lock to access, while the latter is directly
- // accessible on this thread.
- void ReloadWorkQueue();
-
// Delete tasks that haven't run yet without running them. Used in the
// destructor to make sure all the task's destructors get called. Returns
// true if some work was done.
bool DeletePendingTasks();
- // Calculates the time at which a PendingTask should run.
- TimeTicks CalculateDelayedRuntime(TimeDelta delay);
+ // Creates a process-wide unique ID to represent this task in trace events.
+ // This will be mangled with a Process ID hash to reduce the likelyhood of
+ // colliding with MessageLoop pointers on other processes.
+ uint64 GetTaskTraceID(const PendingTask& task);
+
+ // Loads tasks from the incoming queue to |work_queue_| if the latter is
+ // empty.
+ void ReloadWorkQueue();
+
+ // Wakes up the message pump. Can be called on any thread. The caller is
+ // responsible for synchronizing WakeUpPump() calls.
+ void WakeUpPump();
// Start recording histogram info about events and action IF it was enabled
// and IF the statistics recorder can accept a registration of our histogram.
@@ -498,40 +483,28 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
ObserverList<DestructionObserver> destruction_observers_;
+ bool exception_restoration_;
+
// A recursion block that prevents accidentally running additional tasks when
// insider a (accidentally induced?) nested message pump.
bool nestable_tasks_allowed_;
- bool exception_restoration_;
-
- std::string thread_name_;
- // A profiling histogram showing the counts of various messages and events.
- HistogramBase* message_histogram_;
-
- // An incoming queue of tasks that are acquired under a mutex for processing
- // on this instance's thread. These tasks have not yet been sorted out into
- // items for our work_queue_ vs delayed_work_queue_.
- TaskQueue incoming_queue_;
- // Protect access to incoming_queue_.
- mutable Lock incoming_queue_lock_;
-
- RunLoop* run_loop_;
-
#if defined(OS_WIN)
- TimeTicks high_resolution_timer_expiration_;
// Should be set to true before calling Windows APIs like TrackPopupMenu, etc
// which enter a modal message loop.
bool os_modal_loop_;
#endif
- // The next sequence number to use for delayed tasks. Updating this counter is
- // protected by incoming_queue_lock_.
- int next_sequence_num_;
+ std::string thread_name_;
+ // A profiling histogram showing the counts of various messages and events.
+ HistogramBase* message_histogram_;
+
+ RunLoop* run_loop_;
ObserverList<TaskObserver> task_observers_;
- // The message loop proxy associated with this message loop, if one exists.
- scoped_refptr<MessageLoopProxy> message_loop_proxy_;
+ // The message loop proxy associated with this message loop.
+ scoped_refptr<ProxyImpl> message_loop_proxy_;
scoped_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_;
template <class T, class R> friend class base::subtle::DeleteHelperInternal;
« no previous file with comments | « no previous file | base/message_loop/message_loop.cc » ('j') | base/message_loop/message_loop_proxy_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698