| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/wm/core/nested_accelerator_controller.h" | 5 #include "ui/wm/core/nested_accelerator_controller.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 10 #include "ui/wm/core/nested_accelerator_delegate.h" | 12 #include "ui/wm/core/nested_accelerator_delegate.h" |
| 11 #include "ui/wm/core/nested_accelerator_dispatcher.h" | 13 #include "ui/wm/core/nested_accelerator_dispatcher.h" |
| 12 | 14 |
| 13 namespace wm { | 15 namespace wm { |
| 14 | 16 |
| 15 NestedAcceleratorController::NestedAcceleratorController( | 17 NestedAcceleratorController::NestedAcceleratorController( |
| 16 NestedAcceleratorDelegate* delegate) | 18 NestedAcceleratorDelegate* delegate) |
| 17 : dispatcher_delegate_(delegate) { | 19 : dispatcher_delegate_(delegate) { |
| 18 DCHECK(delegate); | 20 DCHECK(delegate); |
| 19 } | 21 } |
| 20 | 22 |
| 21 NestedAcceleratorController::~NestedAcceleratorController() { | 23 NestedAcceleratorController::~NestedAcceleratorController() { |
| 22 } | 24 } |
| 23 | 25 |
| 24 void NestedAcceleratorController::PrepareNestedLoopClosures( | 26 void NestedAcceleratorController::PrepareNestedLoopClosures( |
| 25 base::MessagePumpDispatcher* nested_dispatcher, | 27 base::MessagePumpDispatcher* nested_dispatcher, |
| 26 base::Closure* run_closure, | 28 base::Closure* run_closure, |
| 27 base::Closure* quit_closure) { | 29 base::Closure* quit_closure) { |
| 28 scoped_ptr<NestedAcceleratorDispatcher> old_accelerator_dispatcher = | 30 scoped_ptr<NestedAcceleratorDispatcher> old_accelerator_dispatcher = |
| 29 accelerator_dispatcher_.Pass(); | 31 std::move(accelerator_dispatcher_); |
| 30 accelerator_dispatcher_ = NestedAcceleratorDispatcher::Create( | 32 accelerator_dispatcher_ = NestedAcceleratorDispatcher::Create( |
| 31 dispatcher_delegate_.get(), nested_dispatcher); | 33 dispatcher_delegate_.get(), nested_dispatcher); |
| 32 | 34 |
| 33 scoped_ptr<base::RunLoop> run_loop = accelerator_dispatcher_->CreateRunLoop(); | 35 scoped_ptr<base::RunLoop> run_loop = accelerator_dispatcher_->CreateRunLoop(); |
| 34 *quit_closure = | 36 *quit_closure = |
| 35 base::Bind(&NestedAcceleratorController::QuitNestedMessageLoop, | 37 base::Bind(&NestedAcceleratorController::QuitNestedMessageLoop, |
| 36 base::Unretained(this), | 38 base::Unretained(this), |
| 37 run_loop->QuitClosure()); | 39 run_loop->QuitClosure()); |
| 38 *run_closure = base::Bind(&NestedAcceleratorController::RunNestedMessageLoop, | 40 *run_closure = base::Bind(&NestedAcceleratorController::RunNestedMessageLoop, |
| 39 base::Unretained(this), | 41 base::Unretained(this), |
| 40 base::Passed(&run_loop), | 42 base::Passed(&run_loop), |
| 41 base::Passed(&old_accelerator_dispatcher)); | 43 base::Passed(&old_accelerator_dispatcher)); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void NestedAcceleratorController::RunNestedMessageLoop( | 46 void NestedAcceleratorController::RunNestedMessageLoop( |
| 45 scoped_ptr<base::RunLoop> run_loop, | 47 scoped_ptr<base::RunLoop> run_loop, |
| 46 scoped_ptr<NestedAcceleratorDispatcher> old_accelerator_dispatcher) { | 48 scoped_ptr<NestedAcceleratorDispatcher> old_accelerator_dispatcher) { |
| 47 run_loop->Run(); | 49 run_loop->Run(); |
| 48 accelerator_dispatcher_ = old_accelerator_dispatcher.Pass(); | 50 accelerator_dispatcher_ = std::move(old_accelerator_dispatcher); |
| 49 } | 51 } |
| 50 | 52 |
| 51 void NestedAcceleratorController::QuitNestedMessageLoop( | 53 void NestedAcceleratorController::QuitNestedMessageLoop( |
| 52 const base::Closure& quit_runloop) { | 54 const base::Closure& quit_runloop) { |
| 53 quit_runloop.Run(); | 55 quit_runloop.Run(); |
| 54 accelerator_dispatcher_.reset(); | 56 accelerator_dispatcher_.reset(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 } // namespace wm | 59 } // namespace wm |
| OLD | NEW |