Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/mus/views_mus_test_suite.h" | 5 #include "ui/views/mus/views_mus_test_suite.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 if (!WindowManagerConnection::Exists()) | 60 if (!WindowManagerConnection::Exists()) |
| 61 WindowManagerConnection::Create(connector, identity); | 61 WindowManagerConnection::Create(connector, identity); |
| 62 return base::WrapUnique(new PlatformTestHelperMus); | 62 return base::WrapUnique(new PlatformTestHelperMus); |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 class ShellConnection { | 67 class ShellConnection { |
| 68 public: | 68 public: |
| 69 ShellConnection() : thread_("Persistent shell connections") { | 69 ShellConnection() : thread_("Persistent shell connections") { |
| 70 base::WaitableEvent wait(false, false); | 70 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
|
sky
2016/06/01 19:18:35
Did you consider making WaitableEvent take a bitma
gab
2016/06/01 19:50:30
Copied your suggestion on bug, danakj prefers the
| |
| 71 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
| 71 base::Thread::Options options; | 72 base::Thread::Options options; |
| 72 thread_.StartWithOptions(options); | 73 thread_.StartWithOptions(options); |
| 73 thread_.task_runner()->PostTask( | 74 thread_.task_runner()->PostTask( |
| 74 FROM_HERE, base::Bind(&ShellConnection::SetUpConnections, | 75 FROM_HERE, base::Bind(&ShellConnection::SetUpConnections, |
| 75 base::Unretained(this), &wait)); | 76 base::Unretained(this), &wait)); |
| 76 wait.Wait(); | 77 wait.Wait(); |
| 77 | 78 |
| 78 // WindowManagerConnection cannot be created from here yet, although the | 79 // WindowManagerConnection cannot be created from here yet, although the |
| 79 // connector and identity are available at this point. This is because | 80 // connector and identity are available at this point. This is because |
| 80 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have | 81 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have |
| 81 // been installed first. So delay the creation until the necessary | 82 // been installed first. So delay the creation until the necessary |
| 82 // dependencies have been met. | 83 // dependencies have been met. |
| 83 PlatformTestHelper::set_factory(base::Bind( | 84 PlatformTestHelper::set_factory(base::Bind( |
| 84 &CreatePlatformTestHelper, shell_connector_.get(), shell_identity_)); | 85 &CreatePlatformTestHelper, shell_connector_.get(), shell_identity_)); |
| 85 } | 86 } |
| 86 | 87 |
| 87 ~ShellConnection() { | 88 ~ShellConnection() { |
| 88 if (views::WindowManagerConnection::Exists()) | 89 if (views::WindowManagerConnection::Exists()) |
| 89 views::WindowManagerConnection::Reset(); | 90 views::WindowManagerConnection::Reset(); |
| 90 base::WaitableEvent wait(false, false); | 91 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 92 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
| 91 thread_.task_runner()->PostTask( | 93 thread_.task_runner()->PostTask( |
| 92 FROM_HERE, base::Bind(&ShellConnection::TearDownConnections, | 94 FROM_HERE, base::Bind(&ShellConnection::TearDownConnections, |
| 93 base::Unretained(this), &wait)); | 95 base::Unretained(this), &wait)); |
| 94 wait.Wait(); | 96 wait.Wait(); |
| 95 } | 97 } |
| 96 | 98 |
| 97 private: | 99 private: |
| 98 void SetUpConnections(base::WaitableEvent* wait) { | 100 void SetUpConnections(base::WaitableEvent* wait) { |
| 99 background_shell_.reset(new shell::BackgroundShell); | 101 background_shell_.reset(new shell::BackgroundShell); |
| 100 background_shell_->Init(nullptr); | 102 background_shell_->Init(nullptr); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 ViewsTestSuite::Initialize(); | 152 ViewsTestSuite::Initialize(); |
| 151 shell_connections_.reset(new ShellConnection); | 153 shell_connections_.reset(new ShellConnection); |
| 152 } | 154 } |
| 153 | 155 |
| 154 void ViewsMusTestSuite::Shutdown() { | 156 void ViewsMusTestSuite::Shutdown() { |
| 155 shell_connections_.reset(); | 157 shell_connections_.reset(); |
| 156 ViewsTestSuite::Shutdown(); | 158 ViewsTestSuite::Shutdown(); |
| 157 } | 159 } |
| 158 | 160 |
| 159 } // namespace views | 161 } // namespace views |
| OLD | NEW |