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/message_loop/message_pump.h" | 10 #include "base/message_loop/message_pump.h" |
| 11 #include "base/time/time.h" |
11 #include "mojo/common/mojo_common_export.h" | 12 #include "mojo/common/mojo_common_export.h" |
12 #include "mojo/public/system/core.h" | 13 #include "mojo/public/system/core.h" |
13 | 14 |
14 namespace mojo { | 15 namespace mojo { |
15 namespace common { | 16 namespace common { |
16 | 17 |
17 class MessagePumpMojoHandler; | 18 class MessagePumpMojoHandler; |
18 | 19 |
19 // Mojo implementation of MessagePump. | 20 // Mojo implementation of MessagePump. |
20 class MOJO_COMMON_EXPORT MessagePumpMojo : public base::MessagePump { | 21 class MOJO_COMMON_EXPORT MessagePumpMojo : public base::MessagePump { |
21 public: | 22 public: |
22 MessagePumpMojo(); | 23 MessagePumpMojo(); |
23 virtual ~MessagePumpMojo(); | 24 virtual ~MessagePumpMojo(); |
24 | 25 |
25 // Registers a MessagePumpMojoHandler for the specified handle. Only one | 26 // Registers a MessagePumpMojoHandler for the specified handle. Only one |
26 // handler can be registered for a specified handle. If there is an existing | 27 // handler can be registered for a specified handle. If there is an existing |
27 // handler registered it is clobbered and silently removed. | 28 // handler already registered the existing handler is notified it was removed |
28 // The handler is notified either when the handle is ready, or when it becomes | 29 // (MOJO_RESULT_CANCELLED). If the handle becomes invalid the handler is |
29 // invalid. If the handle becomes invalid the handler is removed and notified. | 30 // removed and notified. |
30 void AddHandler(MessagePumpMojoHandler* handler, | 31 void AddHandler(MessagePumpMojoHandler* handler, |
31 MojoHandle handle, | 32 MojoHandle handle, |
32 MojoWaitFlags wait_flags); | 33 MojoWaitFlags wait_flags, |
| 34 base::TimeTicks deadline); |
33 | 35 |
34 void RemoveHandler(MojoHandle handle); | 36 void RemoveHandler(MojoHandle handle); |
35 | 37 |
36 // MessagePump: | 38 // MessagePump: |
37 virtual void Run(Delegate* delegate) OVERRIDE; | 39 virtual void Run(Delegate* delegate) OVERRIDE; |
38 virtual void Quit() OVERRIDE; | 40 virtual void Quit() OVERRIDE; |
39 virtual void ScheduleWork() OVERRIDE; | 41 virtual void ScheduleWork() OVERRIDE; |
40 virtual void ScheduleDelayedWork( | 42 virtual void ScheduleDelayedWork( |
41 const base::TimeTicks& delayed_work_time) OVERRIDE; | 43 const base::TimeTicks& delayed_work_time) OVERRIDE; |
42 | 44 |
43 private: | 45 private: |
44 struct RunState; | 46 struct RunState; |
45 struct WaitState; | 47 struct WaitState; |
46 | 48 |
47 // Creates a MessagePumpMojoHandler and the set of MojoWaitFlags it was | 49 // Creates a MessagePumpMojoHandler and the set of MojoWaitFlags it was |
48 // registered with. | 50 // registered with. |
49 struct Handler { | 51 struct Handler { |
50 Handler() : handler(NULL), wait_flags(MOJO_WAIT_FLAG_NONE) {} | 52 Handler() : handler(NULL), wait_flags(MOJO_WAIT_FLAG_NONE) {} |
51 | 53 |
52 MessagePumpMojoHandler* handler; | 54 MessagePumpMojoHandler* handler; |
53 MojoWaitFlags wait_flags; | 55 MojoWaitFlags wait_flags; |
| 56 base::TimeTicks deadline; |
54 }; | 57 }; |
55 | 58 |
56 typedef std::map<MojoHandle, Handler> HandleToHandler; | 59 typedef std::map<MojoHandle, Handler> HandleToHandler; |
57 | 60 |
58 // Services the set of handles ready. If |block| is true this waits for a | 61 // Services the set of handles ready. If |block| is true this waits for a |
59 // handle to become ready, otherwise this does not block. | 62 // handle to become ready, otherwise this does not block. |
60 void DoInternalWork(bool block); | 63 void DoInternalWork(bool block); |
61 | 64 |
62 // Removes the first invalid handle. This is called if MojoWaitMany finds an | 65 // Removes the first invalid handle. This is called if MojoWaitMany finds an |
63 // invalid handle. | 66 // invalid handle. |
64 void RemoveFirstInvalidHandle(const WaitState& wait_state); | 67 void RemoveFirstInvalidHandle(const WaitState& wait_state); |
65 | 68 |
66 void SignalControlPipe(); | 69 void SignalControlPipe(); |
67 | 70 |
68 WaitState GetWaitState() const; | 71 WaitState GetWaitState() const; |
69 | 72 |
| 73 // Returns the deadline for the call to MojoWaitMany(). |
| 74 MojoDeadline GetDeadlineForWait() const; |
| 75 |
70 // If non-NULL we're running (inside Run()). Member is reference to value on | 76 // If non-NULL we're running (inside Run()). Member is reference to value on |
71 // stack. | 77 // stack. |
72 RunState* run_state_; | 78 RunState* run_state_; |
73 | 79 |
74 HandleToHandler handlers_; | 80 HandleToHandler handlers_; |
75 | 81 |
76 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo); | 82 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo); |
77 }; | 83 }; |
78 | 84 |
79 } // namespace common | 85 } // namespace common |
80 } // namespace mojo | 86 } // namespace mojo |
81 | 87 |
82 #endif // MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ | 88 #endif // MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ |
OLD | NEW |