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

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

Issue 2407313002: Disallow nesting on some BrowserThreads. (Closed)
Patch Set: self-review Created 4 years, 2 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.
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 <memory> 8 #include <memory>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // Returns true if the message loop is "idle". Provided for testing. 309 // Returns true if the message loop is "idle". Provided for testing.
310 bool IsIdleForTesting(); 310 bool IsIdleForTesting();
311 311
312 // Returns the TaskAnnotator which is used to add debug information to posted 312 // Returns the TaskAnnotator which is used to add debug information to posted
313 // tasks. 313 // tasks.
314 debug::TaskAnnotator* task_annotator() { return &task_annotator_; } 314 debug::TaskAnnotator* task_annotator() { return &task_annotator_; }
315 315
316 // Runs the specified PendingTask. 316 // Runs the specified PendingTask.
317 void RunTask(const PendingTask& pending_task); 317 void RunTask(const PendingTask& pending_task);
318 318
319 // Disallow nesting. After this is called, running a nested RunLoop or calling
320 // Add/RemoveNestingObserver() on this MessageLoop will crash.
321 void DisallowNesting() { allow_nesting_ = false; }
322
319 //---------------------------------------------------------------------------- 323 //----------------------------------------------------------------------------
320 protected: 324 protected:
321 std::unique_ptr<MessagePump> pump_; 325 std::unique_ptr<MessagePump> pump_;
322 326
323 using MessagePumpFactoryCallback = Callback<std::unique_ptr<MessagePump>()>; 327 using MessagePumpFactoryCallback = Callback<std::unique_ptr<MessagePump>()>;
324 328
325 // Common protected constructor. Other constructors delegate the 329 // Common protected constructor. Other constructors delegate the
326 // initialization to this constructor. 330 // initialization to this constructor.
327 // A subclass can invoke this constructor to create a message_loop of a 331 // A subclass can invoke this constructor to create a message_loop of a
328 // specific type with a custom loop. The implementation does not call 332 // specific type with a custom loop. The implementation does not call
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; 448 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_;
445 449
446 // The task runner associated with this message loop. 450 // The task runner associated with this message loop.
447 scoped_refptr<SingleThreadTaskRunner> task_runner_; 451 scoped_refptr<SingleThreadTaskRunner> task_runner_;
448 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; 452 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_;
449 453
450 // Id of the thread this message loop is bound to. Initialized once when the 454 // Id of the thread this message loop is bound to. Initialized once when the
451 // MessageLoop is bound to its thread and constant forever after. 455 // MessageLoop is bound to its thread and constant forever after.
452 PlatformThreadId thread_id_; 456 PlatformThreadId thread_id_;
453 457
458 // Whether nesting is allowed.
459 bool allow_nesting_ = true;
460
454 DISALLOW_COPY_AND_ASSIGN(MessageLoop); 461 DISALLOW_COPY_AND_ASSIGN(MessageLoop);
455 }; 462 };
456 463
457 #if !defined(OS_NACL) 464 #if !defined(OS_NACL)
458 465
459 //----------------------------------------------------------------------------- 466 //-----------------------------------------------------------------------------
460 // MessageLoopForUI extends MessageLoop with methods that are particular to a 467 // MessageLoopForUI extends MessageLoop with methods that are particular to a
461 // MessageLoop instantiated with TYPE_UI. 468 // MessageLoop instantiated with TYPE_UI.
462 // 469 //
463 // This class is typically used like so: 470 // This class is typically used like so:
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 598
592 // Do not add any member variables to MessageLoopForIO! This is important b/c 599 // Do not add any member variables to MessageLoopForIO! This is important b/c
593 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 600 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
594 // data that you need should be stored on the MessageLoop's pump_ instance. 601 // data that you need should be stored on the MessageLoop's pump_ instance.
595 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 602 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
596 "MessageLoopForIO should not have extra member variables"); 603 "MessageLoopForIO should not have extra member variables");
597 604
598 } // namespace base 605 } // namespace base
599 606
600 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 607 #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