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

chromeos: Make multi-profile add user dialog work with mash

For go/mustash we have to use mojo interfaces to communicate between
the ash process and chrome browser. Add a mojo method to show the
dialog.

Migrate code from SystemTrayDelegateChromeOS (deprecated and doesn't
exist in mash) and ChromeShellClient (also doesn't exist in mash)
into SessionControllerClient.

This helps consolidate more session-related code into
SessionControllerClient and reduce the size of SystemTrayDelegate.

TBR=oshima@chromium.org

Bug: 647412
Test: existing ash and chrome tests
Change-Id: I1f65f43a4fe668095325ad20c8dc0c201f706321
Reviewed-on: https://chromium-review.googlesource.com/557935Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485334}
parent 37e685b3
......@@ -40,7 +40,7 @@ bool ShellDelegateMus::IsIncognitoAllowed() const {
bool ShellDelegateMus::IsMultiProfilesEnabled() const {
NOTIMPLEMENTED();
return false;
return true; // For manual testing of multi-profile under mash.
}
bool ShellDelegateMus::IsRunningInForcedAppMode() const {
......
......@@ -169,4 +169,7 @@ interface SessionControllerClient {
// Switch the active user to the next or previous user.
CycleActiveUser(CycleUserDirection direction);
// Show the multi-profile login UI to add another user to this session.
ShowMultiProfileLogin();
};
......@@ -180,6 +180,11 @@ void SessionController::CycleActiveUser(CycleUserDirection direction) {
client_->CycleActiveUser(direction);
}
void SessionController::ShowMultiProfileLogin() {
if (client_)
client_->ShowMultiProfileLogin();
}
void SessionController::AddObserver(SessionObserver* observer) {
observers_.AddObserver(observer);
}
......
......@@ -110,6 +110,9 @@ class ASH_EXPORT SessionController
// ordering as user sessions are created.
void CycleActiveUser(CycleUserDirection direction);
// Show the multi-profile login UI to add another user to this session.
void ShowMultiProfileLogin();
void AddObserver(SessionObserver* observer);
void RemoveObserver(SessionObserver* observer);
......
......@@ -12,8 +12,6 @@ SystemTrayDelegate::~SystemTrayDelegate() = default;
void SystemTrayDelegate::Initialize() {}
void SystemTrayDelegate::ShowUserLogin() {}
NetworkingConfigDelegate* SystemTrayDelegate::GetNetworkingConfigDelegate()
const {
return nullptr;
......
......@@ -26,9 +26,6 @@ class ASH_EXPORT SystemTrayDelegate {
// Called after SystemTray has been instantiated.
virtual void Initialize();
// Shows login UI to add other users to this session.
virtual void ShowUserLogin();
// Returns NetworkingConfigDelegate. May return nullptr.
virtual NetworkingConfigDelegate* GetNetworkingConfigDelegate() const;
......
......@@ -19,7 +19,6 @@
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_controller.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_popup_item_style.h"
#include "ash/system/tray/tray_popup_utils.h"
......@@ -262,7 +261,7 @@ void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) {
// The last item is the "sign in another user" row.
if (index_in_add_menu == sender->parent()->child_count() - 1) {
MultiProfileUMA::RecordSigninUser(MultiProfileUMA::SIGNIN_USER_BY_TRAY);
Shell::Get()->system_tray_delegate()->ShowUserLogin();
Shell::Get()->session_controller()->ShowMultiProfileLogin();
} else {
const int user_index = index_in_add_menu;
SwitchUser(user_index);
......
......@@ -179,5 +179,7 @@ void TestSessionControllerClient::CycleActiveUser(
SwitchActiveUser((*it)->user_info->account_id);
}
void TestSessionControllerClient::ShowMultiProfileLogin() {}
} // namespace test
} // namespace ash
......@@ -67,6 +67,7 @@ class TestSessionControllerClient : public ash::mojom::SessionControllerClient {
void RequestLockScreen() override;
void SwitchActiveUser(const AccountId& account_id) override;
void CycleActiveUser(CycleUserDirection direction) override;
void ShowMultiProfileLogin() override;
private:
SessionController* const controller_;
......
......@@ -5,10 +5,9 @@
#include "chrome/browser/chromeos/profiles/avatar_menu_actions_chromeos.h"
#include "ash/multi_profile_uma.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/ui/ash/session_controller_client.h"
#include "chrome/browser/ui/browser.h"
#include "components/user_manager/user_manager.h"
......@@ -29,7 +28,7 @@ void AvatarMenuActionsChromeOS::AddNewProfile(ProfileMetrics::ProfileAdd type) {
// Let the user add another account to the session.
ash::MultiProfileUMA::RecordSigninUser(
ash::MultiProfileUMA::SIGNIN_USER_BY_BROWSER_FRAME);
ash::Shell::Get()->system_tray_delegate()->ShowUserLogin();
SessionControllerClient::Get()->ShowMultiProfileLogin();
}
void AvatarMenuActionsChromeOS::EditProfile(Profile* profile) {
......
......@@ -41,7 +41,6 @@
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/signin_error_notifier_factory_ash.h"
#include "chrome/browser/speech/tts_controller.h"
#include "chrome/browser/sync/sync_error_notifier_factory_ash.h"
......@@ -50,6 +49,7 @@
#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/palette_delegate_chromeos.h"
#include "chrome/browser/ui/ash/session_controller_client.h"
#include "chrome/browser/ui/ash/session_util.h"
#include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
#include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
......@@ -406,28 +406,7 @@ service_manager::Connector* ChromeShellDelegate::GetShellConnector() const {
}
bool ChromeShellDelegate::IsMultiProfilesEnabled() const {
if (!profiles::IsMultipleProfilesEnabled())
return false;
// If there is a user manager, we need to see that we can at least have 2
// simultaneous users to allow this feature.
if (!user_manager::UserManager::IsInitialized())
return false;
size_t admitted_users_to_be_added =
user_manager::UserManager::Get()->GetUsersAllowedForMultiProfile().size();
size_t logged_in_users =
user_manager::UserManager::Get()->GetLoggedInUsers().size();
if (!logged_in_users) {
// The shelf gets created on the login screen and as such we have to create
// all multi profile items of the the system tray menu before the user logs
// in. For special cases like Kiosk mode and / or guest mode this isn't a
// problem since either the browser gets restarted and / or the flag is not
// allowed, but for an "ephermal" user (see crbug.com/312324) it is not
// decided yet if they could add other users to their session or not.
// TODO(skuhne): As soon as the issue above needs to be resolved, this logic
// should change.
logged_in_users = 1;
}
return admitted_users_to_be_added + logged_in_users > 1;
return SessionControllerClient::IsMultiProfileEnabled();
}
bool ChromeShellDelegate::IsIncognitoAllowed() const {
......
......@@ -16,13 +16,18 @@
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/chromeos/login/user_flow.h"
#include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
#include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
#include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/user_switch_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/theme_resources.h"
......@@ -31,6 +36,7 @@
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
#include "components/session_manager/core/session_manager.h"
#include "components/user_manager/user_type.h"
#include "content/public/browser/notification_service.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/service_names.mojom.h"
......@@ -113,6 +119,14 @@ void DoSwitchUser(const AccountId& account_id) {
UserManager::Get()->SwitchActiveUser(account_id);
}
// Callback for the dialog that warns the user about multi-profile, which has
// a "never show again" checkbox.
void OnAcceptMultiProfileIntro(bool never_show_again) {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
prefs->SetBoolean(prefs::kMultiProfileNeverShowIntro, never_show_again);
chromeos::UserAddingScreen::Get()->Start();
}
} // namespace
namespace mojo {
......@@ -215,6 +229,67 @@ void SessionControllerClient::CycleActiveUser(
DoCycleActiveUser(direction);
}
void SessionControllerClient::ShowMultiProfileLogin() {
if (!IsMultiProfileEnabled())
return;
// Only regular non-supervised users could add other users to current session.
if (UserManager::Get()->GetActiveUser()->GetType() !=
user_manager::USER_TYPE_REGULAR) {
return;
}
if (UserManager::Get()->GetLoggedInUsers().size() >=
session_manager::kMaxmiumNumberOfUserSessions) {
return;
}
// Launch sign in screen to add another user to current session.
if (!UserManager::Get()->GetUsersAllowedForMultiProfile().empty()) {
// Don't show the dialog if any logged-in user in the multi-profile session
// dismissed it.
bool show_intro = true;
const user_manager::UserList logged_in_users =
UserManager::Get()->GetLoggedInUsers();
for (User* user : logged_in_users) {
show_intro &=
!multi_user_util::GetProfileFromAccountId(user->GetAccountId())
->GetPrefs()
->GetBoolean(prefs::kMultiProfileNeverShowIntro);
if (!show_intro)
break;
}
if (show_intro) {
base::Callback<void(bool)> on_accept =
base::Bind(&OnAcceptMultiProfileIntro);
chromeos::ShowMultiprofilesIntroDialog(on_accept);
} else {
chromeos::UserAddingScreen::Get()->Start();
}
}
}
// static
bool SessionControllerClient::IsMultiProfileEnabled() {
if (!profiles::IsMultipleProfilesEnabled() || !UserManager::IsInitialized())
return false;
size_t admitted_users_to_be_added =
UserManager::Get()->GetUsersAllowedForMultiProfile().size();
size_t logged_in_users = UserManager::Get()->GetLoggedInUsers().size();
if (logged_in_users == 0) {
// The shelf gets created on the login screen and as such we have to create
// all multi profile items of the the system tray menu before the user logs
// in. For special cases like Kiosk mode and / or guest mode this isn't a
// problem since either the browser gets restarted and / or the flag is not
// allowed, but for an "ephermal" user (see crbug.com/312324) it is not
// decided yet if they could add other users to their session or not.
// TODO(skuhne): As soon as the issue above needs to be resolved, this logic
// should change.
logged_in_users = 1;
}
return (admitted_users_to_be_added + logged_in_users) > 1;
}
void SessionControllerClient::ActiveUserChanged(const User* active_user) {
SendSessionInfoIfChanged();
......
......@@ -69,6 +69,9 @@ class SessionControllerClient
void RequestLockScreen() override;
void SwitchActiveUser(const AccountId& account_id) override;
void CycleActiveUser(ash::CycleUserDirection direction) override;
void ShowMultiProfileLogin() override;
static bool IsMultiProfileEnabled();
// user_manager::UserManager::UserSessionStateObserver:
void ActiveUserChanged(const user_manager::User* active_user) override;
......
......@@ -30,12 +30,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
#include "chrome/browser/chromeos/events/system_key_event_listener.h"
#include "chrome/browser/chromeos/login/login_wizard.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/networking_config_delegate_chromeos.h"
#include "chrome/browser/ui/ash/system_tray_client.h"
#include "chrome/browser/ui/browser.h"
......@@ -51,9 +46,6 @@
#include "components/google/core/browser/google_util.h"
#include "components/prefs/pref_service.h"
#include "components/session_manager/core/session_manager.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "components/user_manager/user_type.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_service.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -62,16 +54,6 @@
namespace chromeos {
namespace {
void OnAcceptMultiprofilesIntro(bool no_show_again) {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
prefs->SetBoolean(prefs::kMultiProfileNeverShowIntro, no_show_again);
UserAddingScreen::Get()->Start();
}
} // namespace
SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS()
: networking_config_delegate_(
base::MakeUnique<NetworkingConfigDelegateChromeos>()) {
......@@ -120,50 +102,6 @@ SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() {
DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this);
}
void SystemTrayDelegateChromeOS::ShowUserLogin() {
if (!ash::Shell::Get()->shell_delegate()->IsMultiProfilesEnabled())
return;
// Only regular non-supervised users could add other users to current session.
if (user_manager::UserManager::Get()->GetActiveUser()->GetType() !=
user_manager::USER_TYPE_REGULAR) {
return;
}
if (user_manager::UserManager::Get()->GetLoggedInUsers().size() >=
session_manager::kMaxmiumNumberOfUserSessions) {
return;
}
// Launch sign in screen to add another user to current session.
if (user_manager::UserManager::Get()
->GetUsersAllowedForMultiProfile()
.size()) {
// Don't show dialog if any logged in user in multi-profiles session
// dismissed it.
bool show_intro = true;
const user_manager::UserList logged_in_users =
user_manager::UserManager::Get()->GetLoggedInUsers();
for (user_manager::UserList::const_iterator it = logged_in_users.begin();
it != logged_in_users.end();
++it) {
show_intro &=
!multi_user_util::GetProfileFromAccountId((*it)->GetAccountId())
->GetPrefs()
->GetBoolean(prefs::kMultiProfileNeverShowIntro);
if (!show_intro)
break;
}
if (show_intro) {
base::Callback<void(bool)> on_accept =
base::Bind(&OnAcceptMultiprofilesIntro);
ShowMultiprofilesIntroDialog(on_accept);
} else {
UserAddingScreen::Get()->Start();
}
}
}
ash::NetworkingConfigDelegate*
SystemTrayDelegateChromeOS::GetNetworkingConfigDelegate() const {
return networking_config_delegate_.get();
......
......@@ -43,7 +43,6 @@ class SystemTrayDelegateChromeOS
// Overridden from ash::SystemTrayDelegate:
void Initialize() override;
void ShowUserLogin() override;
ash::NetworkingConfigDelegate* GetNetworkingConfigDelegate() const override;
void ActiveUserWasChanged() override;
bool IsSearchKeyMappedToCapsLock() override;
......
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