Disable signin-to-Chrome when using Guest profile.
[chromium-blink-merge.git] / mojo / common / message_pump_mojo.h
blobb5b6443e3ad8dd9d15b0ac57ec38517d240de4c8
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
3 // found in the LICENSE file.
5 #ifndef MOJO_COMMON_MESSAGE_PUMP_MOJO_H_
6 #define MOJO_COMMON_MESSAGE_PUMP_MOJO_H_
8 #include <map>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_pump.h"
12 #include "base/time/time.h"
13 #include "mojo/common/mojo_common_export.h"
14 #include "mojo/public/system/core_cpp.h"
16 namespace mojo {
17 namespace common {
19 class MessagePumpMojoHandler;
21 // Mojo implementation of MessagePump.
22 class MOJO_COMMON_EXPORT MessagePumpMojo : public base::MessagePump {
23 public:
24 MessagePumpMojo();
25 virtual ~MessagePumpMojo();
27 // Static factory function (for using with |base::Thread::Options|, wrapped
28 // using |base::Bind()|).
29 static scoped_ptr<base::MessagePump> Create();
31 // Registers a MessagePumpMojoHandler for the specified handle. Only one
32 // handler can be registered for a specified handle.
33 void AddHandler(MessagePumpMojoHandler* handler,
34 const Handle& handle,
35 MojoWaitFlags wait_flags,
36 base::TimeTicks deadline);
38 void RemoveHandler(const Handle& handle);
40 // MessagePump:
41 virtual void Run(Delegate* delegate) OVERRIDE;
42 virtual void Quit() OVERRIDE;
43 virtual void ScheduleWork() OVERRIDE;
44 virtual void ScheduleDelayedWork(
45 const base::TimeTicks& delayed_work_time) OVERRIDE;
47 private:
48 struct RunState;
49 struct WaitState;
51 // Contains the data needed to track a request to AddHandler().
52 struct Handler {
53 Handler() : handler(NULL), wait_flags(MOJO_WAIT_FLAG_NONE), id(0) {}
55 MessagePumpMojoHandler* handler;
56 MojoWaitFlags wait_flags;
57 base::TimeTicks deadline;
58 // See description of |MessagePumpMojo::next_handler_id_| for details.
59 int id;
62 typedef std::map<Handle, Handler> HandleToHandler;
64 // Services the set of handles ready. If |block| is true this waits for a
65 // handle to become ready, otherwise this does not block.
66 void DoInternalWork(bool block);
68 // Removes the first invalid handle. This is called if MojoWaitMany finds an
69 // invalid handle.
70 void RemoveFirstInvalidHandle(const WaitState& wait_state);
72 void SignalControlPipe();
74 WaitState GetWaitState() const;
76 // Returns the deadline for the call to MojoWaitMany().
77 MojoDeadline GetDeadlineForWait() const;
79 // If non-NULL we're running (inside Run()). Member is reference to value on
80 // stack.
81 RunState* run_state_;
83 HandleToHandler handlers_;
85 // An ever increasing value assigned to each Handler::id. Used to detect
86 // uniqueness while notifying. That is, while notifying expired timers we copy
87 // |handlers_| and only notify handlers whose id match. If the id does not
88 // match it means the handler was removed then added so that we shouldn't
89 // notify it.
90 int next_handler_id_;
92 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo);
95 } // namespace common
96 } // namespace mojo
98 #endif // MOJO_COMMON_MESSAGE_PUMP_MOJO_H_