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

Side by Side Diff: trunk/src/base/message_loop/message_loop.h

Issue 16897005: Revert 206507 "Move message_pump to base/message_loop." (Closed) Base URL: svn://svn.chromium.org/chrome/
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
« no previous file with comments | « trunk/src/base/mac/scoped_sending_event.h ('k') | trunk/src/base/message_loop/message_loop.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/message_loop/message_loop_proxy.h" 16 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/message_loop/message_pump.h" 17 #include "base/message_pump.h"
18 #include "base/observer_list.h" 18 #include "base/observer_list.h"
19 #include "base/pending_task.h" 19 #include "base/pending_task.h"
20 #include "base/sequenced_task_runner_helpers.h" 20 #include "base/sequenced_task_runner_helpers.h"
21 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
22 #include "base/tracking_info.h" 22 #include "base/tracking_info.h"
23 #include "base/time.h" 23 #include "base/time.h"
24 24
25 #if defined(OS_WIN) 25 #if defined(OS_WIN)
26 // We need this to declare base::MessagePumpWin::Dispatcher, which we should 26 // We need this to declare base::MessagePumpWin::Dispatcher, which we should
27 // really just eliminate. 27 // really just eliminate.
28 #include "base/message_loop/message_pump_win.h" 28 #include "base/message_pump_win.h"
29 #elif defined(OS_IOS) 29 #elif defined(OS_IOS)
30 #include "base/message_loop/message_pump_io_ios.h" 30 #include "base/message_pump_io_ios.h"
31 #elif defined(OS_POSIX) 31 #elif defined(OS_POSIX)
32 #include "base/message_loop/message_pump_libevent.h" 32 #include "base/message_pump_libevent.h"
33 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 33 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
34 34
35 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_NACL) 35 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_NACL)
36 #include "base/message_loop/message_pump_aurax11.h" 36 #include "base/message_pump_aurax11.h"
37 #elif defined(USE_OZONE) && !defined(OS_NACL) 37 #elif defined(USE_OZONE) && !defined(OS_NACL)
38 #include "base/message_loop/message_pump_ozone.h" 38 #include "base/message_pump_ozone.h"
39 #else 39 #else
40 #include "base/message_loop/message_pump_gtk.h" 40 #include "base/message_pump_gtk.h"
41 #endif 41 #endif
42 42
43 #endif 43 #endif
44 #endif 44 #endif
45 45
46 namespace base { 46 namespace base {
47
48 class HistogramBase; 47 class HistogramBase;
49 class MessageLoopLockTest; 48 class MessageLoopLockTest;
50 class RunLoop; 49 class RunLoop;
51 class ThreadTaskRunnerHandle; 50 class ThreadTaskRunnerHandle;
52 #if defined(OS_ANDROID) 51 #if defined(OS_ANDROID)
53 class MessagePumpForUI; 52 class MessagePumpForUI;
54 #endif 53 #endif
55 54
56 // A MessageLoop is used to process events for a particular thread. There is 55 // A MessageLoop is used to process events for a particular thread. There is
57 // at most one MessageLoop instance per thread. 56 // at most one MessageLoop instance per thread.
(...skipping 19 matching lines...) Expand all
77 // HRESULT hr; 76 // HRESULT hr;
78 // { 77 // {
79 // MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); 78 // MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
80 // hr = DoDragDrop(...); // Implicitly runs a modal message loop. 79 // hr = DoDragDrop(...); // Implicitly runs a modal message loop.
81 // } 80 // }
82 // // Process |hr| (the result returned by DoDragDrop()). 81 // // Process |hr| (the result returned by DoDragDrop()).
83 // 82 //
84 // Please be SURE your task is reentrant (nestable) and all global variables 83 // Please be SURE your task is reentrant (nestable) and all global variables
85 // are stable and accessible before calling SetNestableTasksAllowed(true). 84 // are stable and accessible before calling SetNestableTasksAllowed(true).
86 // 85 //
87 class BASE_EXPORT MessageLoop : public MessagePump::Delegate { 86 class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
88 public: 87 public:
89 88
90 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 89 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
91 typedef MessagePumpDispatcher Dispatcher; 90 typedef base::MessagePumpDispatcher Dispatcher;
92 typedef MessagePumpObserver Observer; 91 typedef base::MessagePumpObserver Observer;
93 #endif 92 #endif
94 93
95 // A MessageLoop has a particular type, which indicates the set of 94 // A MessageLoop has a particular type, which indicates the set of
96 // asynchronous events it may process in addition to tasks and timers. 95 // asynchronous events it may process in addition to tasks and timers.
97 // 96 //
98 // TYPE_DEFAULT 97 // TYPE_DEFAULT
99 // This type of ML only supports tasks and timers. 98 // This type of ML only supports tasks and timers.
100 // 99 //
101 // TYPE_UI 100 // TYPE_UI
102 // This type of ML also supports native UI events (e.g., Windows messages). 101 // This type of ML also supports native UI events (e.g., Windows messages).
(...skipping 12 matching lines...) Expand all
115 // Normally, it is not necessary to instantiate a MessageLoop. Instead, it 114 // Normally, it is not necessary to instantiate a MessageLoop. Instead, it
116 // is typical to make use of the current thread's MessageLoop instance. 115 // is typical to make use of the current thread's MessageLoop instance.
117 explicit MessageLoop(Type type = TYPE_DEFAULT); 116 explicit MessageLoop(Type type = TYPE_DEFAULT);
118 virtual ~MessageLoop(); 117 virtual ~MessageLoop();
119 118
120 // Returns the MessageLoop object for the current thread, or null if none. 119 // Returns the MessageLoop object for the current thread, or null if none.
121 static MessageLoop* current(); 120 static MessageLoop* current();
122 121
123 static void EnableHistogrammer(bool enable_histogrammer); 122 static void EnableHistogrammer(bool enable_histogrammer);
124 123
125 typedef MessagePump* (MessagePumpFactory)(); 124 typedef base::MessagePump* (MessagePumpFactory)();
126 // Uses the given base::MessagePumpForUIFactory to override the default 125 // Uses the given base::MessagePumpForUIFactory to override the default
127 // MessagePump implementation for 'TYPE_UI'. Returns true if the factory 126 // MessagePump implementation for 'TYPE_UI'. Returns true if the factory
128 // was successfully registered. 127 // was successfully registered.
129 static bool InitMessagePumpForUIFactory(MessagePumpFactory* factory); 128 static bool InitMessagePumpForUIFactory(MessagePumpFactory* factory);
130 129
131 // A DestructionObserver is notified when the current MessageLoop is being 130 // A DestructionObserver is notified when the current MessageLoop is being
132 // destroyed. These observers are notified prior to MessageLoop::current() 131 // destroyed. These observers are notified prior to MessageLoop::current()
133 // being changed to return NULL. This gives interested parties the chance to 132 // being changed to return NULL. This gives interested parties the chance to
134 // do final cleanup that depends on the MessageLoop. 133 // do final cleanup that depends on the MessageLoop.
135 // 134 //
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // 167 //
169 // PostTask(from_here, task) is equivalent to 168 // PostTask(from_here, task) is equivalent to
170 // PostDelayedTask(from_here, task, 0). 169 // PostDelayedTask(from_here, task, 0).
171 // 170 //
172 // The TryPostTask is meant for the cases where the calling thread cannot 171 // The TryPostTask is meant for the cases where the calling thread cannot
173 // block. If posting the task will block, the call returns false, the task 172 // block. If posting the task will block, the call returns false, the task
174 // is not posted but the task is consumed anyways. 173 // is not posted but the task is consumed anyways.
175 // 174 //
176 // NOTE: These methods may be called on any thread. The Task will be invoked 175 // NOTE: These methods may be called on any thread. The Task will be invoked
177 // on the thread that executes MessageLoop::Run(). 176 // on the thread that executes MessageLoop::Run().
178 void PostTask(const tracked_objects::Location& from_here, 177 void PostTask(
179 const Closure& task); 178 const tracked_objects::Location& from_here,
179 const base::Closure& task);
180 180
181 bool TryPostTask(const tracked_objects::Location& from_here, 181 bool TryPostTask(
182 const Closure& task); 182 const tracked_objects::Location& from_here,
183 const base::Closure& task);
183 184
184 void PostDelayedTask(const tracked_objects::Location& from_here, 185 void PostDelayedTask(
185 const Closure& task, 186 const tracked_objects::Location& from_here,
186 TimeDelta delay); 187 const base::Closure& task,
188 base::TimeDelta delay);
187 189
188 void PostNonNestableTask(const tracked_objects::Location& from_here, 190 void PostNonNestableTask(
189 const Closure& task); 191 const tracked_objects::Location& from_here,
192 const base::Closure& task);
190 193
191 void PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 194 void PostNonNestableDelayedTask(
192 const Closure& task, 195 const tracked_objects::Location& from_here,
193 TimeDelta delay); 196 const base::Closure& task,
197 base::TimeDelta delay);
194 198
195 // A variant on PostTask that deletes the given object. This is useful 199 // A variant on PostTask that deletes the given object. This is useful
196 // if the object needs to live until the next run of the MessageLoop (for 200 // if the object needs to live until the next run of the MessageLoop (for
197 // example, deleting a RenderProcessHost from within an IPC callback is not 201 // example, deleting a RenderProcessHost from within an IPC callback is not
198 // good). 202 // good).
199 // 203 //
200 // NOTE: This method may be called on any thread. The object will be deleted 204 // NOTE: This method may be called on any thread. The object will be deleted
201 // on the thread that executes MessageLoop::Run(). If this is not the same 205 // on the thread that executes MessageLoop::Run(). If this is not the same
202 // as the thread that calls PostDelayedTask(FROM_HERE, ), then T MUST inherit 206 // as the thread that calls PostDelayedTask(FROM_HERE, ), then T MUST inherit
203 // from RefCountedThreadSafe<T>! 207 // from RefCountedThreadSafe<T>!
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // which nested run loop you are quitting, so be careful! 257 // which nested run loop you are quitting, so be careful!
254 void QuitWhenIdle(); 258 void QuitWhenIdle();
255 259
256 // Deprecated: use RunLoop instead. 260 // Deprecated: use RunLoop instead.
257 // 261 //
258 // This method is a variant of Quit, that does not wait for pending messages 262 // This method is a variant of Quit, that does not wait for pending messages
259 // to be processed before returning from Run. 263 // to be processed before returning from Run.
260 void QuitNow(); 264 void QuitNow();
261 265
262 // TODO(jbates) remove this. crbug.com/131220. See QuitWhenIdleClosure(). 266 // TODO(jbates) remove this. crbug.com/131220. See QuitWhenIdleClosure().
263 static Closure QuitClosure() { return QuitWhenIdleClosure(); } 267 static base::Closure QuitClosure() { return QuitWhenIdleClosure(); }
264 268
265 // Deprecated: use RunLoop instead. 269 // Deprecated: use RunLoop instead.
266 // Construct a Closure that will call QuitWhenIdle(). Useful to schedule an 270 // Construct a Closure that will call QuitWhenIdle(). Useful to schedule an
267 // arbitrary MessageLoop to QuitWhenIdle. 271 // arbitrary MessageLoop to QuitWhenIdle.
268 static Closure QuitWhenIdleClosure(); 272 static base::Closure QuitWhenIdleClosure();
269 273
270 // Returns true if this loop is |type|. This allows subclasses (especially 274 // Returns true if this loop is |type|. This allows subclasses (especially
271 // those in tests) to specialize how they are identified. 275 // those in tests) to specialize how they are identified.
272 virtual bool IsType(Type type) const; 276 virtual bool IsType(Type type) const;
273 277
274 // Returns the type passed to the constructor. 278 // Returns the type passed to the constructor.
275 Type type() const { return type_; } 279 Type type() const { return type_; }
276 280
277 // Optional call to connect the thread name with this loop. 281 // Optional call to connect the thread name with this loop.
278 void set_thread_name(const std::string& thread_name) { 282 void set_thread_name(const std::string& thread_name) {
279 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; 283 DCHECK(thread_name_.empty()) << "Should not rename this thread!";
280 thread_name_ = thread_name; 284 thread_name_ = thread_name;
281 } 285 }
282 const std::string& thread_name() const { return thread_name_; } 286 const std::string& thread_name() const { return thread_name_; }
283 287
284 // Gets the message loop proxy associated with this message loop. 288 // Gets the message loop proxy associated with this message loop.
285 scoped_refptr<MessageLoopProxy> message_loop_proxy() { 289 scoped_refptr<base::MessageLoopProxy> message_loop_proxy() {
286 return message_loop_proxy_.get(); 290 return message_loop_proxy_.get();
287 } 291 }
288 292
289 // Enables or disables the recursive task processing. This happens in the case 293 // Enables or disables the recursive task processing. This happens in the case
290 // of recursive message loops. Some unwanted message loop may occurs when 294 // of recursive message loops. Some unwanted message loop may occurs when
291 // using common controls or printer functions. By default, recursive task 295 // using common controls or printer functions. By default, recursive task
292 // processing is disabled. 296 // processing is disabled.
293 // 297 //
294 // Please utilize |ScopedNestableTaskAllower| instead of calling these methods 298 // Please utilize |ScopedNestableTaskAllower| instead of calling these methods
295 // directly. In general nestable message loops are to be avoided. They are 299 // directly. In general nestable message loops are to be avoided. They are
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 342
339 // A TaskObserver is an object that receives task notifications from the 343 // A TaskObserver is an object that receives task notifications from the
340 // MessageLoop. 344 // MessageLoop.
341 // 345 //
342 // NOTE: A TaskObserver implementation should be extremely fast! 346 // NOTE: A TaskObserver implementation should be extremely fast!
343 class BASE_EXPORT TaskObserver { 347 class BASE_EXPORT TaskObserver {
344 public: 348 public:
345 TaskObserver(); 349 TaskObserver();
346 350
347 // This method is called before processing a task. 351 // This method is called before processing a task.
348 virtual void WillProcessTask(const PendingTask& pending_task) = 0; 352 virtual void WillProcessTask(const base::PendingTask& pending_task) = 0;
349 353
350 // This method is called after processing a task. 354 // This method is called after processing a task.
351 virtual void DidProcessTask(const PendingTask& pending_task) = 0; 355 virtual void DidProcessTask(const base::PendingTask& pending_task) = 0;
352 356
353 protected: 357 protected:
354 virtual ~TaskObserver(); 358 virtual ~TaskObserver();
355 }; 359 };
356 360
357 // These functions can only be called on the same thread that |this| is 361 // These functions can only be called on the same thread that |this| is
358 // running on. 362 // running on.
359 void AddTaskObserver(TaskObserver* task_observer); 363 void AddTaskObserver(TaskObserver* task_observer);
360 void RemoveTaskObserver(TaskObserver* task_observer); 364 void RemoveTaskObserver(TaskObserver* task_observer);
361 365
(...skipping 24 matching lines...) Expand all
386 } 390 }
387 #endif // OS_WIN 391 #endif // OS_WIN
388 392
389 // Can only be called from the thread that owns the MessageLoop. 393 // Can only be called from the thread that owns the MessageLoop.
390 bool is_running() const; 394 bool is_running() const;
391 395
392 //---------------------------------------------------------------------------- 396 //----------------------------------------------------------------------------
393 protected: 397 protected:
394 398
395 #if defined(OS_WIN) 399 #if defined(OS_WIN)
396 MessagePumpWin* pump_win() { 400 base::MessagePumpWin* pump_win() {
397 return static_cast<MessagePumpWin*>(pump_.get()); 401 return static_cast<base::MessagePumpWin*>(pump_.get());
398 } 402 }
399 #elif defined(OS_POSIX) && !defined(OS_IOS) 403 #elif defined(OS_POSIX) && !defined(OS_IOS)
400 MessagePumpLibevent* pump_libevent() { 404 base::MessagePumpLibevent* pump_libevent() {
401 return static_cast<MessagePumpLibevent*>(pump_.get()); 405 return static_cast<base::MessagePumpLibevent*>(pump_.get());
402 } 406 }
403 #endif 407 #endif
404 408
405 scoped_refptr<MessagePump> pump_; 409 scoped_refptr<base::MessagePump> pump_;
406 410
407 private: 411 private:
408 friend class RunLoop; 412 friend class base::RunLoop;
409 friend class MessageLoopLockTest; 413 friend class base::MessageLoopLockTest;
410 414
411 // A function to encapsulate all the exception handling capability in the 415 // A function to encapsulate all the exception handling capability in the
412 // stacks around the running of a main message loop. It will run the message 416 // stacks around the running of a main message loop. It will run the message
413 // loop in a SEH try block or not depending on the set_SEH_restoration() 417 // loop in a SEH try block or not depending on the set_SEH_restoration()
414 // flag invoking respectively RunInternalInSEHFrame() or RunInternal(). 418 // flag invoking respectively RunInternalInSEHFrame() or RunInternal().
415 void RunHandler(); 419 void RunHandler();
416 420
417 #if defined(OS_WIN) 421 #if defined(OS_WIN)
418 __declspec(noinline) void RunInternalInSEHFrame(); 422 __declspec(noinline) void RunInternalInSEHFrame();
419 #endif 423 #endif
420 424
421 // A surrounding stack frame around the running of the message loop that 425 // A surrounding stack frame around the running of the message loop that
422 // supports all saving and restoring of state, as is needed for any/all (ugly) 426 // supports all saving and restoring of state, as is needed for any/all (ugly)
423 // recursive calls. 427 // recursive calls.
424 void RunInternal(); 428 void RunInternal();
425 429
426 // Called to process any delayed non-nestable tasks. 430 // Called to process any delayed non-nestable tasks.
427 bool ProcessNextDelayedNonNestableTask(); 431 bool ProcessNextDelayedNonNestableTask();
428 432
429 // Runs the specified PendingTask. 433 // Runs the specified PendingTask.
430 void RunTask(const PendingTask& pending_task); 434 void RunTask(const base::PendingTask& pending_task);
431 435
432 // Calls RunTask or queues the pending_task on the deferred task list if it 436 // Calls RunTask or queues the pending_task on the deferred task list if it
433 // cannot be run right now. Returns true if the task was run. 437 // cannot be run right now. Returns true if the task was run.
434 bool DeferOrRunPendingTask(const PendingTask& pending_task); 438 bool DeferOrRunPendingTask(const base::PendingTask& pending_task);
435 439
436 // Adds the pending task to delayed_work_queue_. 440 // Adds the pending task to delayed_work_queue_.
437 void AddToDelayedWorkQueue(const PendingTask& pending_task); 441 void AddToDelayedWorkQueue(const base::PendingTask& pending_task);
438 442
439 // This function attempts to add pending task to our incoming_queue_. 443 // This function attempts to add pending task to our incoming_queue_.
440 // The append can only possibly fail when |use_try_lock| is true. 444 // The append can only possibly fail when |use_try_lock| is true.
441 // 445 //
442 // When |use_try_lock| is true, then this call will avoid blocking if 446 // When |use_try_lock| is true, then this call will avoid blocking if
443 // the related lock is already held, and will in that case (when the 447 // the related lock is already held, and will in that case (when the
444 // lock is contended) fail to perform the append, and will return false. 448 // lock is contended) fail to perform the append, and will return false.
445 // 449 //
446 // If the call succeeds to append to the queue, then this call 450 // If the call succeeds to append to the queue, then this call
447 // will return true. 451 // will return true.
448 // 452 //
449 // In all cases, the caller retains ownership of |pending_task|, but this 453 // In all cases, the caller retains ownership of |pending_task|, but this
450 // function will reset the value of pending_task->task. This is needed to 454 // function will reset the value of pending_task->task. This is needed to
451 // ensure that the posting call stack does not retain pending_task->task 455 // ensure that the posting call stack does not retain pending_task->task
452 // beyond this function call. 456 // beyond this function call.
453 bool AddToIncomingQueue(PendingTask* pending_task, bool use_try_lock); 457 bool AddToIncomingQueue(base::PendingTask* pending_task, bool use_try_lock);
454 458
455 // Load tasks from the incoming_queue_ into work_queue_ if the latter is 459 // Load tasks from the incoming_queue_ into work_queue_ if the latter is
456 // empty. The former requires a lock to access, while the latter is directly 460 // empty. The former requires a lock to access, while the latter is directly
457 // accessible on this thread. 461 // accessible on this thread.
458 void ReloadWorkQueue(); 462 void ReloadWorkQueue();
459 463
460 // Delete tasks that haven't run yet without running them. Used in the 464 // Delete tasks that haven't run yet without running them. Used in the
461 // destructor to make sure all the task's destructors get called. Returns 465 // destructor to make sure all the task's destructors get called. Returns
462 // true if some work was done. 466 // true if some work was done.
463 bool DeletePendingTasks(); 467 bool DeletePendingTasks();
464 468
465 // Calculates the time at which a PendingTask should run. 469 // Calculates the time at which a PendingTask should run.
466 TimeTicks CalculateDelayedRuntime(TimeDelta delay); 470 base::TimeTicks CalculateDelayedRuntime(base::TimeDelta delay);
467 471
468 // Start recording histogram info about events and action IF it was enabled 472 // Start recording histogram info about events and action IF it was enabled
469 // and IF the statistics recorder can accept a registration of our histogram. 473 // and IF the statistics recorder can accept a registration of our histogram.
470 void StartHistogrammer(); 474 void StartHistogrammer();
471 475
472 // Add occurrence of event to our histogram, so that we can see what is being 476 // Add occurrence of event to our histogram, so that we can see what is being
473 // done in a specific MessageLoop instance (i.e., specific thread). 477 // done in a specific MessageLoop instance (i.e., specific thread).
474 // If message_histogram_ is NULL, this is a no-op. 478 // If message_histogram_ is NULL, this is a no-op.
475 void HistogramEvent(int event); 479 void HistogramEvent(int event);
476 480
477 // MessagePump::Delegate methods: 481 // base::MessagePump::Delegate methods:
478 virtual bool DoWork() OVERRIDE; 482 virtual bool DoWork() OVERRIDE;
479 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE; 483 virtual bool DoDelayedWork(base::TimeTicks* next_delayed_work_time) OVERRIDE;
480 virtual bool DoIdleWork() OVERRIDE; 484 virtual bool DoIdleWork() OVERRIDE;
481 485
482 Type type_; 486 Type type_;
483 487
484 // A list of tasks that need to be processed by this instance. Note that 488 // A list of tasks that need to be processed by this instance. Note that
485 // this queue is only accessed (push/pop) by our current thread. 489 // this queue is only accessed (push/pop) by our current thread.
486 TaskQueue work_queue_; 490 base::TaskQueue work_queue_;
487 491
488 // Contains delayed tasks, sorted by their 'delayed_run_time' property. 492 // Contains delayed tasks, sorted by their 'delayed_run_time' property.
489 DelayedTaskQueue delayed_work_queue_; 493 base::DelayedTaskQueue delayed_work_queue_;
490 494
491 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. 495 // A recent snapshot of Time::Now(), used to check delayed_work_queue_.
492 TimeTicks recent_time_; 496 base::TimeTicks recent_time_;
493 497
494 // A queue of non-nestable tasks that we had to defer because when it came 498 // A queue of non-nestable tasks that we had to defer because when it came
495 // time to execute them we were in a nested message loop. They will execute 499 // time to execute them we were in a nested message loop. They will execute
496 // once we're out of nested message loops. 500 // once we're out of nested message loops.
497 TaskQueue deferred_non_nestable_work_queue_; 501 base::TaskQueue deferred_non_nestable_work_queue_;
498 502
499 ObserverList<DestructionObserver> destruction_observers_; 503 ObserverList<DestructionObserver> destruction_observers_;
500 504
501 // A recursion block that prevents accidentally running additional tasks when 505 // A recursion block that prevents accidentally running additional tasks when
502 // insider a (accidentally induced?) nested message pump. 506 // insider a (accidentally induced?) nested message pump.
503 bool nestable_tasks_allowed_; 507 bool nestable_tasks_allowed_;
504 508
505 bool exception_restoration_; 509 bool exception_restoration_;
506 510
507 std::string thread_name_; 511 std::string thread_name_;
508 // A profiling histogram showing the counts of various messages and events. 512 // A profiling histogram showing the counts of various messages and events.
509 HistogramBase* message_histogram_; 513 base::HistogramBase* message_histogram_;
510 514
511 // An incoming queue of tasks that are acquired under a mutex for processing 515 // An incoming queue of tasks that are acquired under a mutex for processing
512 // on this instance's thread. These tasks have not yet been sorted out into 516 // on this instance's thread. These tasks have not yet been sorted out into
513 // items for our work_queue_ vs delayed_work_queue_. 517 // items for our work_queue_ vs delayed_work_queue_.
514 TaskQueue incoming_queue_; 518 base::TaskQueue incoming_queue_;
515 // Protect access to incoming_queue_. 519 // Protect access to incoming_queue_.
516 mutable Lock incoming_queue_lock_; 520 mutable base::Lock incoming_queue_lock_;
517 521
518 RunLoop* run_loop_; 522 base::RunLoop* run_loop_;
519 523
520 #if defined(OS_WIN) 524 #if defined(OS_WIN)
521 TimeTicks high_resolution_timer_expiration_; 525 base::TimeTicks high_resolution_timer_expiration_;
522 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc 526 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc
523 // which enter a modal message loop. 527 // which enter a modal message loop.
524 bool os_modal_loop_; 528 bool os_modal_loop_;
525 #endif 529 #endif
526 530
527 // The next sequence number to use for delayed tasks. Updating this counter is 531 // The next sequence number to use for delayed tasks. Updating this counter is
528 // protected by incoming_queue_lock_. 532 // protected by incoming_queue_lock_.
529 int next_sequence_num_; 533 int next_sequence_num_;
530 534
531 ObserverList<TaskObserver> task_observers_; 535 ObserverList<TaskObserver> task_observers_;
532 536
533 // The message loop proxy associated with this message loop, if one exists. 537 // The message loop proxy associated with this message loop, if one exists.
534 scoped_refptr<MessageLoopProxy> message_loop_proxy_; 538 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
535 scoped_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; 539 scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
536 540
537 template <class T, class R> friend class base::subtle::DeleteHelperInternal; 541 template <class T, class R> friend class base::subtle::DeleteHelperInternal;
538 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; 542 template <class T, class R> friend class base::subtle::ReleaseHelperInternal;
539 543
540 void DeleteSoonInternal(const tracked_objects::Location& from_here, 544 void DeleteSoonInternal(const tracked_objects::Location& from_here,
541 void(*deleter)(const void*), 545 void(*deleter)(const void*),
542 const void* object); 546 const void* object);
543 void ReleaseSoonInternal(const tracked_objects::Location& from_here, 547 void ReleaseSoonInternal(const tracked_objects::Location& from_here,
544 void(*releaser)(const void*), 548 void(*releaser)(const void*),
545 const void* object); 549 const void* object);
546 550
547 DISALLOW_COPY_AND_ASSIGN(MessageLoop); 551 DISALLOW_COPY_AND_ASSIGN(MessageLoop);
548 }; 552 };
549 553
550 //----------------------------------------------------------------------------- 554 //-----------------------------------------------------------------------------
551 // MessageLoopForUI extends MessageLoop with methods that are particular to a 555 // MessageLoopForUI extends MessageLoop with methods that are particular to a
552 // MessageLoop instantiated with TYPE_UI. 556 // MessageLoop instantiated with TYPE_UI.
553 // 557 //
554 // This class is typically used like so: 558 // This class is typically used like so:
555 // MessageLoopForUI::current()->...call some method... 559 // MessageLoopForUI::current()->...call some method...
556 // 560 //
557 class BASE_EXPORT MessageLoopForUI : public MessageLoop { 561 class BASE_EXPORT MessageLoopForUI : public MessageLoop {
558 public: 562 public:
559 #if defined(OS_WIN) 563 #if defined(OS_WIN)
560 typedef MessagePumpForUI::MessageFilter MessageFilter; 564 typedef base::MessagePumpForUI::MessageFilter MessageFilter;
561 #endif 565 #endif
562 566
563 MessageLoopForUI() : MessageLoop(TYPE_UI) { 567 MessageLoopForUI() : MessageLoop(TYPE_UI) {
564 } 568 }
565 569
566 // Returns the MessageLoopForUI of the current thread. 570 // Returns the MessageLoopForUI of the current thread.
567 static MessageLoopForUI* current() { 571 static MessageLoopForUI* current() {
568 MessageLoop* loop = MessageLoop::current(); 572 MessageLoop* loop = MessageLoop::current();
569 DCHECK(loop); 573 DCHECK(loop);
570 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); 574 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type());
(...skipping 25 matching lines...) Expand all
596 600
597 #if defined(OS_WIN) 601 #if defined(OS_WIN)
598 // Plese see MessagePumpForUI for definitions of this method. 602 // Plese see MessagePumpForUI for definitions of this method.
599 void SetMessageFilter(scoped_ptr<MessageFilter> message_filter) { 603 void SetMessageFilter(scoped_ptr<MessageFilter> message_filter) {
600 pump_ui()->SetMessageFilter(message_filter.Pass()); 604 pump_ui()->SetMessageFilter(message_filter.Pass());
601 } 605 }
602 #endif 606 #endif
603 607
604 protected: 608 protected:
605 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_NACL) 609 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_NACL)
606 friend class MessagePumpAuraX11; 610 friend class base::MessagePumpAuraX11;
607 #endif 611 #endif
608 #if defined(USE_OZONE) && !defined(OS_NACL) 612 #if defined(USE_OZONE) && !defined(OS_NACL)
609 friend class MessagePumpOzone; 613 friend class base::MessagePumpOzone;
610 #endif 614 #endif
611 615
612 // TODO(rvargas): Make this platform independent. 616 // TODO(rvargas): Make this platform independent.
613 MessagePumpForUI* pump_ui() { 617 base::MessagePumpForUI* pump_ui() {
614 return static_cast<MessagePumpForUI*>(pump_.get()); 618 return static_cast<base::MessagePumpForUI*>(pump_.get());
615 } 619 }
616 #endif // !defined(OS_MACOSX) 620 #endif // !defined(OS_MACOSX)
617 }; 621 };
618 622
619 // Do not add any member variables to MessageLoopForUI! This is important b/c 623 // Do not add any member variables to MessageLoopForUI! This is important b/c
620 // MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra 624 // MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra
621 // data that you need should be stored on the MessageLoop's pump_ instance. 625 // data that you need should be stored on the MessageLoop's pump_ instance.
622 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForUI), 626 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForUI),
623 MessageLoopForUI_should_not_have_extra_member_variables); 627 MessageLoopForUI_should_not_have_extra_member_variables);
624 628
625 //----------------------------------------------------------------------------- 629 //-----------------------------------------------------------------------------
626 // MessageLoopForIO extends MessageLoop with methods that are particular to a 630 // MessageLoopForIO extends MessageLoop with methods that are particular to a
627 // MessageLoop instantiated with TYPE_IO. 631 // MessageLoop instantiated with TYPE_IO.
628 // 632 //
629 // This class is typically used like so: 633 // This class is typically used like so:
630 // MessageLoopForIO::current()->...call some method... 634 // MessageLoopForIO::current()->...call some method...
631 // 635 //
632 class BASE_EXPORT MessageLoopForIO : public MessageLoop { 636 class BASE_EXPORT MessageLoopForIO : public MessageLoop {
633 public: 637 public:
634 #if defined(OS_WIN) 638 #if defined(OS_WIN)
635 typedef MessagePumpForIO::IOHandler IOHandler; 639 typedef base::MessagePumpForIO::IOHandler IOHandler;
636 typedef MessagePumpForIO::IOContext IOContext; 640 typedef base::MessagePumpForIO::IOContext IOContext;
637 typedef MessagePumpForIO::IOObserver IOObserver; 641 typedef base::MessagePumpForIO::IOObserver IOObserver;
638 #elif defined(OS_IOS) 642 #elif defined(OS_IOS)
639 typedef MessagePumpIOSForIO::Watcher Watcher; 643 typedef base::MessagePumpIOSForIO::Watcher Watcher;
640 typedef MessagePumpIOSForIO::FileDescriptorWatcher 644 typedef base::MessagePumpIOSForIO::FileDescriptorWatcher
641 FileDescriptorWatcher; 645 FileDescriptorWatcher;
642 typedef MessagePumpIOSForIO::IOObserver IOObserver; 646 typedef base::MessagePumpIOSForIO::IOObserver IOObserver;
643 647
644 enum Mode { 648 enum Mode {
645 WATCH_READ = MessagePumpIOSForIO::WATCH_READ, 649 WATCH_READ = base::MessagePumpIOSForIO::WATCH_READ,
646 WATCH_WRITE = MessagePumpIOSForIO::WATCH_WRITE, 650 WATCH_WRITE = base::MessagePumpIOSForIO::WATCH_WRITE,
647 WATCH_READ_WRITE = MessagePumpIOSForIO::WATCH_READ_WRITE 651 WATCH_READ_WRITE = base::MessagePumpIOSForIO::WATCH_READ_WRITE
648 }; 652 };
649 #elif defined(OS_POSIX) 653 #elif defined(OS_POSIX)
650 typedef MessagePumpLibevent::Watcher Watcher; 654 typedef base::MessagePumpLibevent::Watcher Watcher;
651 typedef MessagePumpLibevent::FileDescriptorWatcher 655 typedef base::MessagePumpLibevent::FileDescriptorWatcher
652 FileDescriptorWatcher; 656 FileDescriptorWatcher;
653 typedef MessagePumpLibevent::IOObserver IOObserver; 657 typedef base::MessagePumpLibevent::IOObserver IOObserver;
654 658
655 enum Mode { 659 enum Mode {
656 WATCH_READ = MessagePumpLibevent::WATCH_READ, 660 WATCH_READ = base::MessagePumpLibevent::WATCH_READ,
657 WATCH_WRITE = MessagePumpLibevent::WATCH_WRITE, 661 WATCH_WRITE = base::MessagePumpLibevent::WATCH_WRITE,
658 WATCH_READ_WRITE = MessagePumpLibevent::WATCH_READ_WRITE 662 WATCH_READ_WRITE = base::MessagePumpLibevent::WATCH_READ_WRITE
659 }; 663 };
660 664
661 #endif 665 #endif
662 666
663 MessageLoopForIO() : MessageLoop(TYPE_IO) { 667 MessageLoopForIO() : MessageLoop(TYPE_IO) {
664 } 668 }
665 669
666 // Returns the MessageLoopForIO of the current thread. 670 // Returns the MessageLoopForIO of the current thread.
667 static MessageLoopForIO* current() { 671 static MessageLoopForIO* current() {
668 MessageLoop* loop = MessageLoop::current(); 672 MessageLoop* loop = MessageLoop::current();
(...skipping 10 matching lines...) Expand all
679 } 683 }
680 684
681 #if defined(OS_WIN) 685 #if defined(OS_WIN)
682 // Please see MessagePumpWin for definitions of these methods. 686 // Please see MessagePumpWin for definitions of these methods.
683 void RegisterIOHandler(HANDLE file, IOHandler* handler); 687 void RegisterIOHandler(HANDLE file, IOHandler* handler);
684 bool RegisterJobObject(HANDLE job, IOHandler* handler); 688 bool RegisterJobObject(HANDLE job, IOHandler* handler);
685 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter); 689 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter);
686 690
687 protected: 691 protected:
688 // TODO(rvargas): Make this platform independent. 692 // TODO(rvargas): Make this platform independent.
689 MessagePumpForIO* pump_io() { 693 base::MessagePumpForIO* pump_io() {
690 return static_cast<MessagePumpForIO*>(pump_.get()); 694 return static_cast<base::MessagePumpForIO*>(pump_.get());
691 } 695 }
692 696
693 #elif defined(OS_IOS) 697 #elif defined(OS_IOS)
694 // Please see MessagePumpIOSForIO for definition. 698 // Please see MessagePumpIOSForIO for definition.
695 bool WatchFileDescriptor(int fd, 699 bool WatchFileDescriptor(int fd,
696 bool persistent, 700 bool persistent,
697 Mode mode, 701 Mode mode,
698 FileDescriptorWatcher *controller, 702 FileDescriptorWatcher *controller,
699 Watcher *delegate); 703 Watcher *delegate);
700 704
701 private: 705 private:
702 MessagePumpIOSForIO* pump_io() { 706 base::MessagePumpIOSForIO* pump_io() {
703 return static_cast<MessagePumpIOSForIO*>(pump_.get()); 707 return static_cast<base::MessagePumpIOSForIO*>(pump_.get());
704 } 708 }
705 709
706 #elif defined(OS_POSIX) 710 #elif defined(OS_POSIX)
707 // Please see MessagePumpLibevent for definition. 711 // Please see MessagePumpLibevent for definition.
708 bool WatchFileDescriptor(int fd, 712 bool WatchFileDescriptor(int fd,
709 bool persistent, 713 bool persistent,
710 Mode mode, 714 Mode mode,
711 FileDescriptorWatcher* controller, 715 FileDescriptorWatcher* controller,
712 Watcher* delegate); 716 Watcher* delegate);
713 717
714 private: 718 private:
715 MessagePumpLibevent* pump_io() { 719 base::MessagePumpLibevent* pump_io() {
716 return static_cast<MessagePumpLibevent*>(pump_.get()); 720 return static_cast<base::MessagePumpLibevent*>(pump_.get());
717 } 721 }
718 #endif // defined(OS_POSIX) 722 #endif // defined(OS_POSIX)
719 }; 723 };
720 724
721 // Do not add any member variables to MessageLoopForIO! This is important b/c 725 // Do not add any member variables to MessageLoopForIO! This is important b/c
722 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 726 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
723 // data that you need should be stored on the MessageLoop's pump_ instance. 727 // data that you need should be stored on the MessageLoop's pump_ instance.
724 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 728 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
725 MessageLoopForIO_should_not_have_extra_member_variables); 729 MessageLoopForIO_should_not_have_extra_member_variables);
726 730
727 } // namespace base 731 } // namespace base
728 732
729 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 733 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « trunk/src/base/mac/scoped_sending_event.h ('k') | trunk/src/base/message_loop/message_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698