| OLD | NEW |
| 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 MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ | 5 #ifndef MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ |
| 6 #define MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ | 6 #define MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 Observer() {} | 29 Observer() {} |
| 30 | 30 |
| 31 virtual void WillSignalHandler() = 0; | 31 virtual void WillSignalHandler() = 0; |
| 32 virtual void DidSignalHandler() = 0; | 32 virtual void DidSignalHandler() = 0; |
| 33 | 33 |
| 34 protected: | 34 protected: |
| 35 virtual ~Observer() {} | 35 virtual ~Observer() {} |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 MessagePumpMojo(); | 38 MessagePumpMojo(); |
| 39 virtual ~MessagePumpMojo(); | 39 ~MessagePumpMojo() override; |
| 40 | 40 |
| 41 // Static factory function (for using with |base::Thread::Options|, wrapped | 41 // Static factory function (for using with |base::Thread::Options|, wrapped |
| 42 // using |base::Bind()|). | 42 // using |base::Bind()|). |
| 43 static scoped_ptr<base::MessagePump> Create(); | 43 static scoped_ptr<base::MessagePump> Create(); |
| 44 | 44 |
| 45 // Returns the MessagePumpMojo instance of the current thread, if it exists. | 45 // Returns the MessagePumpMojo instance of the current thread, if it exists. |
| 46 static MessagePumpMojo* current(); | 46 static MessagePumpMojo* current(); |
| 47 | 47 |
| 48 static bool IsCurrent() { return !!current(); } | 48 static bool IsCurrent() { return !!current(); } |
| 49 | 49 |
| 50 // Registers a MessagePumpMojoHandler for the specified handle. Only one | 50 // Registers a MessagePumpMojoHandler for the specified handle. Only one |
| 51 // handler can be registered for a specified handle. | 51 // handler can be registered for a specified handle. |
| 52 // NOTE: a value of 0 for |deadline| indicates an indefinite timeout. | 52 // NOTE: a value of 0 for |deadline| indicates an indefinite timeout. |
| 53 void AddHandler(MessagePumpMojoHandler* handler, | 53 void AddHandler(MessagePumpMojoHandler* handler, |
| 54 const Handle& handle, | 54 const Handle& handle, |
| 55 MojoHandleSignals wait_signals, | 55 MojoHandleSignals wait_signals, |
| 56 base::TimeTicks deadline); | 56 base::TimeTicks deadline); |
| 57 | 57 |
| 58 void RemoveHandler(const Handle& handle); | 58 void RemoveHandler(const Handle& handle); |
| 59 | 59 |
| 60 void AddObserver(Observer*); | 60 void AddObserver(Observer*); |
| 61 void RemoveObserver(Observer*); | 61 void RemoveObserver(Observer*); |
| 62 | 62 |
| 63 // MessagePump: | 63 // MessagePump: |
| 64 virtual void Run(Delegate* delegate) override; | 64 void Run(Delegate* delegate) override; |
| 65 virtual void Quit() override; | 65 void Quit() override; |
| 66 virtual void ScheduleWork() override; | 66 void ScheduleWork() override; |
| 67 virtual void ScheduleDelayedWork( | 67 void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override; |
| 68 const base::TimeTicks& delayed_work_time) override; | |
| 69 | 68 |
| 70 private: | 69 private: |
| 71 struct RunState; | 70 struct RunState; |
| 72 struct WaitState; | 71 struct WaitState; |
| 73 | 72 |
| 74 // Contains the data needed to track a request to AddHandler(). | 73 // Contains the data needed to track a request to AddHandler(). |
| 75 struct Handler { | 74 struct Handler { |
| 76 Handler() : handler(NULL), wait_signals(MOJO_HANDLE_SIGNAL_NONE), id(0) {} | 75 Handler() : handler(NULL), wait_signals(MOJO_HANDLE_SIGNAL_NONE), id(0) {} |
| 77 | 76 |
| 78 MessagePumpMojoHandler* handler; | 77 MessagePumpMojoHandler* handler; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 125 |
| 127 ObserverList<Observer> observers_; | 126 ObserverList<Observer> observers_; |
| 128 | 127 |
| 129 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo); | 128 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo); |
| 130 }; | 129 }; |
| 131 | 130 |
| 132 } // namespace common | 131 } // namespace common |
| 133 } // namespace mojo | 132 } // namespace mojo |
| 134 | 133 |
| 135 #endif // MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ | 134 #endif // MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ |
| OLD | NEW |