From 5f4bcb54da73204661a44f12c69ed06e75384d83 Mon Sep 17 00:00:00 2001 From: "sadrul@chromium.org" Date: Thu, 29 May 2014 22:48:37 +0000 Subject: wm: Change the DispatcherClient interface. Instead of having RunWithDispatcher() to start a nested message-loop, and a corresponding QuitNestedMessageLoop() to terminate it, have a DispatcherRunLoop object that is similar to base::RunLoop for starting a nested message loop for a specified DispatcherClient. BUG=none R=sky@chromium.org Review URL: https://codereview.chromium.org/280483003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273634 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/wm/public/dispatcher_client.cc | 23 +++++++++++++++++++++++ ui/wm/public/dispatcher_client.h | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) (limited to 'ui/wm/public') diff --git a/ui/wm/public/dispatcher_client.cc b/ui/wm/public/dispatcher_client.cc index cec4a8a..e3be7ca 100644 --- a/ui/wm/public/dispatcher_client.cc +++ b/ui/wm/public/dispatcher_client.cc @@ -4,6 +4,7 @@ #include "ui/wm/public/dispatcher_client.h" +#include "base/callback.h" #include "ui/aura/window.h" #include "ui/aura/window_property.h" @@ -12,6 +13,28 @@ DECLARE_WINDOW_PROPERTY_TYPE(aura::client::DispatcherClient*); namespace aura { namespace client { +DispatcherRunLoop::DispatcherRunLoop(DispatcherClient* client, + base::MessagePumpDispatcher* dispatcher) { + client->PrepareNestedLoopClosures(dispatcher, &run_closure_, &quit_closure_); +} + +DispatcherRunLoop::~DispatcherRunLoop() { +} + +void DispatcherRunLoop::Run() { + base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); + base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); + run_closure_.Run(); +} + +base::Closure DispatcherRunLoop::QuitClosure() { + return quit_closure_; +} + +void DispatcherRunLoop::Quit() { + quit_closure_.Run(); +} + DEFINE_LOCAL_WINDOW_PROPERTY_KEY(DispatcherClient*, kDispatcherClientKey, NULL); void SetDispatcherClient(Window* root_window, DispatcherClient* client) { diff --git a/ui/wm/public/dispatcher_client.h b/ui/wm/public/dispatcher_client.h index 9fd9c94..a301e92 100644 --- a/ui/wm/public/dispatcher_client.h +++ b/ui/wm/public/dispatcher_client.h @@ -5,6 +5,8 @@ #ifndef UI_WM_PUBLIC_DISPATCHER_CLIENT_H_ #define UI_WM_PUBLIC_DISPATCHER_CLIENT_H_ +#include "base/callback.h" +#include "base/macros.h" #include "base/message_loop/message_pump_dispatcher.h" #include "ui/aura/aura_export.h" @@ -12,12 +14,39 @@ namespace aura { class Window; namespace client { +class DispatcherClient; + +// A base::RunLoop like object for running a nested message-loop with a +// specified DispatcherClient and a MessagePumpDispatcher. +class AURA_EXPORT DispatcherRunLoop { + public: + DispatcherRunLoop(DispatcherClient* client, + base::MessagePumpDispatcher* dispatcher); + ~DispatcherRunLoop(); + + void Run(); + base::Closure QuitClosure(); + void Quit(); + + private: + base::Closure run_closure_; + base::Closure quit_closure_; + + DISALLOW_COPY_AND_ASSIGN(DispatcherRunLoop); +}; + // An interface implemented by an object which handles nested dispatchers. class AURA_EXPORT DispatcherClient { public: - virtual void RunWithDispatcher(base::MessagePumpDispatcher* dispatcher) = 0; + virtual ~DispatcherClient() {} + + protected: + friend class DispatcherRunLoop; - virtual void QuitNestedMessageLoop() = 0; + virtual void PrepareNestedLoopClosures( + base::MessagePumpDispatcher* dispatcher, + base::Closure* run_closure, + base::Closure* quit_closure) = 0; }; AURA_EXPORT void SetDispatcherClient(Window* root_window, -- cgit v1.1