summaryrefslogtreecommitdiffstats
path: root/ui/wm
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-29 22:48:37 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-29 22:48:37 +0000
commit5f4bcb54da73204661a44f12c69ed06e75384d83 (patch)
treeb4df6c6a0fcdc2d5bc05059ff9ec3bc8cbbca976 /ui/wm
parent82436480cd91ef18ed391291d72704b872772ddc (diff)
downloadchromium_src-5f4bcb54da73204661a44f12c69ed06e75384d83.zip
chromium_src-5f4bcb54da73204661a44f12c69ed06e75384d83.tar.gz
chromium_src-5f4bcb54da73204661a44f12c69ed06e75384d83.tar.bz2
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
Diffstat (limited to 'ui/wm')
-rw-r--r--ui/wm/core/nested_accelerator_controller.cc33
-rw-r--r--ui/wm/core/nested_accelerator_controller.h12
-rw-r--r--ui/wm/core/nested_accelerator_controller_unittest.cc8
-rw-r--r--ui/wm/public/dispatcher_client.cc23
-rw-r--r--ui/wm/public/dispatcher_client.h33
5 files changed, 89 insertions, 20 deletions
diff --git a/ui/wm/core/nested_accelerator_controller.cc b/ui/wm/core/nested_accelerator_controller.cc
index 782ac6d..e4ace4f 100644
--- a/ui/wm/core/nested_accelerator_controller.cc
+++ b/ui/wm/core/nested_accelerator_controller.cc
@@ -5,6 +5,7 @@
#include "ui/wm/core/nested_accelerator_controller.h"
#include "base/auto_reset.h"
+#include "base/bind.h"
#include "base/run_loop.h"
#include "ui/wm/core/nested_accelerator_delegate.h"
#include "ui/wm/core/nested_accelerator_dispatcher.h"
@@ -20,28 +21,36 @@ NestedAcceleratorController::NestedAcceleratorController(
NestedAcceleratorController::~NestedAcceleratorController() {
}
-void NestedAcceleratorController::RunWithDispatcher(
- base::MessagePumpDispatcher* nested_dispatcher) {
- base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
- base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
-
+void NestedAcceleratorController::PrepareNestedLoopClosures(
+ base::MessagePumpDispatcher* nested_dispatcher,
+ base::Closure* run_closure,
+ base::Closure* quit_closure) {
scoped_ptr<NestedAcceleratorDispatcher> old_accelerator_dispatcher =
accelerator_dispatcher_.Pass();
accelerator_dispatcher_ = NestedAcceleratorDispatcher::Create(
dispatcher_delegate_.get(), nested_dispatcher);
- // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them
- // use run_loop.QuitClosure().
scoped_ptr<base::RunLoop> run_loop = accelerator_dispatcher_->CreateRunLoop();
- base::AutoReset<base::Closure> reset_closure(&quit_closure_,
- run_loop->QuitClosure());
+ *quit_closure =
+ base::Bind(&NestedAcceleratorController::QuitNestedMessageLoop,
+ base::Unretained(this),
+ run_loop->QuitClosure());
+ *run_closure = base::Bind(&NestedAcceleratorController::RunNestedMessageLoop,
+ base::Unretained(this),
+ base::Passed(&run_loop),
+ base::Passed(&old_accelerator_dispatcher));
+}
+
+void NestedAcceleratorController::RunNestedMessageLoop(
+ scoped_ptr<base::RunLoop> run_loop,
+ scoped_ptr<NestedAcceleratorDispatcher> old_accelerator_dispatcher) {
run_loop->Run();
accelerator_dispatcher_ = old_accelerator_dispatcher.Pass();
}
-void NestedAcceleratorController::QuitNestedMessageLoop() {
- CHECK(!quit_closure_.is_null());
- quit_closure_.Run();
+void NestedAcceleratorController::QuitNestedMessageLoop(
+ const base::Closure& quit_runloop) {
+ quit_runloop.Run();
accelerator_dispatcher_.reset();
}
diff --git a/ui/wm/core/nested_accelerator_controller.h b/ui/wm/core/nested_accelerator_controller.h
index 2adfcbc..2826d72e 100644
--- a/ui/wm/core/nested_accelerator_controller.h
+++ b/ui/wm/core/nested_accelerator_controller.h
@@ -26,12 +26,16 @@ class WM_EXPORT NestedAcceleratorController
virtual ~NestedAcceleratorController();
// aura::client::DispatcherClient:
- virtual void RunWithDispatcher(
- base::MessagePumpDispatcher* dispatcher) OVERRIDE;
- virtual void QuitNestedMessageLoop() OVERRIDE;
+ virtual void PrepareNestedLoopClosures(
+ base::MessagePumpDispatcher* dispatcher,
+ base::Closure* run_closure,
+ base::Closure* quit_closure) OVERRIDE;
private:
- base::Closure quit_closure_;
+ void RunNestedMessageLoop(scoped_ptr<base::RunLoop> run_loop,
+ scoped_ptr<NestedAcceleratorDispatcher> dispatcher);
+ void QuitNestedMessageLoop(const base::Closure& quit_runloop);
+
scoped_ptr<NestedAcceleratorDispatcher> accelerator_dispatcher_;
scoped_ptr<NestedAcceleratorDelegate> dispatcher_delegate_;
diff --git a/ui/wm/core/nested_accelerator_controller_unittest.cc b/ui/wm/core/nested_accelerator_controller_unittest.cc
index 996b2a4..fae9f8e 100644
--- a/ui/wm/core/nested_accelerator_controller_unittest.cc
+++ b/ui/wm/core/nested_accelerator_controller_unittest.cc
@@ -180,7 +180,9 @@ TEST_F(NestedAcceleratorTest, AssociatedWindowAboveLockScreen) {
scoped_ptr<ui::ScopedEventDispatcher> override_dispatcher =
ui::PlatformEventSource::GetInstance()->OverrideDispatcher(
&inner_dispatcher);
- aura::client::GetDispatcherClient(root_window())->RunWithDispatcher(NULL);
+ aura::client::DispatcherRunLoop run_loop(
+ aura::client::GetDispatcherClient(root_window()), NULL);
+ run_loop.Run();
EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched());
}
@@ -199,7 +201,9 @@ TEST_F(NestedAcceleratorTest, AcceleratorsHandled) {
scoped_ptr<ui::ScopedEventDispatcher> override_dispatcher =
ui::PlatformEventSource::GetInstance()->OverrideDispatcher(
&inner_dispatcher);
- aura::client::GetDispatcherClient(root_window())->RunWithDispatcher(NULL);
+ aura::client::DispatcherRunLoop run_loop(
+ aura::client::GetDispatcherClient(root_window()), NULL);
+ run_loop.Run();
EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched());
EXPECT_EQ(1, target.accelerator_pressed_count());
}
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,