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

Side by Side Diff: mojo/common/message_pump_mojo.h

Issue 69883008: Implements HandleWatcher in terms of MessagePumpMojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add id to detect whether should notify Created 7 years, 1 month 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 | « mojo/common/handle_watcher.cc ('k') | mojo/common/message_pump_mojo.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 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), id(0) {}
51 50
52 MessagePumpMojoHandler* handler; 51 MessagePumpMojoHandler* handler;
53 MojoWaitFlags wait_flags; 52 MojoWaitFlags wait_flags;
53 base::TimeTicks deadline;
54 // See description of |MessagePumpMojo::next_handler_id_| for details.
55 int id;
54 }; 56 };
55 57
56 typedef std::map<MojoHandle, Handler> HandleToHandler; 58 typedef std::map<MojoHandle, Handler> HandleToHandler;
57 59
58 // Services the set of handles ready. If |block| is true this waits for a 60 // Services the set of handles ready. If |block| is true this waits for a
59 // handle to become ready, otherwise this does not block. 61 // handle to become ready, otherwise this does not block.
60 void DoInternalWork(bool block); 62 void DoInternalWork(bool block);
61 63
62 // Removes the first invalid handle. This is called if MojoWaitMany finds an 64 // Removes the first invalid handle. This is called if MojoWaitMany finds an
63 // invalid handle. 65 // invalid handle.
64 void RemoveFirstInvalidHandle(const WaitState& wait_state); 66 void RemoveFirstInvalidHandle(const WaitState& wait_state);
65 67
66 void SignalControlPipe(); 68 void SignalControlPipe();
67 69
68 WaitState GetWaitState() const; 70 WaitState GetWaitState() const;
69 71
72 // Returns the deadline for the call to MojoWaitMany().
73 MojoDeadline GetDeadlineForWait() const;
74
70 // If non-NULL we're running (inside Run()). Member is reference to value on 75 // If non-NULL we're running (inside Run()). Member is reference to value on
71 // stack. 76 // stack.
72 RunState* run_state_; 77 RunState* run_state_;
73 78
74 HandleToHandler handlers_; 79 HandleToHandler handlers_;
75 80
81 // An ever increasing value assigned to each Handler::id. Used to detect
82 // uniqueness while notifying. That is, while notifying expired timers we copy
83 // |handlers_| and only notify handlers whose id match. If the id does not
84 // match it means the handler was removed then added so that we shouldn't
85 // notify it.
86 int next_handler_id_;
87
76 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo); 88 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo);
77 }; 89 };
78 90
79 } // namespace common 91 } // namespace common
80 } // namespace mojo 92 } // namespace mojo
81 93
82 #endif // MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ 94 #endif // MOJO_COMMON_MESSAGE_PUMP_MOJO_H_
OLDNEW
« no previous file with comments | « mojo/common/handle_watcher.cc ('k') | mojo/common/message_pump_mojo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698