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

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

Issue 1582123002: Augment message_loop with ability for custom UI message pumps (issue 576536) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | 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.
Mark Mentovai 2016/01/25 14:54:55 Give this change an appropriate description. The d
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"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // tasks. 392 // tasks.
393 debug::TaskAnnotator* task_annotator() { return &task_annotator_; } 393 debug::TaskAnnotator* task_annotator() { return &task_annotator_; }
394 394
395 // Runs the specified PendingTask. 395 // Runs the specified PendingTask.
396 void RunTask(const PendingTask& pending_task); 396 void RunTask(const PendingTask& pending_task);
397 397
398 //---------------------------------------------------------------------------- 398 //----------------------------------------------------------------------------
399 protected: 399 protected:
400 scoped_ptr<MessagePump> pump_; 400 scoped_ptr<MessagePump> pump_;
401 401
402 using MessagePumpFactoryCallback = Callback<scoped_ptr<MessagePump>()>;
403
404 // Common protected constructor. Other constructors delegate the
405 // initialization to this constructor.
406 MessageLoop(Type type, MessagePumpFactoryCallback pump_factory);
407
408 // Configure various members and bind this message loop to the current thread.
Mark Mentovai 2016/01/25 14:54:54 Since this is now protected, you should say when a
409 void BindToCurrentThread();
410
402 private: 411 private:
403 friend class RunLoop; 412 friend class RunLoop;
404 friend class internal::IncomingTaskQueue; 413 friend class internal::IncomingTaskQueue;
405 friend class ScheduleWorkTest; 414 friend class ScheduleWorkTest;
406 friend class Thread; 415 friend class Thread;
407 FRIEND_TEST_ALL_PREFIXES(MessageLoopTest, DeleteUnboundLoop); 416 FRIEND_TEST_ALL_PREFIXES(MessageLoopTest, DeleteUnboundLoop);
408 417
409 using MessagePumpFactoryCallback = Callback<scoped_ptr<MessagePump>()>;
410
411 // Creates a MessageLoop without binding to a thread. 418 // Creates a MessageLoop without binding to a thread.
412 // If |type| is TYPE_CUSTOM non-null |pump_factory| must be also given 419 // If |type| is TYPE_CUSTOM non-null |pump_factory| must be also given
413 // to create a message pump for this message loop. Otherwise a default 420 // to create a message pump for this message loop. Otherwise a default
414 // message pump for the |type| is created. 421 // message pump for the |type| is created.
415 // 422 //
416 // It is valid to call this to create a new message loop on one thread, 423 // It is valid to call this to create a new message loop on one thread,
417 // and then pass it to the thread where the message loop actually runs. 424 // and then pass it to the thread where the message loop actually runs.
418 // The message loop's BindToCurrentThread() method must be called on the 425 // The message loop's BindToCurrentThread() method must be called on the
419 // thread the message loop runs on, before calling Run(). 426 // thread the message loop runs on, before calling Run().
420 // Before BindToCurrentThread() is called, only Post*Task() functions can 427 // Before BindToCurrentThread() is called, only Post*Task() functions can
421 // be called on the message loop. 428 // be called on the message loop.
422 static scoped_ptr<MessageLoop> CreateUnbound( 429 static scoped_ptr<MessageLoop> CreateUnbound(
423 Type type, 430 Type type,
424 MessagePumpFactoryCallback pump_factory); 431 MessagePumpFactoryCallback pump_factory);
425 432
426 // Common private constructor. Other constructors delegate the initialization
427 // to this constructor.
428 MessageLoop(Type type, MessagePumpFactoryCallback pump_factory);
429
430 // Configure various members and bind this message loop to the current thread.
431 void BindToCurrentThread();
432
433 // Sets the ThreadTaskRunnerHandle for the current thread to point to the 433 // Sets the ThreadTaskRunnerHandle for the current thread to point to the
434 // task runner for this message loop. 434 // task runner for this message loop.
435 void SetThreadTaskRunnerHandle(); 435 void SetThreadTaskRunnerHandle();
436 436
437 // Invokes the actual run loop using the message pump. 437 // Invokes the actual run loop using the message pump.
438 void RunHandler(); 438 void RunHandler();
439 439
440 // Called to process any delayed non-nestable tasks. 440 // Called to process any delayed non-nestable tasks.
441 bool ProcessNextDelayedNonNestableTask(); 441 bool ProcessNextDelayedNonNestableTask();
442 442
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 // MessageLoop instantiated with TYPE_UI. 556 // MessageLoop instantiated with TYPE_UI.
557 // 557 //
558 // This class is typically used like so: 558 // This class is typically used like so:
559 // MessageLoopForUI::current()->...call some method... 559 // MessageLoopForUI::current()->...call some method...
560 // 560 //
561 class BASE_EXPORT MessageLoopForUI : public MessageLoop { 561 class BASE_EXPORT MessageLoopForUI : public MessageLoop {
562 public: 562 public:
563 MessageLoopForUI() : MessageLoop(TYPE_UI) { 563 MessageLoopForUI() : MessageLoop(TYPE_UI) {
564 } 564 }
565 565
566 explicit MessageLoopForUI(scoped_ptr<MessagePump> pump);
567
566 // Returns the MessageLoopForUI of the current thread. 568 // Returns the MessageLoopForUI of the current thread.
567 static MessageLoopForUI* current() { 569 static MessageLoopForUI* current() {
568 MessageLoop* loop = MessageLoop::current(); 570 MessageLoop* loop = MessageLoop::current();
569 DCHECK(loop); 571 DCHECK(loop);
570 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); 572 DCHECK(loop->IsType(MessageLoop::TYPE_UI));
571 return static_cast<MessageLoopForUI*>(loop); 573 return static_cast<MessageLoopForUI*>(loop);
572 } 574 }
573 575
574 static bool IsCurrent() { 576 static bool IsCurrent() {
575 MessageLoop* loop = MessageLoop::current(); 577 MessageLoop* loop = MessageLoop::current();
576 return loop && loop->type() == MessageLoop::TYPE_UI; 578 return loop && loop->IsType(MessageLoop::TYPE_UI);
577 } 579 }
578 580
579 #if defined(OS_IOS) 581 #if defined(OS_IOS)
580 // On iOS, the main message loop cannot be Run(). Instead call Attach(), 582 // On iOS, the main message loop cannot be Run(). Instead call Attach(),
581 // which connects this MessageLoop to the UI thread's CFRunLoop and allows 583 // which connects this MessageLoop to the UI thread's CFRunLoop and allows
582 // PostTask() to work. 584 // PostTask() to work.
583 void Attach(); 585 void Attach();
584 #endif 586 #endif
585 587
586 #if defined(OS_ANDROID) 588 #if defined(OS_ANDROID)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 686
685 // Do not add any member variables to MessageLoopForIO! This is important b/c 687 // Do not add any member variables to MessageLoopForIO! This is important b/c
686 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 688 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
687 // data that you need should be stored on the MessageLoop's pump_ instance. 689 // data that you need should be stored on the MessageLoop's pump_ instance.
688 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 690 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
689 "MessageLoopForIO should not have extra member variables"); 691 "MessageLoopForIO should not have extra member variables");
690 692
691 } // namespace base 693 } // namespace base
692 694
693 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 695 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_loop/message_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698