Commit a5245ad5 authored by James Cook's avatar James Cook Committed by Commit Bot

Convert aura::Env::GetInstanceDontCreate to aura::Env::HasInstance

The existing aura::Env::GetInstance() doesn't create anything. Most
callers were using GetInstanceDontCreate() to mean HasInstance(), so
rename the method.

This makes it easier to write presubmits for aura::Env::GetInstance().

Bug: none
Test: bots
Change-Id: I0c606df7c8e439579d4ae39fa11dd119b610cb77
Reviewed-on: https://chromium-review.googlesource.com/1173473Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582906}
parent 4b16517a
...@@ -12,7 +12,7 @@ namespace keyboard_shortcut_viewer { ...@@ -12,7 +12,7 @@ namespace keyboard_shortcut_viewer {
LastWindowClosedObserver::LastWindowClosedObserver( LastWindowClosedObserver::LastWindowClosedObserver(
const base::RepeatingClosure& callback) const base::RepeatingClosure& callback)
: callback_(callback) { : callback_(callback) {
env_observer_.Add(aura::Env::GetInstanceDontCreate()); env_observer_.Add(aura::Env::GetInstance());
} }
LastWindowClosedObserver::~LastWindowClosedObserver() = default; LastWindowClosedObserver::~LastWindowClosedObserver() = default;
......
...@@ -237,12 +237,10 @@ void ExecuteScriptWaitForTitle(content::WebContents* web_contents, ...@@ -237,12 +237,10 @@ void ExecuteScriptWaitForTitle(content::WebContents* web_contents,
class SelectControlWaiter : public aura::WindowObserver, class SelectControlWaiter : public aura::WindowObserver,
public aura::EnvObserver { public aura::EnvObserver {
public: public:
SelectControlWaiter() { SelectControlWaiter() { aura::Env::GetInstance()->AddObserver(this); }
aura::Env::GetInstanceDontCreate()->AddObserver(this);
}
~SelectControlWaiter() override { ~SelectControlWaiter() override {
aura::Env::GetInstanceDontCreate()->RemoveObserver(this); aura::Env::GetInstance()->RemoveObserver(this);
} }
void Wait(bool wait_for_widget_shown) { void Wait(bool wait_for_widget_shown) {
......
...@@ -49,14 +49,15 @@ gfx::PointF GetScreenLocationFromEvent(const ui::LocatedEvent& event) { ...@@ -49,14 +49,15 @@ gfx::PointF GetScreenLocationFromEvent(const ui::LocatedEvent& event) {
const ui::KeyboardCode kSpeakSelectionKey = ui::VKEY_S; const ui::KeyboardCode kSpeakSelectionKey = ui::VKEY_S;
SelectToSpeakEventHandler::SelectToSpeakEventHandler() { SelectToSpeakEventHandler::SelectToSpeakEventHandler() {
if (aura::Env::GetInstanceDontCreate()) if (aura::Env::HasInstance()) {
aura::Env::GetInstanceDontCreate()->AddPreTargetHandler( aura::Env::GetInstance()->AddPreTargetHandler(
this, ui::EventTarget::Priority::kAccessibility); this, ui::EventTarget::Priority::kAccessibility);
}
} }
SelectToSpeakEventHandler::~SelectToSpeakEventHandler() { SelectToSpeakEventHandler::~SelectToSpeakEventHandler() {
if (aura::Env::GetInstanceDontCreate()) if (aura::Env::HasInstance())
aura::Env::GetInstanceDontCreate()->RemovePreTargetHandler(this); aura::Env::GetInstance()->RemovePreTargetHandler(this);
} }
void SelectToSpeakEventHandler::SetSelectToSpeakStateSelecting( void SelectToSpeakEventHandler::SetSelectToSpeakStateSelecting(
......
// Copyright 2016 The Chromium Authors. All rights reserved. // Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
#include <string> #include <string>
...@@ -431,9 +432,8 @@ void ArcAppWindowLauncherController::OnWindowActivated( ...@@ -431,9 +432,8 @@ void ArcAppWindowLauncherController::OnWindowActivated(
} }
void ArcAppWindowLauncherController::StartObserving(Profile* profile) { void ArcAppWindowLauncherController::StartObserving(Profile* profile) {
aura::Env* env = aura::Env::GetInstanceDontCreate(); if (aura::Env::HasInstance())
if (env) aura::Env::GetInstance()->AddObserver(this);
env->AddObserver(this);
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile);
DCHECK(prefs); DCHECK(prefs);
prefs->AddObserver(this); prefs->AddObserver(this);
...@@ -444,9 +444,8 @@ void ArcAppWindowLauncherController::StopObserving(Profile* profile) { ...@@ -444,9 +444,8 @@ void ArcAppWindowLauncherController::StopObserving(Profile* profile) {
window->RemoveObserver(this); window->RemoveObserver(this);
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile);
prefs->RemoveObserver(this); prefs->RemoveObserver(this);
aura::Env* env = aura::Env::GetInstanceDontCreate(); if (aura::Env::HasInstance())
if (env) aura::Env::GetInstance()->RemoveObserver(this);
env->RemoveObserver(this);
} }
ArcAppWindowLauncherItemController* ArcAppWindowLauncherItemController*
......
...@@ -63,17 +63,15 @@ void MoveWindowFromOldDisplayToNewDisplay(aura::Window* window, ...@@ -63,17 +63,15 @@ void MoveWindowFromOldDisplayToNewDisplay(aura::Window* window,
CrostiniAppWindowShelfController::CrostiniAppWindowShelfController( CrostiniAppWindowShelfController::CrostiniAppWindowShelfController(
ChromeLauncherController* owner) ChromeLauncherController* owner)
: AppWindowLauncherController(owner) { : AppWindowLauncherController(owner) {
aura::Env* env = aura::Env::GetInstanceDontCreate(); if (aura::Env::HasInstance())
if (env) aura::Env::GetInstance()->AddObserver(this);
env->AddObserver(this);
} }
CrostiniAppWindowShelfController::~CrostiniAppWindowShelfController() { CrostiniAppWindowShelfController::~CrostiniAppWindowShelfController() {
for (auto* window : observed_windows_) for (auto* window : observed_windows_)
window->RemoveObserver(this); window->RemoveObserver(this);
aura::Env* env = aura::Env::GetInstanceDontCreate(); if (aura::Env::HasInstance())
if (env) aura::Env::GetInstance()->RemoveObserver(this);
env->RemoveObserver(this);
} }
void CrostiniAppWindowShelfController::AddToShelf(aura::Window* window, void CrostiniAppWindowShelfController::AddToShelf(aura::Window* window,
......
...@@ -21,18 +21,16 @@ ...@@ -21,18 +21,16 @@
InternalAppWindowShelfController::InternalAppWindowShelfController( InternalAppWindowShelfController::InternalAppWindowShelfController(
ChromeLauncherController* owner) ChromeLauncherController* owner)
: AppWindowLauncherController(owner) { : AppWindowLauncherController(owner) {
aura::Env* env = aura::Env::GetInstanceDontCreate(); if (aura::Env::HasInstance())
if (env) aura::Env::GetInstance()->AddObserver(this);
env->AddObserver(this);
} }
InternalAppWindowShelfController::~InternalAppWindowShelfController() { InternalAppWindowShelfController::~InternalAppWindowShelfController() {
for (auto* window : observed_windows_) for (auto* window : observed_windows_)
window->RemoveObserver(this); window->RemoveObserver(this);
aura::Env* env = aura::Env::GetInstanceDontCreate(); if (aura::Env::HasInstance())
if (env) aura::Env::GetInstance()->RemoveObserver(this);
env->RemoveObserver(this);
} }
void InternalAppWindowShelfController::OnWindowInitialized( void InternalAppWindowShelfController::OnWindowInitialized(
......
...@@ -119,9 +119,8 @@ ArcImeService::ArcImeService(content::BrowserContext* context, ...@@ -119,9 +119,8 @@ ArcImeService::ArcImeService(content::BrowserContext* context,
ime_type_(ui::TEXT_INPUT_TYPE_NONE), ime_type_(ui::TEXT_INPUT_TYPE_NONE),
is_personalized_learning_allowed_(false), is_personalized_learning_allowed_(false),
has_composition_text_(false) { has_composition_text_(false) {
aura::Env* env = aura::Env::GetInstanceDontCreate(); if (aura::Env::HasInstance())
if (env) aura::Env::GetInstance()->AddObserver(this);
env->AddObserver(this);
arc_window_delegate_->RegisterFocusObserver(); arc_window_delegate_->RegisterFocusObserver();
} }
...@@ -133,9 +132,8 @@ ArcImeService::~ArcImeService() { ...@@ -133,9 +132,8 @@ ArcImeService::~ArcImeService() {
if (focused_arc_window_) if (focused_arc_window_)
focused_arc_window_->RemoveObserver(this); focused_arc_window_->RemoveObserver(this);
arc_window_delegate_->UnregisterFocusObserver(); arc_window_delegate_->UnregisterFocusObserver();
aura::Env* env = aura::Env::GetInstanceDontCreate(); if (aura::Env::HasInstance())
if (env) aura::Env::GetInstance()->RemoveObserver(this);
env->RemoveObserver(this);
// KeyboardController is destroyed before ArcImeService (except in tests), // KeyboardController is destroyed before ArcImeService (except in tests),
// so check whether there is a KeyboardController first before removing |this| // so check whether there is a KeyboardController first before removing |this|
......
...@@ -298,7 +298,7 @@ class ServiceBinaryLauncherFactory ...@@ -298,7 +298,7 @@ class ServiceBinaryLauncherFactory
bool ShouldEnableVizService() { bool ShouldEnableVizService() {
#if defined(USE_AURA) #if defined(USE_AURA)
// aura::Env can be null in tests. // aura::Env can be null in tests.
return aura::Env::GetInstanceDontCreate() && return aura::Env::HasInstance() &&
aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS; aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS;
#else #else
return false; return false;
......
...@@ -729,7 +729,7 @@ gfx::Rect WebContentsViewAura::GetViewBounds() const { ...@@ -729,7 +729,7 @@ gfx::Rect WebContentsViewAura::GetViewBounds() const {
} }
void WebContentsViewAura::CreateAuraWindow(aura::Window* context) { void WebContentsViewAura::CreateAuraWindow(aura::Window* context) {
DCHECK(aura::Env::GetInstanceDontCreate()); DCHECK(aura::Env::HasInstance());
DCHECK(!window_); DCHECK(!window_);
window_ = std::make_unique<aura::Window>(this); window_ = std::make_unique<aura::Window>(this);
window_->set_owned_by_parent(false); window_->set_owned_by_parent(false);
......
...@@ -100,8 +100,8 @@ Env* Env::GetInstance() { ...@@ -100,8 +100,8 @@ Env* Env::GetInstance() {
} }
// static // static
Env* Env::GetInstanceDontCreate() { bool Env::HasInstance() {
return g_primary_instance; return !!g_primary_instance;
} }
std::unique_ptr<WindowPort> Env::CreateWindowPort(Window* window) { std::unique_ptr<WindowPort> Env::CreateWindowPort(Window* window) {
......
...@@ -100,7 +100,7 @@ class AURA_EXPORT Env : public ui::EventTarget, ...@@ -100,7 +100,7 @@ class AURA_EXPORT Env : public ui::EventTarget,
// returned by GetInstance()) *and* an instance is created via // returned by GetInstance()) *and* an instance is created via
// CreateLocalInstanceForInProcess(). // CreateLocalInstanceForInProcess().
static Env* GetInstance(); static Env* GetInstance();
static Env* GetInstanceDontCreate(); static bool HasInstance();
Mode mode() const { return mode_; } Mode mode() const { return mode_; }
......
...@@ -93,8 +93,7 @@ void AuraTestHelper::SetUp(ui::ContextFactory* context_factory, ...@@ -93,8 +93,7 @@ void AuraTestHelper::SetUp(ui::ContextFactory* context_factory,
ui::ContextFactoryPrivate* context_factory_private) { ui::ContextFactoryPrivate* context_factory_private) {
// If Env has been configured with MUS, but |mode_| is still |LOCAL|, switch // If Env has been configured with MUS, but |mode_| is still |LOCAL|, switch
// to MUS. This is used for tests suites that setup Env globally. // to MUS. This is used for tests suites that setup Env globally.
if (Env::GetInstanceDontCreate() && if (Env::HasInstance() && Env::GetInstance()->mode() == Env::Mode::MUS &&
Env::GetInstanceDontCreate()->mode() == Env::Mode::MUS &&
mode_ == Mode::LOCAL) { mode_ == Mode::LOCAL) {
test_window_tree_client_delegate_ = test_window_tree_client_delegate_ =
std::make_unique<TestWindowTreeClientDelegate>(); std::make_unique<TestWindowTreeClientDelegate>();
...@@ -117,7 +116,7 @@ void AuraTestHelper::SetUp(ui::ContextFactory* context_factory, ...@@ -117,7 +116,7 @@ void AuraTestHelper::SetUp(ui::ContextFactory* context_factory,
if (mode_ == Mode::MUS_CREATE_WINDOW_TREE_CLIENT) if (mode_ == Mode::MUS_CREATE_WINDOW_TREE_CLIENT)
InitWindowTreeClient(); InitWindowTreeClient();
if (Env::GetInstanceDontCreate()) { if (Env::HasInstance()) {
// Some tests suites create Env globally rather than per test. In this case // Some tests suites create Env globally rather than per test. In this case
// make sure Env is configured with the right mode. // make sure Env is configured with the right mode.
env_mode_to_restore_ = Env::GetInstance()->mode(); env_mode_to_restore_ = Env::GetInstance()->mode();
......
...@@ -38,7 +38,7 @@ class TestInputDeviceClient : public ui::InputDeviceClient { ...@@ -38,7 +38,7 @@ class TestInputDeviceClient : public ui::InputDeviceClient {
} // namespace } // namespace
AuraTestSuiteSetup::AuraTestSuiteSetup() { AuraTestSuiteSetup::AuraTestSuiteSetup() {
DCHECK(!Env::GetInstanceDontCreate()); DCHECK(!Env::HasInstance());
#if BUILDFLAG(ENABLE_MUS) #if BUILDFLAG(ENABLE_MUS)
const Env::Mode env_mode = const Env::Mode env_mode =
features::IsAshInBrowserProcess() ? Env::Mode::LOCAL : Env::Mode::MUS; features::IsAshInBrowserProcess() ? Env::Mode::LOCAL : Env::Mode::MUS;
......
...@@ -23,7 +23,7 @@ aura::Window* GetOwnerRootWindow(views::Widget* owner) { ...@@ -23,7 +23,7 @@ aura::Window* GetOwnerRootWindow(views::Widget* owner) {
MenuPreTargetHandler::MenuPreTargetHandler(MenuController* controller, MenuPreTargetHandler::MenuPreTargetHandler(MenuController* controller,
Widget* owner) Widget* owner)
: controller_(controller), root_(GetOwnerRootWindow(owner)) { : controller_(controller), root_(GetOwnerRootWindow(owner)) {
aura::Env::GetInstanceDontCreate()->AddPreTargetHandler( aura::Env::GetInstance()->AddPreTargetHandler(
this, ui::EventTarget::Priority::kSystem); this, ui::EventTarget::Priority::kSystem);
if (root_) { if (root_) {
wm::GetActivationClient(root_)->AddObserver(this); wm::GetActivationClient(root_)->AddObserver(this);
...@@ -32,7 +32,7 @@ MenuPreTargetHandler::MenuPreTargetHandler(MenuController* controller, ...@@ -32,7 +32,7 @@ MenuPreTargetHandler::MenuPreTargetHandler(MenuController* controller,
} }
MenuPreTargetHandler::~MenuPreTargetHandler() { MenuPreTargetHandler::~MenuPreTargetHandler() {
aura::Env::GetInstanceDontCreate()->RemovePreTargetHandler(this); aura::Env::GetInstance()->RemovePreTargetHandler(this);
Cleanup(); Cleanup();
} }
......
...@@ -22,7 +22,7 @@ void RemoteViewHost::EmbedUsingToken(const base::UnguessableToken& embed_token, ...@@ -22,7 +22,7 @@ void RemoteViewHost::EmbedUsingToken(const base::UnguessableToken& embed_token,
int embed_flags, int embed_flags,
EmbedCallback callback) { EmbedCallback callback) {
// Only works with mus. // Only works with mus.
DCHECK_EQ(aura::Env::Mode::MUS, aura::Env::GetInstanceDontCreate()->mode()); DCHECK_EQ(aura::Env::Mode::MUS, aura::Env::GetInstance()->mode());
embed_token_ = embed_token; embed_token_ = embed_token;
embed_flags_ = embed_flags; embed_flags_ = embed_flags;
......
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