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