Commit 9bd413c9 authored by Anastasiia N's avatar Anastasiia N Committed by Chromium LUCI CQ

[Lacros] Add AccountManagerUI

`AccountManagerUI` is used by `AccountManagerFacadeAsh` to show system
UI (system dialogs, OS Settings etc.). `AccountManagerFacadeAsh` cannot
show system dialogs directly because it is inside
chromeos/components/ and can not depend on chrome/browser/.

`InlineLoginDialogChromeOS::Show` methods will be private, so no one can
call them directly. These methods will be called only by
`AccountManagerUIImpl`. Also, `InlineLoginDialogChromeOS` will not send
UMA stats anymore (they will be sent by `AccountManagerFacade` instead).

Bug: 1140469
Change-Id: I5f204d2dfcae7e8c920af672f1d4d7109ae1c5f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550741
Commit-Queue: Anastasiia N <anastasiian@chromium.org>
Reviewed-by: default avatarKush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835637}
parent eefc5925
......@@ -448,6 +448,8 @@ source_set("chromeos") {
"account_manager/account_manager_policy_controller.h",
"account_manager/account_manager_policy_controller_factory.cc",
"account_manager/account_manager_policy_controller_factory.h",
"account_manager/account_manager_ui_impl.cc",
"account_manager/account_manager_ui_impl.h",
"account_manager/account_manager_util.cc",
"account_manager/account_manager_util.h",
"account_manager/account_migration_runner.cc",
......
// Copyright 2020 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/chromeos/account_manager/account_manager_ui_impl.h"
#include "chrome/browser/ui/webui/signin/inline_login_dialog_chromeos.h"
namespace chromeos {
AccountManagerUIImpl::AccountManagerUIImpl() = default;
AccountManagerUIImpl::~AccountManagerUIImpl() = default;
void AccountManagerUIImpl::ShowAddAccountDialog(
base::OnceClosure close_dialog_closure) {
InlineLoginDialogChromeOS::Show(std::move(close_dialog_closure));
}
void AccountManagerUIImpl::ShowReauthAccountDialog(const std::string& email) {
InlineLoginDialogChromeOS::Show(email,
/*close_dialog_closure=*/base::DoNothing());
}
bool AccountManagerUIImpl::IsDialogShown() {
return InlineLoginDialogChromeOS::IsShown();
}
} // namespace chromeos
// Copyright 2020 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.
#ifndef CHROME_BROWSER_CHROMEOS_ACCOUNT_MANAGER_ACCOUNT_MANAGER_UI_IMPL_H_
#define CHROME_BROWSER_CHROMEOS_ACCOUNT_MANAGER_ACCOUNT_MANAGER_UI_IMPL_H_
#include "chromeos/components/account_manager/account_manager_ui.h"
namespace chromeos {
class AccountManagerUIImpl : public AccountManagerUI {
public:
AccountManagerUIImpl();
AccountManagerUIImpl(const AccountManagerUIImpl&) = delete;
AccountManagerUIImpl& operator=(const AccountManagerUIImpl&) = delete;
~AccountManagerUIImpl() override;
private:
// AccountManagerUI overrides:
void ShowAddAccountDialog(base::OnceClosure close_dialog_closure) override;
void ShowReauthAccountDialog(const std::string& email) override;
bool IsDialogShown() override;
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_ACCOUNT_MANAGER_ACCOUNT_MANAGER_UI_IMPL_H_
......@@ -9,6 +9,7 @@
#include "ash/public/cpp/window_backdrop.h"
#include "ash/public/cpp/window_properties.h"
#include "base/callback_helpers.h"
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/json/json_writer.h"
......@@ -96,34 +97,20 @@ GURL GetInlineLoginUrl(const std::string& email, bool is_arc_source) {
const char InlineLoginDialogChromeOS::kAccountAdditionSource[] =
"AccountManager.AccountAdditionSource";
// static
bool InlineLoginDialogChromeOS::IsShown() {
return dialog != nullptr;
}
// static
void InlineLoginDialogChromeOS::ShowDeprecated(const std::string& email,
const Source& source) {
base::UmaHistogramEnumeration(kAccountAdditionSource, source);
// If the dialog was triggered as a response to background request, it could
// get displayed on the lock screen. In this case it is safe to ignore it,
// since in this case user will get it again after a request to Google
// properties.
if (session_manager::SessionManager::Get()->IsUserSessionBlocked())
return;
if (dialog) {
dialog->dialog_window()->Focus();
return;
}
// Will be deleted by |SystemWebDialogDelegate::OnDialogClosed|.
const bool is_arc_source = source == InlineLoginDialogChromeOS::Source::kArc;
dialog = new InlineLoginDialogChromeOS(
GetInlineLoginUrl(email, is_arc_source), is_arc_source);
dialog->ShowSystemDialog();
// TODO(crbug.com/1016828): Remove/update this after the dialog behavior on
// Chrome OS is defined.
ash::WindowBackdrop::Get(dialog->dialog_window())
->SetBackdropType(ash::WindowBackdrop::BackdropType::kSemiOpaque);
ShowInternal(email, is_arc_source);
}
// static
void InlineLoginDialogChromeOS::ShowDeprecated(const Source& source) {
ShowDeprecated(/* email= */ std::string(), source);
}
......@@ -183,7 +170,24 @@ InlineLoginDialogChromeOS::InlineLoginDialogChromeOS(const GURL& url,
dialog = this;
}
InlineLoginDialogChromeOS::InlineLoginDialogChromeOS(
const GURL& url,
bool is_arc_source,
base::OnceClosure close_dialog_closure)
: SystemWebDialogDelegate(url, base::string16() /* title */),
delegate_(this),
is_arc_source_(is_arc_source),
url_(url),
close_dialog_closure_(std::move(close_dialog_closure)) {
DCHECK(!dialog);
dialog = this;
}
InlineLoginDialogChromeOS::~InlineLoginDialogChromeOS() {
if (!close_dialog_closure_.is_null()) {
std::move(close_dialog_closure_).Run();
}
DCHECK_EQ(this, dialog);
dialog = nullptr;
}
......@@ -245,4 +249,44 @@ void InlineLoginDialogChromeOS::OnDialogClosed(const std::string& json_retval) {
SystemWebDialogDelegate::OnDialogClosed(json_retval);
}
// static
void InlineLoginDialogChromeOS::Show(base::OnceClosure close_dialog_closure) {
Show(/* email= */ std::string(), std::move(close_dialog_closure));
}
// static
void InlineLoginDialogChromeOS::Show(const std::string& email,
base::OnceClosure close_dialog_closure) {
ShowInternal(email, /*is_arc_source=*/false, std::move(close_dialog_closure));
}
// static
void InlineLoginDialogChromeOS::ShowInternal(
const std::string& email,
bool is_arc_source,
base::OnceClosure close_dialog_closure) {
// If the dialog was triggered as a response to background request, it could
// get displayed on the lock screen. In this case it is safe to ignore it,
// since in this case user will get it again after a request to Google
// properties.
if (session_manager::SessionManager::Get()->IsUserSessionBlocked())
return;
if (dialog) {
dialog->dialog_window()->Focus();
return;
}
// Will be deleted by |SystemWebDialogDelegate::OnDialogClosed|.
dialog = new InlineLoginDialogChromeOS(
GetInlineLoginUrl(email, is_arc_source), is_arc_source,
std::move(close_dialog_closure));
dialog->ShowSystemDialog();
// TODO(crbug.com/1016828): Remove/update this after the dialog behavior on
// Chrome OS is defined.
ash::WindowBackdrop::Get(dialog->dialog_window())
->SetBackdropType(ash::WindowBackdrop::BackdropType::kSemiOpaque);
}
} // namespace chromeos
......@@ -11,6 +11,7 @@
#include "base/optional.h"
#include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h"
#include "chrome/browser/ui/webui/signin/inline_login_handler_modal_delegate.h"
#include "chromeos/components/account_manager/account_manager.h"
#include "components/web_modal/web_contents_modal_dialog_host.h"
class GURL;
......@@ -66,6 +67,8 @@ class InlineLoginDialogChromeOS : public SystemWebDialogDelegate,
kMaxValue = kFlowCompleted
};
static bool IsShown();
// Displays the dialog. |email| pre-fills the account email field in the
// sign-in dialog - useful for account re-authentication. |source| specifies
// the source UX surface used for launching the dialog.
......@@ -99,6 +102,10 @@ class InlineLoginDialogChromeOS : public SystemWebDialogDelegate,
// from ARC. It's used to display the correct error message for Child users.
explicit InlineLoginDialogChromeOS(bool is_arc_source);
InlineLoginDialogChromeOS(const GURL& url, bool is_arc_source);
InlineLoginDialogChromeOS(const GURL& url,
bool is_arc_source,
base::OnceClosure close_dialog_closure);
~InlineLoginDialogChromeOS() override;
// ui::WebDialogDelegate overrides
......@@ -110,10 +117,30 @@ class InlineLoginDialogChromeOS : public SystemWebDialogDelegate,
void OnDialogClosed(const std::string& json_retval) override;
private:
// `Show` method can be called directly only by `AccountManagerUIImpl` class.
// To show the dialog, use `AccountManagerFacade`.
friend class AccountManagerUIImpl;
// Displays the dialog. |close_dialog_closure| will be called when the dialog
// is closed.
static void Show(base::OnceClosure close_dialog_closure);
// Displays the dialog. |email| pre-fills the account email field in the
// sign-in dialog - useful for account re-authentication.
// |close_dialog_closure| will be called when the dialog is closed.
static void Show(const std::string& email,
base::OnceClosure close_dialog_closure);
static void ShowInternal(
const std::string& email,
bool is_arc_source,
base::OnceClosure close_dialog_closure = base::DoNothing());
InlineLoginHandlerModalDelegate delegate_;
const bool is_arc_source_;
const GURL url_;
base::Optional<EduCoexistenceFlowResult> edu_coexistence_flow_result_;
base::OnceClosure close_dialog_closure_;
DISALLOW_COPY_AND_ASSIGN(InlineLoginDialogChromeOS);
};
......
......@@ -14,6 +14,8 @@ component("account_manager") {
"account_manager_facade_ash.h",
"account_manager_factory.cc",
"account_manager_factory.h",
"account_manager_ui.cc",
"account_manager_ui.h",
]
public_deps = [
......
// Copyright 2020 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 "chromeos/components/account_manager/account_manager_ui.h"
namespace chromeos {
AccountManagerUI::AccountManagerUI() = default;
AccountManagerUI::~AccountManagerUI() = default;
} // namespace chromeos
// Copyright 2020 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.
#ifndef CHROMEOS_COMPONENTS_ACCOUNT_MANAGER_ACCOUNT_MANAGER_UI_H_
#define CHROMEOS_COMPONENTS_ACCOUNT_MANAGER_ACCOUNT_MANAGER_UI_H_
#include "base/callback.h"
#include "base/component_export.h"
namespace chromeos {
// This interface is used by `AccountManagerFacadeAsh` to show system UI (system
// dialogs, OS Settings etc.)
class COMPONENT_EXPORT(ACCOUNT_MANAGER) AccountManagerUI {
public:
AccountManagerUI();
AccountManagerUI(const AccountManagerUI&) = delete;
AccountManagerUI& operator=(const AccountManagerUI&) = delete;
virtual ~AccountManagerUI();
// Show system dialog for account addition.
// `close_dialog_closure` callback will be called when dialog is closed.
virtual void ShowAddAccountDialog(base::OnceClosure close_dialog_closure) = 0;
// Show system dialog for account reauthentication.
// `email` is the email of account that will be reauthenticated.
virtual void ShowReauthAccountDialog(const std::string& email) = 0;
virtual bool IsDialogShown() = 0;
};
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_ACCOUNT_MANAGER_ACCOUNT_MANAGER_UI_H_
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