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

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

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « base/memory/shared_memory_win.cc ('k') | 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/debug/task_annotator.h" 14 #include "base/debug/task_annotator.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/message_loop/incoming_task_queue.h" 18 #include "base/message_loop/incoming_task_queue.h"
19 #include "base/message_loop/message_loop_proxy.h" 19 #include "base/message_loop/message_loop_task_runner.h"
20 #include "base/message_loop/message_loop_proxy_impl.h"
21 #include "base/message_loop/message_pump.h" 20 #include "base/message_loop/message_pump.h"
22 #include "base/message_loop/timer_slack.h" 21 #include "base/message_loop/timer_slack.h"
23 #include "base/observer_list.h" 22 #include "base/observer_list.h"
24 #include "base/pending_task.h" 23 #include "base/pending_task.h"
25 #include "base/sequenced_task_runner_helpers.h" 24 #include "base/sequenced_task_runner_helpers.h"
26 #include "base/synchronization/lock.h" 25 #include "base/synchronization/lock.h"
27 #include "base/time/time.h" 26 #include "base/time/time.h"
28 #include "base/tracking_info.h" 27 #include "base/tracking_info.h"
29 28
30 // TODO(sky): these includes should not be necessary. Nuke them. 29 // TODO(sky): these includes should not be necessary. Nuke them.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // Returns the type passed to the constructor. 288 // Returns the type passed to the constructor.
290 Type type() const { return type_; } 289 Type type() const { return type_; }
291 290
292 // Optional call to connect the thread name with this loop. 291 // Optional call to connect the thread name with this loop.
293 void set_thread_name(const std::string& thread_name) { 292 void set_thread_name(const std::string& thread_name) {
294 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; 293 DCHECK(thread_name_.empty()) << "Should not rename this thread!";
295 thread_name_ = thread_name; 294 thread_name_ = thread_name;
296 } 295 }
297 const std::string& thread_name() const { return thread_name_; } 296 const std::string& thread_name() const { return thread_name_; }
298 297
299 // Gets the message loop proxy associated with this message loop. 298 // Gets the TaskRunner associated with this message loop.
300 // 299 const scoped_refptr<SingleThreadTaskRunner>& task_runner() {
301 // NOTE: Deprecated; prefer task_runner() and the TaskRunner interfaces 300 return task_runner_;
302 scoped_refptr<MessageLoopProxy> message_loop_proxy() {
303 return message_loop_proxy_;
304 } 301 }
305 302
306 // Gets the TaskRunner associated with this message loop. 303 // Sets a new TaskRunner for this message loop. The message loop must already
307 // TODO(skyostil): Change this to return a const reference to a refptr 304 // have been bound to a thread prior to this call, and the task runner must
308 // once the internal type matches what is being returned (crbug.com/465354). 305 // belong to that thread. Note that changing the task runner will also affect
309 scoped_refptr<SingleThreadTaskRunner> task_runner() { 306 // the ThreadTaskRunnerHandle for the target thread. Must be called on the
310 return message_loop_proxy_; 307 // thread to which the message loop is bound.
311 } 308 void SetTaskRunner(scoped_refptr<SingleThreadTaskRunner> task_runner);
312 309
313 // Enables or disables the recursive task processing. This happens in the case 310 // Enables or disables the recursive task processing. This happens in the case
314 // of recursive message loops. Some unwanted message loop may occurs when 311 // of recursive message loops. Some unwanted message loop may occurs when
315 // using common controls or printer functions. By default, recursive task 312 // using common controls or printer functions. By default, recursive task
316 // processing is disabled. 313 // processing is disabled.
317 // 314 //
318 // Please utilize |ScopedNestableTaskAllower| instead of calling these methods 315 // Please utilize |ScopedNestableTaskAllower| instead of calling these methods
319 // directly. In general nestable message loops are to be avoided. They are 316 // directly. In general nestable message loops are to be avoided. They are
320 // dangerous and difficult to get right, so please use with extreme caution. 317 // dangerous and difficult to get right, so please use with extreme caution.
321 // 318 //
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // If |type| is TYPE_CUSTOM non-null |pump_factory| must be also given 415 // If |type| is TYPE_CUSTOM non-null |pump_factory| must be also given
419 // to create a message pump for this message loop. Otherwise a default 416 // to create a message pump for this message loop. Otherwise a default
420 // message pump for the |type| is created. 417 // message pump for the |type| is created.
421 // 418 //
422 // It is valid to call this to create a new message loop on one thread, 419 // It is valid to call this to create a new message loop on one thread,
423 // and then pass it to the thread where the message loop actually runs. 420 // and then pass it to the thread where the message loop actually runs.
424 // The message loop's BindToCurrentThread() method must be called on the 421 // The message loop's BindToCurrentThread() method must be called on the
425 // thread the message loop runs on, before calling Run(). 422 // thread the message loop runs on, before calling Run().
426 // Before BindToCurrentThread() is called only Post*Task() functions can 423 // Before BindToCurrentThread() is called only Post*Task() functions can
427 // be called on the message loop. 424 // be called on the message loop.
428 scoped_ptr<MessageLoop> CreateUnbound( 425 static scoped_ptr<MessageLoop> CreateUnbound(
429 Type type, 426 Type type,
430 MessagePumpFactoryCallback pump_factory); 427 MessagePumpFactoryCallback pump_factory);
431 428
432 // Common private constructor. Other constructors delegate the initialization 429 // Common private constructor. Other constructors delegate the initialization
433 // to this constructor. 430 // to this constructor.
434 MessageLoop(Type type, MessagePumpFactoryCallback pump_factory); 431 MessageLoop(Type type, MessagePumpFactoryCallback pump_factory);
435 432
436 // Configure various members and bind this message loop to the current thread. 433 // Configure various members and bind this message loop to the current thread.
437 void BindToCurrentThread(); 434 void BindToCurrentThread();
438 435
436 // Sets the ThreadTaskRunnerHandle for the current thread to point to the
437 // task runner for this message loop.
438 void SetThreadTaskRunnerHandle();
439
439 // Invokes the actual run loop using the message pump. 440 // Invokes the actual run loop using the message pump.
440 void RunHandler(); 441 void RunHandler();
441 442
442 // Called to process any delayed non-nestable tasks. 443 // Called to process any delayed non-nestable tasks.
443 bool ProcessNextDelayedNonNestableTask(); 444 bool ProcessNextDelayedNonNestableTask();
444 445
445 // Calls RunTask or queues the pending_task on the deferred task list if it 446 // Calls RunTask or queues the pending_task on the deferred task list if it
446 // cannot be run right now. Returns true if the task was run. 447 // cannot be run right now. Returns true if the task was run.
447 bool DeferOrRunPendingTask(const PendingTask& pending_task); 448 bool DeferOrRunPendingTask(const PendingTask& pending_task);
448 449
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 HistogramBase* message_histogram_; 525 HistogramBase* message_histogram_;
525 526
526 RunLoop* run_loop_; 527 RunLoop* run_loop_;
527 528
528 ObserverList<TaskObserver> task_observers_; 529 ObserverList<TaskObserver> task_observers_;
529 530
530 debug::TaskAnnotator task_annotator_; 531 debug::TaskAnnotator task_annotator_;
531 532
532 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; 533 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_;
533 534
534 // The message loop proxy associated with this message loop. 535 // A task runner which we haven't bound to a thread yet.
535 scoped_refptr<internal::MessageLoopProxyImpl> message_loop_proxy_; 536 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_;
537
538 // The task runner associated with this message loop.
539 scoped_refptr<SingleThreadTaskRunner> task_runner_;
536 scoped_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; 540 scoped_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_;
537 541
538 template <class T, class R> friend class base::subtle::DeleteHelperInternal; 542 template <class T, class R> friend class base::subtle::DeleteHelperInternal;
539 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; 543 template <class T, class R> friend class base::subtle::ReleaseHelperInternal;
540 544
541 void DeleteSoonInternal(const tracked_objects::Location& from_here, 545 void DeleteSoonInternal(const tracked_objects::Location& from_here,
542 void(*deleter)(const void*), 546 void(*deleter)(const void*),
543 const void* object); 547 const void* object);
544 void ReleaseSoonInternal(const tracked_objects::Location& from_here, 548 void ReleaseSoonInternal(const tracked_objects::Location& from_here,
545 void(*releaser)(const void*), 549 void(*releaser)(const void*),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 687
684 // Do not add any member variables to MessageLoopForIO! This is important b/c 688 // Do not add any member variables to MessageLoopForIO! This is important b/c
685 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 689 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
686 // data that you need should be stored on the MessageLoop's pump_ instance. 690 // data that you need should be stored on the MessageLoop's pump_ instance.
687 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 691 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
688 MessageLoopForIO_should_not_have_extra_member_variables); 692 MessageLoopForIO_should_not_have_extra_member_variables);
689 693
690 } // namespace base 694 } // namespace base
691 695
692 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 696 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « base/memory/shared_memory_win.cc ('k') | base/message_loop/message_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698