Skip to content

Commit

Permalink
ash: Migrate session info methods to SessionController
Browse files Browse the repository at this point in the history
Migrate the following from mojom::SessionController:
- SetSessionInfo
- UpdateUserSession
- SetUserSessionOrder

Bug: 958214
Change-Id: I33d0210753e61801ac16d16f08360e0121d0f160
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1600432
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Daniele Castagna <dcastagna@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657775}
  • Loading branch information
Xiyuan Xia authored and Commit Bot committed May 8, 2019
1 parent d7748c5 commit 06a4e4c
Show file tree
Hide file tree
Showing 48 changed files with 585 additions and 635 deletions.
8 changes: 4 additions & 4 deletions ash/assistant/assistant_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void AssistantController::DownloadImage(
mojom::AssistantImageDownloader::DownloadCallback callback) {
DCHECK(assistant_image_downloader_);

const mojom::UserSession* user_session =
const UserSession* user_session =
Shell::Get()->session_controller()->GetUserSession(0);

if (!user_session) {
Expand All @@ -156,7 +156,7 @@ void AssistantController::DownloadImage(
return;
}

AccountId account_id = user_session->user_info->account_id;
AccountId account_id = user_session->user_info.account_id;
assistant_image_downloader_->Download(account_id, url, std::move(callback));
}

Expand Down Expand Up @@ -261,7 +261,7 @@ void AssistantController::OpenUrl(const GURL& url, bool from_server) {

void AssistantController::GetNavigableContentsFactory(
mojo::PendingReceiver<content::mojom::NavigableContentsFactory> receiver) {
const mojom::UserSession* user_session =
const UserSession* user_session =
Shell::Get()->session_controller()->GetUserSession(0);

if (!user_session) {
Expand All @@ -270,7 +270,7 @@ void AssistantController::GetNavigableContentsFactory(
}

const base::Optional<base::Token>& service_instance_group =
user_session->user_info->service_instance_group;
user_session->user_info.service_instance_group;
if (!service_instance_group) {
LOG(ERROR) << "Unable to retrieve service instance group.";
return;
Expand Down
4 changes: 2 additions & 2 deletions ash/assistant/assistant_ui_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ void AssistantUiController::OnUiVisibilityChanged(
// user so that we don't leak across user sessions.
auto* window_manager = MultiUserWindowManagerImpl::Get();
if (window_manager) {
const mojom::UserSession* user_session =
const UserSession* user_session =
Shell::Get()->session_controller()->GetUserSession(0);
if (user_session) {
container_view_->GetWidget()->GetNativeWindow()->SetProperty(
aura::client::kCreatedByUserGesture, true);
window_manager->SetWindowOwner(
container_view_->GetWidget()->GetNativeWindow(),
user_session->user_info->account_id);
user_session->user_info.account_id);
}
}
break;
Expand Down
12 changes: 6 additions & 6 deletions ash/detachable_base/detachable_base_notification_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,24 @@ void DetachableBaseNotificationController::ShowPairingNotificationIfNeeded() {
if (Shell::Get()->session_controller()->IsUserSessionBlocked())
return;

const mojom::UserSession* active_session =
const UserSession* active_session =
Shell::Get()->session_controller()->GetUserSession(0);
if (!active_session || !active_session->user_info)
if (!active_session)
return;

DetachableBasePairingStatus pairing_status =
detachable_base_handler_->GetPairingStatus();
if (pairing_status == DetachableBasePairingStatus::kNone)
return;

const mojom::UserInfo& user_info = *active_session->user_info;
const mojom::UserInfoPtr user_info = active_session->user_info.ToMojom();
if (pairing_status == DetachableBasePairingStatus::kAuthenticated &&
detachable_base_handler_->PairedBaseMatchesLastUsedByUser(user_info)) {
detachable_base_handler_->PairedBaseMatchesLastUsedByUser(*user_info)) {
// Set the current base as last used by the user.
// PairedBaseMatchesLastUsedByUser returns true if the user has not
// previously used a base, so make sure the last used base value is actually
// set.
detachable_base_handler_->SetPairedBaseAsLastUsedByUser(user_info);
detachable_base_handler_->SetPairedBaseAsLastUsedByUser(*user_info);
return;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ void DetachableBaseNotificationController::ShowPairingNotificationIfNeeded() {
// At this point the session is unblocked - mark the current base as used by
// user (as they have just been notified about the base change).
if (pairing_status == DetachableBasePairingStatus::kAuthenticated)
detachable_base_handler_->SetPairedBaseAsLastUsedByUser(user_info);
detachable_base_handler_->SetPairedBaseAsLastUsedByUser(*user_info);
}

void DetachableBaseNotificationController::RemovePairingNotification() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ TEST_F(DetachableBaseNotificationControllerTest,
CloseBaseChangedNotification();

GetSessionControllerClient()->SwitchActiveUser(
session_controller()->GetUserSession(1)->user_info->account_id);
session_controller()->GetUserSession(1)->user_info.account_id);

EXPECT_TRUE(IsBaseChangedNotificationVisible());
}
Expand Down Expand Up @@ -212,7 +212,7 @@ TEST_F(DetachableBaseNotificationControllerTest,
EXPECT_FALSE(IsBaseChangedNotificationVisible());

EXPECT_TRUE(detachable_base_handler()->SetPairedBaseAsLastUsedByUser(
*session_controller()->GetUserSession(0)->user_info));
*session_controller()->GetUserSession(0)->user_info.ToMojom()));

UnblockUserSession();
EXPECT_FALSE(IsBaseChangedNotificationVisible());
Expand Down
14 changes: 6 additions & 8 deletions ash/display/resolution_notification_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,12 @@ TEST_F(ResolutionNotificationControllerTest, Fallback) {

TEST_F(ResolutionNotificationControllerTest, NoTimeoutInKioskMode) {
// Login in as kiosk app.
mojom::UserSessionPtr session = mojom::UserSession::New();
session->session_id = 1u;
session->user_info = mojom::UserInfo::New();
session->user_info->avatar = mojom::UserAvatar::New();
session->user_info->type = user_manager::USER_TYPE_KIOSK_APP;
session->user_info->account_id = AccountId::FromUserEmail("user1@test.com");
session->user_info->display_name = "User 1";
session->user_info->display_email = "user1@test.com";
UserSession session;
session.session_id = 1u;
session.user_info.type = user_manager::USER_TYPE_KIOSK_APP;
session.user_info.account_id = AccountId::FromUserEmail("user1@test.com");
session.user_info.display_name = "User 1";
session.user_info.display_email = "user1@test.com";
Shell::Get()->session_controller()->UpdateUserSession(std::move(session));
EXPECT_EQ(LoginStatus::KIOSK_APP,
Shell::Get()->session_controller()->login_status());
Expand Down
2 changes: 1 addition & 1 deletion ash/kiosk_next/kiosk_next_shell_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void KioskNextShellController::OnActiveUserPrefServiceChanged(
kiosk_next_shell_client_->LaunchKioskNextShell(Shell::Get()
->session_controller()
->GetPrimaryUserSession()
->user_info->account_id);
->user_info.account_id);

// Notify observers that KioskNextShell has been enabled.
for (KioskNextShellObserver& observer : observer_list_) {
Expand Down
6 changes: 3 additions & 3 deletions ash/media/media_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class MediaControllerTest : public AshTestBase {
}

void SimulateSessionLock() {
mojom::SessionInfoPtr info_ptr = mojom::SessionInfo::New();
info_ptr->state = session_manager::SessionState::LOCKED;
Shell::Get()->session_controller()->SetSessionInfo(std::move(info_ptr));
SessionInfo info;
info.state = session_manager::SessionState::LOCKED;
Shell::Get()->session_controller()->SetSessionInfo(info);
}

void Flush() {
Expand Down
8 changes: 4 additions & 4 deletions ash/media/media_notification_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class MediaNotificationControllerTest : public AshTestBase {
}

void SimulateSessionLock(bool locked) {
mojom::SessionInfoPtr info_ptr = mojom::SessionInfo::New();
info_ptr->state = locked ? session_manager::SessionState::LOCKED
: session_manager::SessionState::ACTIVE;
Shell::Get()->session_controller()->SetSessionInfo(std::move(info_ptr));
SessionInfo info;
info.state = locked ? session_manager::SessionState::LOCKED
: session_manager::SessionState::ACTIVE;
Shell::Get()->session_controller()->SetSessionInfo(info);
}

private:
Expand Down
5 changes: 2 additions & 3 deletions ash/multi_device_setup/multi_device_notification_presenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,14 @@ void MultiDeviceNotificationPresenter::ObserveMultiDeviceSetupIfPossible() {
return;
}

const mojom::UserSession* user_session =
session_controller->GetPrimaryUserSession();
const UserSession* user_session = session_controller->GetPrimaryUserSession();

// The primary user session may be unavailable (e.g., for test/guest users).
if (!user_session)
return;

base::Optional<base::Token> service_instance_group =
user_session->user_info->service_instance_group;
user_session->user_info.service_instance_group;

// Cannot proceed if there is no known service instance group.
if (!service_instance_group)
Expand Down
10 changes: 5 additions & 5 deletions ash/multi_user/multi_user_window_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ mojom::WallpaperUserInfoPtr WallpaperUserInfoForAccount(
mojom::WallpaperUserInfo::New();
SessionControllerImpl* session_controller =
Shell::Get()->session_controller();
for (const mojom::UserSessionPtr& user_session :
for (const std::unique_ptr<UserSession>& user_session :
session_controller->GetUserSessions()) {
if (user_session->user_info->account_id == account_id) {
if (user_session->user_info.account_id == account_id) {
wallpaper_user_info->account_id = account_id;
wallpaper_user_info->type = user_session->user_info->type;
wallpaper_user_info->is_ephemeral = user_session->user_info->is_ephemeral;
wallpaper_user_info->type = user_session->user_info.type;
wallpaper_user_info->is_ephemeral = user_session->user_info.is_ephemeral;
wallpaper_user_info->has_gaia_account =
user_session->user_info->has_gaia_account;
user_session->user_info.has_gaia_account;
return wallpaper_user_info;
}
}
Expand Down
4 changes: 4 additions & 0 deletions ash/public/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ component("cpp") {
"session/session_controller.cc",
"session/session_controller.h",
"session/session_controller_client.h",
"session/session_types.cc",
"session/session_types.h",
"session/user_info.cc",
"session/user_info.h",
"shelf_item.cc",
"shelf_item.h",
"shelf_item_delegate.cc",
Expand Down Expand Up @@ -163,6 +166,7 @@ component("cpp") {
public_deps = [
"//ash/public/interfaces:interfaces_internal",
"//base",
"//components/session_manager:base",
"//ui/gfx",
]

Expand Down
20 changes: 20 additions & 0 deletions ash/public/cpp/session/session_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
#ifndef ASH_PUBLIC_CPP_SESSION_SESSION_CONTROLLER_H_
#define ASH_PUBLIC_CPP_SESSION_SESSION_CONTROLLER_H_

#include <stdint.h>

#include <vector>

#include "ash/public/cpp/ash_public_export.h"
#include "ash/public/cpp/session/session_types.h"

namespace ash {

Expand All @@ -20,6 +25,21 @@ class ASH_PUBLIC_EXPORT SessionController {
// Sets the client interface.
virtual void SetClient(SessionControllerClient* client) = 0;

// Sets the ash session info.
virtual void SetSessionInfo(const SessionInfo& info) = 0;

// Updates a user session. This is called when a user session is added or
// its meta data (e.g. name, avatar) is changed. There is no method to remove
// a user session because ash/chrome does not support that. All users are
// logged out at the same time.
virtual void UpdateUserSession(const UserSession& user_session) = 0;

// Sets the order of user sessions. The order is keyed by the session id.
// Currently, session manager set a LRU order with the first one being the
// active user session.
virtual void SetUserSessionOrder(
const std::vector<uint32_t>& user_session_ids) = 0;

protected:
SessionController();
virtual ~SessionController();
Expand Down
7 changes: 3 additions & 4 deletions ash/public/cpp/session/session_controller_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
#define ASH_PUBLIC_CPP_SESSION_SESSION_CONTROLLER_CLIENT_H_

#include "ash/public/cpp/ash_public_export.h"

class AccountId;
#include "ash/public/cpp/session/session_controller.h"
#include "ash/public/cpp/session/session_types.h"
#include "components/account_id/account_id.h"

namespace ash {

enum class CycleUserDirection;

class ASH_PUBLIC_EXPORT SessionControllerClient {
public:
// Requests to lock screen.
Expand Down
31 changes: 31 additions & 0 deletions ash/public/cpp/session/session_types.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2019 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 "ash/public/cpp/session/session_types.h"

namespace ash {

bool operator==(const SessionInfo& a, const SessionInfo& b) {
return a.can_lock_screen == b.can_lock_screen &&
a.should_lock_screen_automatically ==
b.should_lock_screen_automatically &&
a.is_running_in_app_mode == b.is_running_in_app_mode &&
a.is_demo_session == b.is_demo_session &&
a.add_user_session_policy == b.add_user_session_policy &&
a.state == b.state;
}

UserSession::UserSession() = default;
UserSession::UserSession(const UserSession& other) = default;
UserSession::~UserSession() = default;

bool operator==(const UserSession& a, const UserSession& b) {
return a.session_id == b.session_id && a.user_info == b.user_info &&
a.custodian_email == b.custodian_email &&
a.second_custodian_email == b.second_custodian_email &&
a.should_enable_settings == b.should_enable_settings &&
a.should_show_notification_tray == b.should_show_notification_tray;
}

} // namespace ash
68 changes: 68 additions & 0 deletions ash/public/cpp/session/session_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
#ifndef ASH_PUBLIC_CPP_SESSION_SESSION_TYPES_H_
#define ASH_PUBLIC_CPP_SESSION_SESSION_TYPES_H_

#include <stdint.h>

#include <string>

#include "ash/public/cpp/ash_public_export.h"
#include "ash/public/cpp/session/user_info.h"
#include "components/session_manager/session_manager_types.h"

namespace ash {

// The index of the user profile to use. The list is always LRU sorted so that
Expand All @@ -29,6 +37,66 @@ enum class CycleUserDirection {
PREVIOUS, // Cycle to the previous user.
};

// Info about an ash session.
struct ASH_PUBLIC_EXPORT SessionInfo {
// Whether the screen can be locked.
bool can_lock_screen = false;

// Whether the screen should be locked automatically before suspending.
bool should_lock_screen_automatically = false;

// Whether the session is in app mode, which includes a kiosk-like mode for
// fullscreen web content or running a single [forced] Chrome or ARC app.
bool is_running_in_app_mode = false;

// Whether the session is a demo session, which is an ephemeral session for
// Demo Mode.
bool is_demo_session = false;

// Sets whether adding a user session to ash is allowed.
AddUserSessionPolicy add_user_session_policy = AddUserSessionPolicy::ALLOWED;

// Current state of the ash session.
session_manager::SessionState state = session_manager::SessionState::UNKNOWN;
};

ASH_PUBLIC_EXPORT bool operator==(const SessionInfo& a, const SessionInfo& b);

// Info about a user session in ash.
struct ASH_PUBLIC_EXPORT UserSession {
UserSession();
UserSession(const UserSession& other);
~UserSession();

// A user session id for the user session. It is generated by session manager
// (chrome) when a user session starts and never changes during the lifetime
// of the session manager. The number starts at 1 for the first user session
// and incremented by one for each subsequent user session.
uint32_t session_id = 0;

// Contains general user information state, like the account id, display name,
// and avatar.
UserInfo user_info;

// For supervised users only, the email address of the custodian account.
// Empty for non-supervised users. Available after profile is loaded.
std::string custodian_email;

// For supervised users only, the email address of the second custodian
// account, if any. Available after profile is loaded.
std::string second_custodian_email;

// Whether the settings icon should be enabled in the system tray menu.
// Usually true after login, but can be false for specialized user sessions
// (e.g. adding supervised users).
bool should_enable_settings = false;

// Similar to |should_show_settings| but for the notification tray.
bool should_show_notification_tray = false;
};

ASH_PUBLIC_EXPORT bool operator==(const UserSession& a, const UserSession& b);

} // namespace ash

#endif // ASH_PUBLIC_CPP_SESSION_SESSION_TYPES_H_
Loading

0 comments on commit 06a4e4c

Please sign in to comment.