Revert of Add Masonry to key_silk_cases. (patchset #3 id:40001 of https://codereview...
[chromium-blink-merge.git] / ui / wm / core / nested_accelerator_controller.cc
blobe4ace4f777ad42177cdd89605133622ec5e91f98
1 // Copyright 2014 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 #include "ui/wm/core/nested_accelerator_controller.h"
7 #include "base/auto_reset.h"
8 #include "base/bind.h"
9 #include "base/run_loop.h"
10 #include "ui/wm/core/nested_accelerator_delegate.h"
11 #include "ui/wm/core/nested_accelerator_dispatcher.h"
13 namespace wm {
15 NestedAcceleratorController::NestedAcceleratorController(
16 NestedAcceleratorDelegate* delegate)
17 : dispatcher_delegate_(delegate) {
18 DCHECK(delegate);
21 NestedAcceleratorController::~NestedAcceleratorController() {
24 void NestedAcceleratorController::PrepareNestedLoopClosures(
25 base::MessagePumpDispatcher* nested_dispatcher,
26 base::Closure* run_closure,
27 base::Closure* quit_closure) {
28 scoped_ptr<NestedAcceleratorDispatcher> old_accelerator_dispatcher =
29 accelerator_dispatcher_.Pass();
30 accelerator_dispatcher_ = NestedAcceleratorDispatcher::Create(
31 dispatcher_delegate_.get(), nested_dispatcher);
33 scoped_ptr<base::RunLoop> run_loop = accelerator_dispatcher_->CreateRunLoop();
34 *quit_closure =
35 base::Bind(&NestedAcceleratorController::QuitNestedMessageLoop,
36 base::Unretained(this),
37 run_loop->QuitClosure());
38 *run_closure = base::Bind(&NestedAcceleratorController::RunNestedMessageLoop,
39 base::Unretained(this),
40 base::Passed(&run_loop),
41 base::Passed(&old_accelerator_dispatcher));
44 void NestedAcceleratorController::RunNestedMessageLoop(
45 scoped_ptr<base::RunLoop> run_loop,
46 scoped_ptr<NestedAcceleratorDispatcher> old_accelerator_dispatcher) {
47 run_loop->Run();
48 accelerator_dispatcher_ = old_accelerator_dispatcher.Pass();
51 void NestedAcceleratorController::QuitNestedMessageLoop(
52 const base::Closure& quit_runloop) {
53 quit_runloop.Run();
54 accelerator_dispatcher_.reset();
57 } // namespace wm