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

Side by Side Diff: base/message_loop.h

Issue 6736019: Base: A few more files using BASE_API (for base.dll) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 | « base/debug/stack_trace.h ('k') | base/message_loop_proxy.h » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_H_ 5 #ifndef BASE_MESSAGE_LOOP_H_
6 #define BASE_MESSAGE_LOOP_H_ 6 #define BASE_MESSAGE_LOOP_H_
7 #pragma once 7 #pragma once
8 8
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 11
12 #include "base/base_api.h"
12 #include "base/basictypes.h" 13 #include "base/basictypes.h"
13 #include "base/message_pump.h" 14 #include "base/message_pump.h"
14 #include "base/observer_list.h" 15 #include "base/observer_list.h"
15 #include "base/ref_counted.h" 16 #include "base/ref_counted.h"
16 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
17 #include "base/task.h" 18 #include "base/task.h"
18 19
19 #if defined(OS_WIN) 20 #if defined(OS_WIN)
20 // We need this to declare base::MessagePumpWin::Dispatcher, which we should 21 // We need this to declare base::MessagePumpWin::Dispatcher, which we should
21 // really just eliminate. 22 // really just eliminate.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // Sample workaround when inner task processing is needed: 59 // Sample workaround when inner task processing is needed:
59 // bool old_state = MessageLoop::current()->NestableTasksAllowed(); 60 // bool old_state = MessageLoop::current()->NestableTasksAllowed();
60 // MessageLoop::current()->SetNestableTasksAllowed(true); 61 // MessageLoop::current()->SetNestableTasksAllowed(true);
61 // HRESULT hr = DoDragDrop(...); // Implicitly runs a modal message loop here. 62 // HRESULT hr = DoDragDrop(...); // Implicitly runs a modal message loop here.
62 // MessageLoop::current()->SetNestableTasksAllowed(old_state); 63 // MessageLoop::current()->SetNestableTasksAllowed(old_state);
63 // // Process hr (the result returned by DoDragDrop(). 64 // // Process hr (the result returned by DoDragDrop().
64 // 65 //
65 // Please be SURE your task is reentrant (nestable) and all global variables 66 // Please be SURE your task is reentrant (nestable) and all global variables
66 // are stable and accessible before calling SetNestableTasksAllowed(true). 67 // are stable and accessible before calling SetNestableTasksAllowed(true).
67 // 68 //
68 class MessageLoop : public base::MessagePump::Delegate { 69 class BASE_API MessageLoop : public base::MessagePump::Delegate {
69 public: 70 public:
70 #if defined(OS_WIN) 71 #if defined(OS_WIN)
71 typedef base::MessagePumpWin::Dispatcher Dispatcher; 72 typedef base::MessagePumpWin::Dispatcher Dispatcher;
72 typedef base::MessagePumpForUI::Observer Observer; 73 typedef base::MessagePumpForUI::Observer Observer;
73 #elif !defined(OS_MACOSX) 74 #elif !defined(OS_MACOSX)
74 #if defined(TOUCH_UI) 75 #if defined(TOUCH_UI)
75 typedef base::MessagePumpGlibXDispatcher Dispatcher; 76 typedef base::MessagePumpGlibXDispatcher Dispatcher;
76 #else 77 #else
77 typedef base::MessagePumpForUI::Dispatcher Dispatcher; 78 typedef base::MessagePumpForUI::Dispatcher Dispatcher;
78 #endif 79 #endif
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 static void EnableHistogrammer(bool enable_histogrammer); 111 static void EnableHistogrammer(bool enable_histogrammer);
111 112
112 // A DestructionObserver is notified when the current MessageLoop is being 113 // A DestructionObserver is notified when the current MessageLoop is being
113 // destroyed. These obsevers are notified prior to MessageLoop::current() 114 // destroyed. These obsevers are notified prior to MessageLoop::current()
114 // being changed to return NULL. This gives interested parties the chance to 115 // being changed to return NULL. This gives interested parties the chance to
115 // do final cleanup that depends on the MessageLoop. 116 // do final cleanup that depends on the MessageLoop.
116 // 117 //
117 // NOTE: Any tasks posted to the MessageLoop during this notification will 118 // NOTE: Any tasks posted to the MessageLoop during this notification will
118 // not be run. Instead, they will be deleted. 119 // not be run. Instead, they will be deleted.
119 // 120 //
120 class DestructionObserver { 121 class BASE_API DestructionObserver {
121 public: 122 public:
122 virtual void WillDestroyCurrentMessageLoop() = 0; 123 virtual void WillDestroyCurrentMessageLoop() = 0;
123 124
124 protected: 125 protected:
125 virtual ~DestructionObserver(); 126 virtual ~DestructionObserver();
126 }; 127 };
127 128
128 // Add a DestructionObserver, which will start receiving notifications 129 // Add a DestructionObserver, which will start receiving notifications
129 // immediately. 130 // immediately.
130 void AddDestructionObserver(DestructionObserver* destruction_observer); 131 void AddDestructionObserver(DestructionObserver* destruction_observer);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 exception_restoration_ = restore; 277 exception_restoration_ = restore;
277 } 278 }
278 279
279 // Returns true if we are currently running a nested message loop. 280 // Returns true if we are currently running a nested message loop.
280 bool IsNested(); 281 bool IsNested();
281 282
282 // A TaskObserver is an object that receives task notifications from the 283 // A TaskObserver is an object that receives task notifications from the
283 // MessageLoop. 284 // MessageLoop.
284 // 285 //
285 // NOTE: A TaskObserver implementation should be extremely fast! 286 // NOTE: A TaskObserver implementation should be extremely fast!
286 class TaskObserver { 287 class BASE_API TaskObserver {
287 public: 288 public:
288 TaskObserver(); 289 TaskObserver();
289 290
290 // This method is called before processing a task. 291 // This method is called before processing a task.
291 virtual void WillProcessTask(const Task* task) = 0; 292 virtual void WillProcessTask(const Task* task) = 0;
292 293
293 // This method is called after processing a task. 294 // This method is called after processing a task.
294 virtual void DidProcessTask(const Task* task) = 0; 295 virtual void DidProcessTask(const Task* task) = 0;
295 296
296 protected: 297 protected:
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc 490 // Should be set to true before calling Windows APIs like TrackPopupMenu, etc
490 // which enter a modal message loop. 491 // which enter a modal message loop.
491 bool os_modal_loop_; 492 bool os_modal_loop_;
492 #endif 493 #endif
493 494
494 // The next sequence number to use for delayed tasks. 495 // The next sequence number to use for delayed tasks.
495 int next_sequence_num_; 496 int next_sequence_num_;
496 497
497 ObserverList<TaskObserver> task_observers_; 498 ObserverList<TaskObserver> task_observers_;
498 499
500 private:
499 DISALLOW_COPY_AND_ASSIGN(MessageLoop); 501 DISALLOW_COPY_AND_ASSIGN(MessageLoop);
500 }; 502 };
501 503
502 //----------------------------------------------------------------------------- 504 //-----------------------------------------------------------------------------
503 // MessageLoopForUI extends MessageLoop with methods that are particular to a 505 // MessageLoopForUI extends MessageLoop with methods that are particular to a
504 // MessageLoop instantiated with TYPE_UI. 506 // MessageLoop instantiated with TYPE_UI.
505 // 507 //
506 // This class is typically used like so: 508 // This class is typically used like so:
507 // MessageLoopForUI::current()->...call some method... 509 // MessageLoopForUI::current()->...call some method...
508 // 510 //
509 class MessageLoopForUI : public MessageLoop { 511 class BASE_API MessageLoopForUI : public MessageLoop {
510 public: 512 public:
511 MessageLoopForUI() : MessageLoop(TYPE_UI) { 513 MessageLoopForUI() : MessageLoop(TYPE_UI) {
512 } 514 }
513 515
514 // Returns the MessageLoopForUI of the current thread. 516 // Returns the MessageLoopForUI of the current thread.
515 static MessageLoopForUI* current() { 517 static MessageLoopForUI* current() {
516 MessageLoop* loop = MessageLoop::current(); 518 MessageLoop* loop = MessageLoop::current();
517 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); 519 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type());
518 return static_cast<MessageLoopForUI*>(loop); 520 return static_cast<MessageLoopForUI*>(loop);
519 } 521 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForUI), 557 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForUI),
556 MessageLoopForUI_should_not_have_extra_member_variables); 558 MessageLoopForUI_should_not_have_extra_member_variables);
557 559
558 //----------------------------------------------------------------------------- 560 //-----------------------------------------------------------------------------
559 // MessageLoopForIO extends MessageLoop with methods that are particular to a 561 // MessageLoopForIO extends MessageLoop with methods that are particular to a
560 // MessageLoop instantiated with TYPE_IO. 562 // MessageLoop instantiated with TYPE_IO.
561 // 563 //
562 // This class is typically used like so: 564 // This class is typically used like so:
563 // MessageLoopForIO::current()->...call some method... 565 // MessageLoopForIO::current()->...call some method...
564 // 566 //
565 class MessageLoopForIO : public MessageLoop { 567 class BASE_API MessageLoopForIO : public MessageLoop {
566 public: 568 public:
567 #if defined(OS_WIN) 569 #if defined(OS_WIN)
568 typedef base::MessagePumpForIO::IOHandler IOHandler; 570 typedef base::MessagePumpForIO::IOHandler IOHandler;
569 typedef base::MessagePumpForIO::IOContext IOContext; 571 typedef base::MessagePumpForIO::IOContext IOContext;
570 typedef base::MessagePumpForIO::IOObserver IOObserver; 572 typedef base::MessagePumpForIO::IOObserver IOObserver;
571 #elif defined(OS_POSIX) 573 #elif defined(OS_POSIX)
572 typedef base::MessagePumpLibevent::Watcher Watcher; 574 typedef base::MessagePumpLibevent::Watcher Watcher;
573 typedef base::MessagePumpLibevent::FileDescriptorWatcher 575 typedef base::MessagePumpLibevent::FileDescriptorWatcher
574 FileDescriptorWatcher; 576 FileDescriptorWatcher;
575 typedef base::MessagePumpLibevent::IOObserver IOObserver; 577 typedef base::MessagePumpLibevent::IOObserver IOObserver;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 #endif // defined(OS_POSIX) 628 #endif // defined(OS_POSIX)
627 }; 629 };
628 630
629 // Do not add any member variables to MessageLoopForIO! This is important b/c 631 // Do not add any member variables to MessageLoopForIO! This is important b/c
630 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 632 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
631 // data that you need should be stored on the MessageLoop's pump_ instance. 633 // data that you need should be stored on the MessageLoop's pump_ instance.
632 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 634 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
633 MessageLoopForIO_should_not_have_extra_member_variables); 635 MessageLoopForIO_should_not_have_extra_member_variables);
634 636
635 #endif // BASE_MESSAGE_LOOP_H_ 637 #endif // BASE_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « base/debug/stack_trace.h ('k') | base/message_loop_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698