OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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. |
| 4 |
| 5 #include "wm/foreign_test_window.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" |
| 9 #include "base/run_loop.h" |
| 10 #include "base/threading/thread.h" |
| 11 #include "ui/aura/env.h" |
| 12 #include "wm/host/foreign_test_window_host.h" |
| 13 |
| 14 namespace wm { |
| 15 |
| 16 namespace { |
| 17 |
| 18 const char kForeignTestWindowThreadName[] = "ForeignTestWindowThread"; |
| 19 |
| 20 class ForeignTestWindowThread : public base::Thread { |
| 21 public: |
| 22 ForeignTestWindowThread() : base::Thread(kForeignTestWindowThreadName) { |
| 23 base::Thread::Options options; |
| 24 options.message_loop_type = MessageLoop::TYPE_IO; |
| 25 StartWithOptions(options); |
| 26 } |
| 27 virtual ~ForeignTestWindowThread() { |
| 28 Stop(); |
| 29 } |
| 30 |
| 31 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(ForeignTestWindowThread); |
| 33 }; |
| 34 |
| 35 base::LazyInstance<ForeignTestWindowThread> g_foreign_test_window_thread = |
| 36 LAZY_INSTANCE_INITIALIZER; |
| 37 |
| 38 void InitializeOnIO(ForeignTestWindowHost* host) { |
| 39 host->Initialize(); |
| 40 } |
| 41 |
| 42 void DeleteOnIO(ForeignTestWindowHost* host) { |
| 43 host->Delete(); |
| 44 } |
| 45 |
| 46 void ShowOnIO(ForeignTestWindowHost* host) { |
| 47 host->Show(); |
| 48 } |
| 49 |
| 50 void HideOnIO(ForeignTestWindowHost* host) { |
| 51 host->Hide(); |
| 52 } |
| 53 |
| 54 void DestroyOnIO(ForeignTestWindowHost* host) { |
| 55 host->Destroy(); |
| 56 } |
| 57 |
| 58 void SyncOnIO(ForeignTestWindowHost* host) { |
| 59 host->Sync(); |
| 60 } |
| 61 |
| 62 void SyncCompleted(base::RunLoop* run_loop) { |
| 63 run_loop->Quit(); |
| 64 } |
| 65 |
| 66 } // namespace |
| 67 |
| 68 ForeignTestWindow::CreateParams::CreateParams(aura::RootWindow* root_window) |
| 69 : root_window(root_window) { |
| 70 } |
| 71 |
| 72 ForeignTestWindow::ForeignTestWindow(const CreateParams& params) { |
| 73 host_ = ForeignTestWindowHost::Create(params.root_window); |
| 74 g_foreign_test_window_thread.Pointer()->message_loop_proxy()->PostTask( |
| 75 FROM_HERE, |
| 76 base::Bind(&InitializeOnIO, host_)); |
| 77 } |
| 78 |
| 79 ForeignTestWindow::~ForeignTestWindow() { |
| 80 g_foreign_test_window_thread.Pointer()->message_loop_proxy()->PostTask( |
| 81 FROM_HERE, |
| 82 base::Bind(&DeleteOnIO, host_)); |
| 83 } |
| 84 |
| 85 void ForeignTestWindow::Show() { |
| 86 g_foreign_test_window_thread.Pointer()->message_loop_proxy()->PostTask( |
| 87 FROM_HERE, |
| 88 base::Bind(&ShowOnIO, host_)); |
| 89 } |
| 90 |
| 91 void ForeignTestWindow::Hide() { |
| 92 g_foreign_test_window_thread.Pointer()->message_loop_proxy()->PostTask( |
| 93 FROM_HERE, |
| 94 base::Bind(&HideOnIO, host_)); |
| 95 } |
| 96 |
| 97 void ForeignTestWindow::Destroy() { |
| 98 g_foreign_test_window_thread.Pointer()->message_loop_proxy()->PostTask( |
| 99 FROM_HERE, |
| 100 base::Bind(&DestroyOnIO, host_)); |
| 101 } |
| 102 |
| 103 void ForeignTestWindow::Sync() { |
| 104 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); |
| 105 g_foreign_test_window_thread.Pointer()->message_loop_proxy()-> |
| 106 PostTaskAndReply(FROM_HERE, |
| 107 base::Bind(&SyncOnIO, host_), |
| 108 base::Bind(&SyncCompleted, |
| 109 base::Unretained(&run_loop))); |
| 110 run_loop.Run(); |
| 111 } |
| 112 |
| 113 } // namespace wm |
OLD | NEW |