OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/widget/desktop_aura/desktop_dispatcher_client.h" | 5 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" |
8 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
9 | 10 |
10 namespace views { | 11 namespace views { |
11 | 12 |
12 DesktopDispatcherClient::DesktopDispatcherClient() | 13 DesktopDispatcherClient::DesktopDispatcherClient() { |
13 : weak_ptr_factory_(this) {} | 14 } |
14 | 15 |
15 DesktopDispatcherClient::~DesktopDispatcherClient() { | 16 DesktopDispatcherClient::~DesktopDispatcherClient() { |
16 } | 17 } |
17 | 18 |
18 void DesktopDispatcherClient::RunWithDispatcher( | 19 void DesktopDispatcherClient::PrepareNestedLoopClosures( |
19 base::MessagePumpDispatcher* nested_dispatcher) { | 20 base::MessagePumpDispatcher* dispatcher, |
20 // TODO(erg): This class has been copypastad from | 21 base::Closure* run_closure, |
21 // ash/accelerators/nested_dispatcher_controller.cc. I have left my changes | 22 base::Closure* quit_closure) { |
22 // commented out because I don't entirely understand the implications of the | |
23 // change. | |
24 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | |
25 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); | |
26 | |
27 base::Closure old_quit_closure = quit_closure_; | |
28 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
29 base::RunLoop run_loop(nested_dispatcher); | 24 scoped_ptr<base::RunLoop> run_loop(new base::RunLoop(dispatcher)); |
30 #else | 25 #else |
31 base::RunLoop run_loop; | 26 scoped_ptr<base::RunLoop> run_loop(new base::RunLoop()); |
32 #endif | 27 #endif |
33 | 28 *quit_closure = run_loop->QuitClosure(); |
34 quit_closure_ = run_loop.QuitClosure(); | 29 *run_closure = |
35 base::WeakPtr<DesktopDispatcherClient> alive(weak_ptr_factory_.GetWeakPtr()); | 30 base::Bind(&base::RunLoop::Run, base::Owned(run_loop.release())); |
36 run_loop.Run(); | |
37 if (alive) { | |
38 weak_ptr_factory_.InvalidateWeakPtrs(); | |
39 quit_closure_ = old_quit_closure; | |
40 } | |
41 } | |
42 | |
43 void DesktopDispatcherClient::QuitNestedMessageLoop() { | |
44 CHECK(!quit_closure_.is_null()); | |
45 quit_closure_.Run(); | |
46 } | 31 } |
47 | 32 |
48 } // namespace views | 33 } // namespace views |
OLD | NEW |