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