diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-12 16:35:02 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-12 16:35:02 +0000 |
commit | 3fee57b39da2e99e44d65021263d057a7b239683 (patch) | |
tree | 06f7887456a61bc27f04a2a1965925ef3713c76e /mojo/common/message_pump_mojo.h | |
parent | 660e19c045e1cd43fe64f0adb8caf678143a461b (diff) | |
download | chromium_src-3fee57b39da2e99e44d65021263d057a7b239683.zip chromium_src-3fee57b39da2e99e44d65021263d057a7b239683.tar.gz chromium_src-3fee57b39da2e99e44d65021263d057a7b239683.tar.bz2 |
Implementation of MessagePump for Mojo.
I've refactored a bunch of the common MessagePump code into
message_pump_test. This allows us to share tests for custom
messagePumps and should allow moving MessagePumpForUI out later
on. Sadly it results in a ginormous macro. On the positive side it's
easy to use.
BUG=none
TEST=none
R=darin@chromium.org
Review URL: https://codereview.chromium.org/66193007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234540 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/common/message_pump_mojo.h')
-rw-r--r-- | mojo/common/message_pump_mojo.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/mojo/common/message_pump_mojo.h b/mojo/common/message_pump_mojo.h new file mode 100644 index 0000000..4eba660 --- /dev/null +++ b/mojo/common/message_pump_mojo.h @@ -0,0 +1,82 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ +#define MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ + +#include <map> + +#include "base/message_loop/message_pump.h" +#include "mojo/common/mojo_common_export.h" +#include "mojo/public/system/core.h" + +namespace mojo { +namespace common { + +class MessagePumpMojoHandler; + +// Mojo implementation of MessagePump. +class MOJO_COMMON_EXPORT MessagePumpMojo : public base::MessagePump { + public: + MessagePumpMojo(); + virtual ~MessagePumpMojo(); + + // Registers a MessagePumpMojoHandler for the specified handle. Only one + // handler can be registered for a specified handle. If there is an existing + // handler registered it is clobbered and silently removed. + // The handler is notified either when the handle is ready, or when it becomes + // invalid. If the handle becomes invalid the handler is removed and notified. + void AddHandler(MessagePumpMojoHandler* handler, + MojoHandle handle, + MojoWaitFlags wait_flags); + + void RemoveHandler(MojoHandle handle); + + // MessagePump: + virtual void Run(Delegate* delegate) OVERRIDE; + virtual void Quit() OVERRIDE; + virtual void ScheduleWork() OVERRIDE; + virtual void ScheduleDelayedWork( + const base::TimeTicks& delayed_work_time) OVERRIDE; + + private: + struct RunState; + struct WaitState; + + // Creates a MessagePumpMojoHandler and the set of MojoWaitFlags it was + // registered with. + struct Handler { + Handler() : handler(NULL), wait_flags(MOJO_WAIT_FLAG_NONE) {} + + MessagePumpMojoHandler* handler; + MojoWaitFlags wait_flags; + }; + + typedef std::map<MojoHandle, Handler> HandleToHandler; + + // Services the set of handles ready. If |block| is true this waits for a + // handle to become ready, otherwise this does not block. + void DoInternalWork(bool block); + + // Removes the first invalid handle. This is called if MojoWaitMany finds an + // invalid handle. + void RemoveFirstInvalidHandle(const WaitState& wait_state); + + void SignalControlPipe(); + + WaitState GetWaitState() const; + + // If non-NULL we're running (inside Run()). Member is reference to value on + // stack. + RunState* run_state_; + + HandleToHandler handlers_; + + DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo); +}; + +} // namespace common +} // namespace mojo + +#endif // MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ |