Commit 0e2fa2af authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Set the global reference in WMHelper ctor

Removed WMHelper::SetInstance and simplified the code a bit.

Bug: None
AX-Relnotes: n/a.
Change-Id: I2c09d7aad7e8dce20d11cd3618da7c5d6f22a07a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285345Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786459}
parent d601e136
...@@ -42,11 +42,9 @@ class ArcInputMethodSurfaceManagerTest : public AshTestBase { ...@@ -42,11 +42,9 @@ class ArcInputMethodSurfaceManagerTest : public AshTestBase {
void SetUp() override { void SetUp() override {
AshTestBase::SetUp(); AshTestBase::SetUp();
wm_helper_ = std::make_unique<exo::WMHelperChromeOS>(); wm_helper_ = std::make_unique<exo::WMHelperChromeOS>();
exo::WMHelper::SetInstance(wm_helper_.get());
} }
void TearDown() override { void TearDown() override {
exo::WMHelper::SetInstance(nullptr);
wm_helper_.reset(); wm_helper_.reset();
AshTestBase::TearDown(); AshTestBase::TearDown();
} }
......
...@@ -126,7 +126,6 @@ class ArcNotificationContentViewTest : public AshTestBase { ...@@ -126,7 +126,6 @@ class ArcNotificationContentViewTest : public AshTestBase {
void SetUp() override { void SetUp() override {
AshTestBase::SetUp(); AshTestBase::SetUp();
wm_helper_ = std::make_unique<exo::WMHelperChromeOS>(); wm_helper_ = std::make_unique<exo::WMHelperChromeOS>();
exo::WMHelper::SetInstance(wm_helper_.get());
DCHECK(exo::WMHelper::HasInstance()); DCHECK(exo::WMHelper::HasInstance());
surface_manager_ = std::make_unique<ArcNotificationSurfaceManagerImpl>(); surface_manager_ = std::make_unique<ArcNotificationSurfaceManagerImpl>();
...@@ -150,7 +149,6 @@ class ArcNotificationContentViewTest : public AshTestBase { ...@@ -150,7 +149,6 @@ class ArcNotificationContentViewTest : public AshTestBase {
surface_manager_.reset(); surface_manager_.reset();
DCHECK(exo::WMHelper::HasInstance()); DCHECK(exo::WMHelper::HasInstance());
exo::WMHelper::SetInstance(nullptr);
wm_helper_.reset(); wm_helper_.reset();
AshTestBase::TearDown(); AshTestBase::TearDown();
......
...@@ -48,11 +48,9 @@ class ArcAccessibilityHelperBridgeBrowserTest : public InProcessBrowserTest { ...@@ -48,11 +48,9 @@ class ArcAccessibilityHelperBridgeBrowserTest : public InProcessBrowserTest {
browser()->profile()); browser()->profile());
wm_helper_ = std::make_unique<exo::WMHelperChromeOS>(); wm_helper_ = std::make_unique<exo::WMHelperChromeOS>();
exo::WMHelper::SetInstance(wm_helper_.get());
} }
void TearDownOnMainThread() override { void TearDownOnMainThread() override {
exo::WMHelper::SetInstance(nullptr);
wm_helper_.reset(); wm_helper_.reset();
ArcServiceManager::Get() ArcServiceManager::Get()
......
...@@ -59,10 +59,9 @@ class ArcPipWindowThrottleObserverTest : public testing::Test { ...@@ -59,10 +59,9 @@ class ArcPipWindowThrottleObserverTest : public testing::Test {
pip_container_ = aura::test::CreateTestWindowWithDelegate( pip_container_ = aura::test::CreateTestWindowWithDelegate(
&dummy_delegate_, ash::kShellWindowId_PipContainer, gfx::Rect(), &dummy_delegate_, ash::kShellWindowId_PipContainer, gfx::Rect(),
nullptr); nullptr);
wm_helper_ = std::make_unique<FakeWMHelper>();
wm_helper()->SetPrimaryDisplayContainer(ash::kShellWindowId_PipContainer, wm_helper()->SetPrimaryDisplayContainer(ash::kShellWindowId_PipContainer,
pip_container_); pip_container_);
exo::WMHelper::SetInstance(wm_helper());
// Set up PIP windows // Set up PIP windows
arc_window_ = aura::test::CreateTestWindowWithDelegate( arc_window_ = aura::test::CreateTestWindowWithDelegate(
&dummy_delegate_, 1, gfx::Rect(), nullptr); &dummy_delegate_, 1, gfx::Rect(), nullptr);
...@@ -74,12 +73,12 @@ class ArcPipWindowThrottleObserverTest : public testing::Test { ...@@ -74,12 +73,12 @@ class ArcPipWindowThrottleObserverTest : public testing::Test {
static_cast<int>(ash::AppType::BROWSER)); static_cast<int>(ash::AppType::BROWSER));
} }
void TearDown() override { exo::WMHelper::SetInstance(nullptr); } void TearDown() override { wm_helper_.reset(); }
protected: protected:
ArcPipWindowThrottleObserver* observer() { return &pip_observer_; } ArcPipWindowThrottleObserver* observer() { return &pip_observer_; }
FakeWMHelper* wm_helper() { return &wm_helper_; } FakeWMHelper* wm_helper() { return wm_helper_.get(); }
aura::Window* pip_container() { return pip_container_; } aura::Window* pip_container() { return pip_container_; }
...@@ -90,7 +89,7 @@ class ArcPipWindowThrottleObserverTest : public testing::Test { ...@@ -90,7 +89,7 @@ class ArcPipWindowThrottleObserverTest : public testing::Test {
public: public:
content::BrowserTaskEnvironment task_environment_; content::BrowserTaskEnvironment task_environment_;
ArcPipWindowThrottleObserver pip_observer_; ArcPipWindowThrottleObserver pip_observer_;
FakeWMHelper wm_helper_; std::unique_ptr<FakeWMHelper> wm_helper_;
aura::test::TestWindowDelegate dummy_delegate_; aura::test::TestWindowDelegate dummy_delegate_;
aura::Window* pip_container_; aura::Window* pip_container_;
aura::Window* arc_window_; aura::Window* arc_window_;
......
...@@ -36,13 +36,11 @@ class CustomTabSessionImplTest : public InProcessBrowserTest, ...@@ -36,13 +36,11 @@ class CustomTabSessionImplTest : public InProcessBrowserTest,
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
wm_helper_ = std::make_unique<exo::WMHelperChromeOS>(); wm_helper_ = std::make_unique<exo::WMHelperChromeOS>();
exo::WMHelper::SetInstance(wm_helper_.get());
DCHECK(exo::WMHelper::HasInstance()); DCHECK(exo::WMHelper::HasInstance());
} }
void TearDownOnMainThread() override { void TearDownOnMainThread() override {
DCHECK(exo::WMHelper::HasInstance()); DCHECK(exo::WMHelper::HasInstance());
exo::WMHelper::SetInstance(nullptr);
wm_helper_.reset(); wm_helper_.reset();
} }
......
...@@ -26,7 +26,6 @@ void ArcAppPerformanceTracingTestHelper::SetUp(Profile* profile) { ...@@ -26,7 +26,6 @@ void ArcAppPerformanceTracingTestHelper::SetUp(Profile* profile) {
DCHECK(IsArcAllowedForProfile(profile)); DCHECK(IsArcAllowedForProfile(profile));
profile_ = profile; profile_ = profile;
wm_helper_ = std::make_unique<exo::WMHelperChromeOS>(); wm_helper_ = std::make_unique<exo::WMHelperChromeOS>();
exo::WMHelper::SetInstance(wm_helper_.get());
// Make sure it is accessible in test. // Make sure it is accessible in test.
if (!GetTracing()) { if (!GetTracing()) {
ArcAppPerformanceTracing::GetForBrowserContextForTesting(profile_); ArcAppPerformanceTracing::GetForBrowserContextForTesting(profile_);
...@@ -36,7 +35,6 @@ void ArcAppPerformanceTracingTestHelper::SetUp(Profile* profile) { ...@@ -36,7 +35,6 @@ void ArcAppPerformanceTracingTestHelper::SetUp(Profile* profile) {
void ArcAppPerformanceTracingTestHelper::TearDown() { void ArcAppPerformanceTracingTestHelper::TearDown() {
DCHECK(profile_); DCHECK(profile_);
exo::WMHelper::SetInstance(nullptr);
wm_helper_.reset(); wm_helper_.reset();
profile_ = nullptr; profile_ = nullptr;
} }
......
...@@ -207,11 +207,9 @@ class ArcAppLauncherBrowserTest : public extensions::ExtensionBrowserTest { ...@@ -207,11 +207,9 @@ class ArcAppLauncherBrowserTest : public extensions::ExtensionBrowserTest {
// Allows creation of windows. // Allows creation of windows.
wm_helper_ = std::make_unique<exo::WMHelperChromeOS>(); wm_helper_ = std::make_unique<exo::WMHelperChromeOS>();
exo::WMHelper::SetInstance(wm_helper_.get());
} }
void TearDownOnMainThread() override { void TearDownOnMainThread() override {
exo::WMHelper::SetInstance(nullptr);
wm_helper_.reset(); wm_helper_.reset();
} }
......
...@@ -17,7 +17,6 @@ WaylandServerController::WaylandServerController( ...@@ -17,7 +17,6 @@ WaylandServerController::WaylandServerController(
CastWindowManagerAura* window_manager) { CastWindowManagerAura* window_manager) {
wm_helper_ = std::make_unique<exo::CastWMHelper>( wm_helper_ = std::make_unique<exo::CastWMHelper>(
window_manager, static_cast<CastScreen*>(CastScreen::GetScreen())); window_manager, static_cast<CastScreen*>(CastScreen::GetScreen()));
exo::WMHelper::SetInstance(wm_helper_.get());
display_ = std::make_unique<exo::Display>(); display_ = std::make_unique<exo::Display>();
wayland_server_ = exo::wayland::Server::Create(display_.get()); wayland_server_ = exo::wayland::Server::Create(display_.get());
// Wayland server creation can fail if XDG_RUNTIME_DIR is not set correctly. // Wayland server creation can fail if XDG_RUNTIME_DIR is not set correctly.
...@@ -29,12 +28,6 @@ WaylandServerController::WaylandServerController( ...@@ -29,12 +28,6 @@ WaylandServerController::WaylandServerController(
} }
} }
WaylandServerController::~WaylandServerController() { WaylandServerController::~WaylandServerController() {}
wayland_watcher_.reset();
wayland_server_.reset();
display_.reset();
exo::WMHelper::SetInstance(nullptr);
wm_helper_.reset();
}
} // namespace chromecast } // namespace chromecast
...@@ -32,24 +32,19 @@ WaylandServerController::CreateIfNecessary( ...@@ -32,24 +32,19 @@ WaylandServerController::CreateIfNecessary(
} }
WaylandServerController::~WaylandServerController() { WaylandServerController::~WaylandServerController() {
// Delete the instance in the reversed order they are created.
wayland_watcher_.reset();
wayland_server_.reset();
display_.reset();
WMHelper::SetInstance(nullptr);
wm_helper_.reset();
} }
WaylandServerController::WaylandServerController( WaylandServerController::WaylandServerController(
std::unique_ptr<FileHelper> file_helper, std::unique_ptr<FileHelper> file_helper,
std::unique_ptr<NotificationSurfaceManager> notification_surface_manager, std::unique_ptr<NotificationSurfaceManager> notification_surface_manager,
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager) std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager)
: wm_helper_(std::make_unique<WMHelperChromeOS>()) { : wm_helper_(std::make_unique<WMHelperChromeOS>()),
WMHelper::SetInstance(wm_helper_.get()); display_(
display_ = std::make_unique<Display>(std::move(notification_surface_manager), std::make_unique<Display>(std::move(notification_surface_manager),
std::move(input_method_surface_manager), std::move(input_method_surface_manager),
std::move(file_helper)); std::move(file_helper))),
wayland_server_ = wayland::Server::Create(display_.get());
wayland_server_(wayland::Server::Create(display_.get())) {
// Wayland server creation can fail if XDG_RUNTIME_DIR is not set correctly. // Wayland server creation can fail if XDG_RUNTIME_DIR is not set correctly.
if (wayland_server_) { if (wayland_server_) {
wayland_watcher_ = wayland_watcher_ =
......
...@@ -40,11 +40,9 @@ ExoTestBase::~ExoTestBase() = default; ...@@ -40,11 +40,9 @@ ExoTestBase::~ExoTestBase() = default;
void ExoTestBase::SetUp() { void ExoTestBase::SetUp() {
AshTestBase::SetUp(); AshTestBase::SetUp();
wm_helper_ = std::make_unique<WMHelperChromeOS>(); wm_helper_ = std::make_unique<WMHelperChromeOS>();
WMHelper::SetInstance(wm_helper_.get());
} }
void ExoTestBase::TearDown() { void ExoTestBase::TearDown() {
WMHelper::SetInstance(nullptr);
wm_helper_.reset(); wm_helper_.reset();
AshTestBase::TearDown(); AshTestBase::TearDown();
} }
......
...@@ -106,11 +106,9 @@ void ExoTestBaseViews::SetUp() { ...@@ -106,11 +106,9 @@ void ExoTestBaseViews::SetUp() {
views::ViewsTestBase::SetUp(); views::ViewsTestBase::SetUp();
wm_helper_ = std::make_unique<WMHelperTester>(root_window()); wm_helper_ = std::make_unique<WMHelperTester>(root_window());
WMHelper::SetInstance(wm_helper_.get());
} }
void ExoTestBaseViews::TearDown() { void ExoTestBaseViews::TearDown() {
WMHelper::SetInstance(nullptr);
wm_helper_.reset(); wm_helper_.reset();
views::ViewsTestBase::TearDown(); views::ViewsTestBase::TearDown();
......
...@@ -110,7 +110,6 @@ void WaylandClientTestHelper::SetUpOnUIThread(base::WaitableEvent* event) { ...@@ -110,7 +110,6 @@ void WaylandClientTestHelper::SetUpOnUIThread(base::WaitableEvent* event) {
ash_test_helper_->SetUp(); ash_test_helper_->SetUp();
wm_helper_ = std::make_unique<WMHelperChromeOS>(); wm_helper_ = std::make_unique<WMHelperChromeOS>();
WMHelper::SetInstance(wm_helper_.get());
display_ = std::make_unique<Display>(nullptr, nullptr, nullptr); display_ = std::make_unique<Display>(nullptr, nullptr, nullptr);
wayland_server_ = exo::wayland::Server::Create(display_.get()); wayland_server_ = exo::wayland::Server::Create(display_.get());
DCHECK(wayland_server_); DCHECK(wayland_server_);
...@@ -122,7 +121,6 @@ void WaylandClientTestHelper::TearDownOnUIThread(base::WaitableEvent* event) { ...@@ -122,7 +121,6 @@ void WaylandClientTestHelper::TearDownOnUIThread(base::WaitableEvent* event) {
wayland_watcher_.reset(); wayland_watcher_.reset();
wayland_server_.reset(); wayland_server_.reset();
display_.reset(); display_.reset();
WMHelper::SetInstance(nullptr);
wm_helper_.reset(); wm_helper_.reset();
ash::Shell::Get()->session_controller()->NotifyChromeTerminating(); ash::Shell::Get()->session_controller()->NotifyChromeTerminating();
......
...@@ -27,14 +27,14 @@ void WMHelper::LifetimeManager::RemoveObserver(Observer* observer) { ...@@ -27,14 +27,14 @@ void WMHelper::LifetimeManager::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer); observers_.RemoveObserver(observer);
} }
WMHelper::WMHelper() {} WMHelper::WMHelper() {
DCHECK(!g_instance);
WMHelper::~WMHelper() {} g_instance = this;
}
// static WMHelper::~WMHelper() {
void WMHelper::SetInstance(WMHelper* helper) { DCHECK(g_instance);
DCHECK_NE(!!helper, !!g_instance); g_instance = nullptr;
g_instance = helper;
} }
// static // static
......
...@@ -85,7 +85,6 @@ class WMHelper : public aura::client::DragDropDelegate { ...@@ -85,7 +85,6 @@ class WMHelper : public aura::client::DragDropDelegate {
WMHelper(); WMHelper();
~WMHelper() override; ~WMHelper() override;
static void SetInstance(WMHelper* helper);
static WMHelper* GetInstance(); static WMHelper* GetInstance();
static bool HasInstance(); static bool HasInstance();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment