Commit 866203ad authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

propagate the device owner info to ash::SessionController

BUG=857103
TEST=ash_unittests, unit_tests

Change-Id: I46f1b09a2d2ad4a90fe42c75a9d0f587c03ab1cf
Reviewed-on: https://chromium-review.googlesource.com/1137232
Commit-Queue: Jun Mukai <mukai@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577626}
parent a312e36b
...@@ -59,4 +59,6 @@ struct UserInfo { ...@@ -59,4 +59,6 @@ struct UserInfo {
// True if the user's non-cryptohome data (wallpaper, avatar etc.) is // True if the user's non-cryptohome data (wallpaper, avatar etc.) is
// ephemeral. See |UserManager::IsUserNonCryptohomeDataEphemeral| for details. // ephemeral. See |UserManager::IsUserNonCryptohomeDataEphemeral| for details.
bool is_ephemeral; bool is_ephemeral;
// True if the user is also the device owner.
bool is_device_owner;
}; };
...@@ -534,6 +534,7 @@ void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { ...@@ -534,6 +534,7 @@ void SessionController::AddUserSession(mojom::UserSessionPtr user_session) {
weak_ptr_factory_.GetWeakPtr(), account_id)); weak_ptr_factory_.GetWeakPtr(), account_id));
} }
UpdateLoginStatus();
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnUserSessionAdded(account_id); observer.OnUserSessionAdded(account_id);
} }
...@@ -570,8 +571,8 @@ LoginStatus SessionController::CalculateLoginStatusForActiveSession() const { ...@@ -570,8 +571,8 @@ LoginStatus SessionController::CalculateLoginStatusForActiveSession() const {
switch (user_sessions_[0]->user_info->type) { switch (user_sessions_[0]->user_info->type) {
case user_manager::USER_TYPE_REGULAR: case user_manager::USER_TYPE_REGULAR:
// TODO: This needs to distinguish between owner and non-owner. return user_sessions_[0]->user_info->is_device_owner ? LoginStatus::OWNER
return LoginStatus::USER; : LoginStatus::USER;
case user_manager::USER_TYPE_GUEST: case user_manager::USER_TYPE_GUEST:
return LoginStatus::GUEST; return LoginStatus::GUEST;
case user_manager::USER_TYPE_PUBLIC_ACCOUNT: case user_manager::USER_TYPE_PUBLIC_ACCOUNT:
......
...@@ -302,6 +302,26 @@ TEST_F(SessionControllerTest, GetLoginStateForActiveSession) { ...@@ -302,6 +302,26 @@ TEST_F(SessionControllerTest, GetLoginStateForActiveSession) {
} }
} }
TEST_F(SessionControllerTest, GetLoginStateForOwner) {
// Simulate an active user session.
mojom::SessionInfo info;
FillDefaultSessionInfo(&info);
info.state = SessionState::ACTIVE;
SetSessionInfo(info);
mojom::UserSessionPtr session = mojom::UserSession::New();
session->session_id = 1u;
session->user_info = mojom::UserInfo::New();
session->user_info->type = user_manager::USER_TYPE_REGULAR;
session->user_info->account_id = AccountId::FromUserEmail("owner@test.com");
session->user_info->display_name = "Owner";
session->user_info->display_email = "owner@test.com";
session->user_info->is_device_owner = true;
controller()->UpdateUserSession(std::move(session));
EXPECT_EQ(LoginStatus::OWNER, controller()->login_status());
}
// Tests that user sessions can be set and updated. // Tests that user sessions can be set and updated.
TEST_F(SessionControllerTest, UserSessions) { TEST_F(SessionControllerTest, UserSessions) {
EXPECT_FALSE(controller()->IsActiveUserSessionStarted()); EXPECT_FALSE(controller()->IsActiveUserSessionStarted());
......
...@@ -243,10 +243,6 @@ void FakeChromeUserManager::SwitchActiveUser(const AccountId& account_id) { ...@@ -243,10 +243,6 @@ void FakeChromeUserManager::SwitchActiveUser(const AccountId& account_id) {
} }
} }
const AccountId& FakeChromeUserManager::GetOwnerAccountId() const {
return owner_account_id_;
}
void FakeChromeUserManager::OnSessionStarted() {} void FakeChromeUserManager::OnSessionStarted() {}
void FakeChromeUserManager::OnProfileInitialized(user_manager::User* user) { void FakeChromeUserManager::OnProfileInitialized(user_manager::User* user) {
...@@ -327,6 +323,10 @@ void FakeChromeUserManager::UpdateLoginState( ...@@ -327,6 +323,10 @@ void FakeChromeUserManager::UpdateLoginState(
is_current_user_owner); is_current_user_owner);
} }
void FakeChromeUserManager::SetOwnerId(const AccountId& account_id) {
UserManagerBase::SetOwnerId(account_id);
}
bool FakeChromeUserManager::GetPlatformKnownUserId( bool FakeChromeUserManager::GetPlatformKnownUserId(
const std::string& user_email, const std::string& user_email,
const std::string& gaia_id, const std::string& gaia_id,
...@@ -531,7 +531,7 @@ void FakeChromeUserManager::UpdateUserAccountData( ...@@ -531,7 +531,7 @@ void FakeChromeUserManager::UpdateUserAccountData(
} }
bool FakeChromeUserManager::IsCurrentUserOwner() const { bool FakeChromeUserManager::IsCurrentUserOwner() const {
return false; return active_user_ && GetOwnerAccountId() == active_user_->GetAccountId();
} }
bool FakeChromeUserManager::IsCurrentUserNew() const { bool FakeChromeUserManager::IsCurrentUserNew() const {
......
...@@ -66,7 +66,6 @@ class FakeChromeUserManager : public ChromeUserManager { ...@@ -66,7 +66,6 @@ class FakeChromeUserManager : public ChromeUserManager {
const user_manager::UserList& GetLoggedInUsers() const override; const user_manager::UserList& GetLoggedInUsers() const override;
const user_manager::UserList& GetLRULoggedInUsers() const override; const user_manager::UserList& GetLRULoggedInUsers() const override;
user_manager::UserList GetUnlockUsers() const override; user_manager::UserList GetUnlockUsers() const override;
const AccountId& GetOwnerAccountId() const override;
void UserLoggedIn(const AccountId& account_id, void UserLoggedIn(const AccountId& account_id,
const std::string& user_id_hash, const std::string& user_id_hash,
bool browser_restart, bool browser_restart,
...@@ -162,6 +161,7 @@ class FakeChromeUserManager : public ChromeUserManager { ...@@ -162,6 +161,7 @@ class FakeChromeUserManager : public ChromeUserManager {
void UpdateLoginState(const user_manager::User* active_user, void UpdateLoginState(const user_manager::User* active_user,
const user_manager::User* primary_user, const user_manager::User* primary_user,
bool is_current_user_owner) const override; bool is_current_user_owner) const override;
void SetOwnerId(const AccountId& account_id) override;
// UserManagerInterface override. // UserManagerInterface override.
MultiProfileUserController* GetMultiProfileUserController() override; MultiProfileUserController* GetMultiProfileUserController() override;
...@@ -184,8 +184,9 @@ class FakeChromeUserManager : public ChromeUserManager { ...@@ -184,8 +184,9 @@ class FakeChromeUserManager : public ChromeUserManager {
fake_ephemeral_users_enabled_ = ephemeral_users_enabled; fake_ephemeral_users_enabled_ = ephemeral_users_enabled;
} }
// TODO(mukai): remove this.
void set_owner_id(const AccountId& owner_account_id) { void set_owner_id(const AccountId& owner_account_id) {
owner_account_id_ = owner_account_id; SetOwnerId(owner_account_id);
} }
void set_multi_profile_user_controller( void set_multi_profile_user_controller(
...@@ -210,7 +211,6 @@ class FakeChromeUserManager : public ChromeUserManager { ...@@ -210,7 +211,6 @@ class FakeChromeUserManager : public ChromeUserManager {
user_manager::User* GetActiveUserInternal() const; user_manager::User* GetActiveUserInternal() const;
std::unique_ptr<FakeSupervisedUserManager> supervised_user_manager_; std::unique_ptr<FakeSupervisedUserManager> supervised_user_manager_;
AccountId owner_account_id_ = EmptyAccountId();
bool fake_ephemeral_users_enabled_ = false; bool fake_ephemeral_users_enabled_ = false;
bool current_user_new_ = false; bool current_user_new_ = false;
bool current_user_ephemeral_ = false; bool current_user_ephemeral_ = false;
......
...@@ -99,6 +99,9 @@ ash::mojom::UserSessionPtr UserToUserSession(const User& user) { ...@@ -99,6 +99,9 @@ ash::mojom::UserSessionPtr UserToUserSession(const User& user) {
session->user_info->display_email = user.display_email(); session->user_info->display_email = user.display_email();
session->user_info->is_ephemeral = session->user_info->is_ephemeral =
UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user.GetAccountId()); UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user.GetAccountId());
const AccountId& owner_id = UserManager::Get()->GetOwnerAccountId();
session->user_info->is_device_owner =
owner_id.is_valid() && owner_id == user.GetAccountId();
if (profile) { if (profile) {
session->user_info->service_user_id = session->user_info->service_user_id =
content::BrowserContext::GetServiceUserIdFor(profile); content::BrowserContext::GetServiceUserIdFor(profile);
...@@ -169,6 +172,7 @@ SessionControllerClient::SessionControllerClient() ...@@ -169,6 +172,7 @@ SessionControllerClient::SessionControllerClient()
SessionManager::Get()->AddObserver(this); SessionManager::Get()->AddObserver(this);
UserManager::Get()->AddSessionStateObserver(this); UserManager::Get()->AddSessionStateObserver(this);
UserManager::Get()->AddObserver(this); UserManager::Get()->AddObserver(this);
chromeos::LoginState::Get()->AddObserver(this);
registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
...@@ -201,6 +205,7 @@ SessionControllerClient::~SessionControllerClient() { ...@@ -201,6 +205,7 @@ SessionControllerClient::~SessionControllerClient() {
->RemoveObserver(this); ->RemoveObserver(this);
} }
chromeos::LoginState::Get()->RemoveObserver(this);
SessionManager::Get()->RemoveObserver(this); SessionManager::Get()->RemoveObserver(this);
UserManager::Get()->RemoveObserver(this); UserManager::Get()->RemoveObserver(this);
UserManager::Get()->RemoveSessionStateObserver(this); UserManager::Get()->RemoveSessionStateObserver(this);
...@@ -484,6 +489,10 @@ void SessionControllerClient::OnCustodianInfoChanged() { ...@@ -484,6 +489,10 @@ void SessionControllerClient::OnCustodianInfoChanged() {
SendUserSession(*user); SendUserSession(*user);
} }
void SessionControllerClient::LoggedInStateChanged() {
SendUserSession(*UserManager::Get()->GetActiveUser());
}
void SessionControllerClient::Observe( void SessionControllerClient::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/policy/off_hours/device_off_hours_controller.h" #include "chrome/browser/chromeos/policy/off_hours/device_off_hours_controller.h"
#include "chrome/browser/supervised_user/supervised_user_service_observer.h" #include "chrome/browser/supervised_user/supervised_user_service_observer.h"
#include "chromeos/login/login_state.h"
#include "components/session_manager/core/session_manager_observer.h" #include "components/session_manager/core/session_manager_observer.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
...@@ -40,6 +41,7 @@ class SessionControllerClient ...@@ -40,6 +41,7 @@ class SessionControllerClient
public user_manager::UserManager::Observer, public user_manager::UserManager::Observer,
public session_manager::SessionManagerObserver, public session_manager::SessionManagerObserver,
public SupervisedUserServiceObserver, public SupervisedUserServiceObserver,
public chromeos::LoginState::Observer,
public content::NotificationObserver, public content::NotificationObserver,
public policy::off_hours::DeviceOffHoursController::Observer { public policy::off_hours::DeviceOffHoursController::Observer {
public: public:
...@@ -95,6 +97,9 @@ class SessionControllerClient ...@@ -95,6 +97,9 @@ class SessionControllerClient
// SupervisedUserServiceObserver: // SupervisedUserServiceObserver:
void OnCustodianInfoChanged() override; void OnCustodianInfoChanged() override;
// chromeos::LoginState::Observer:
void LoggedInStateChanged() override;
// content::NotificationObserver: // content::NotificationObserver:
void Observe(int type, void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
...@@ -120,6 +125,8 @@ class SessionControllerClient ...@@ -120,6 +125,8 @@ class SessionControllerClient
FRIEND_TEST_ALL_PREFIXES(SessionControllerClientTest, SupervisedUser); FRIEND_TEST_ALL_PREFIXES(SessionControllerClientTest, SupervisedUser);
FRIEND_TEST_ALL_PREFIXES(SessionControllerClientTest, UserPrefsChange); FRIEND_TEST_ALL_PREFIXES(SessionControllerClientTest, UserPrefsChange);
FRIEND_TEST_ALL_PREFIXES(SessionControllerClientTest, SessionLengthLimit); FRIEND_TEST_ALL_PREFIXES(SessionControllerClientTest, SessionLengthLimit);
FRIEND_TEST_ALL_PREFIXES(SessionControllerClientTest, DeviceOwner);
FRIEND_TEST_ALL_PREFIXES(SessionControllerClientTest, UserBecomesDeviceOwner);
// Called when the login profile is ready. // Called when the login profile is ready.
void OnLoginUserProfilePrepared(Profile* profile); void OnLoginUserProfilePrepared(Profile* profile);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
#include "chromeos/login/login_state.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/session_manager/core/session_manager.h" #include "components/session_manager/core/session_manager.h"
...@@ -72,6 +73,7 @@ class TestChromeUserManager : public FakeChromeUserManager { ...@@ -72,6 +73,7 @@ class TestChromeUserManager : public FakeChromeUserManager {
FakeChromeUserManager::UserLoggedIn(account_id, user_id_hash, FakeChromeUserManager::UserLoggedIn(account_id, user_id_hash,
browser_restart, is_child); browser_restart, is_child);
active_user_ = const_cast<user_manager::User*>(FindUser(account_id)); active_user_ = const_cast<user_manager::User*>(FindUser(account_id));
NotifyUserAddedToSession(active_user_, false);
NotifyOnLogin(); NotifyOnLogin();
} }
...@@ -180,6 +182,7 @@ class SessionControllerClientTest : public testing::Test { ...@@ -180,6 +182,7 @@ class SessionControllerClientTest : public testing::Test {
void SetUp() override { void SetUp() override {
testing::Test::SetUp(); testing::Test::SetUp();
chromeos::LoginState::Initialize();
// Initialize the UserManager singleton. // Initialize the UserManager singleton.
user_manager_ = new TestChromeUserManager; user_manager_ = new TestChromeUserManager;
...@@ -209,6 +212,7 @@ class SessionControllerClientTest : public testing::Test { ...@@ -209,6 +212,7 @@ class SessionControllerClientTest : public testing::Test {
// PolicyCertService::Shutdown()). // PolicyCertService::Shutdown()).
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
chromeos::LoginState::Shutdown();
testing::Test::TearDown(); testing::Test::TearDown();
} }
...@@ -565,6 +569,50 @@ TEST_F(SessionControllerClientTest, SupervisedUser) { ...@@ -565,6 +569,50 @@ TEST_F(SessionControllerClientTest, SupervisedUser) {
session_controller.last_user_session()->custodian_email); session_controller.last_user_session()->custodian_email);
} }
TEST_F(SessionControllerClientTest, DeviceOwner) {
// Create an object to test and connect it to our test interface.
SessionControllerClient client;
TestSessionController session_controller;
client.session_controller_ = session_controller.CreateInterfacePtrAndBind();
client.Init();
const AccountId owner =
AccountId::FromUserEmailGaiaId("owner@test.com", "1111111111");
const AccountId normal_user =
AccountId::FromUserEmailGaiaId("user@test.com", "2222222222");
user_manager()->SetOwnerId(owner);
UserAddedToSession(owner);
SessionControllerClient::FlushForTesting();
EXPECT_TRUE(
session_controller.last_user_session()->user_info->is_device_owner);
UserAddedToSession(normal_user);
SessionControllerClient::FlushForTesting();
EXPECT_FALSE(
session_controller.last_user_session()->user_info->is_device_owner);
}
TEST_F(SessionControllerClientTest, UserBecomesDeviceOwner) {
// Create an object to test and connect it to our test interface.
SessionControllerClient client;
TestSessionController session_controller;
client.session_controller_ = session_controller.CreateInterfacePtrAndBind();
client.Init();
const AccountId owner =
AccountId::FromUserEmailGaiaId("owner@test.com", "1111111111");
UserAddedToSession(owner);
SessionControllerClient::FlushForTesting();
// The device owner is empty, the current session shouldn't be the owner.
EXPECT_FALSE(
session_controller.last_user_session()->user_info->is_device_owner);
user_manager()->SetOwnerId(owner);
SessionControllerClient::FlushForTesting();
EXPECT_TRUE(
session_controller.last_user_session()->user_info->is_device_owner);
}
TEST_F(SessionControllerClientTest, UserPrefsChange) { TEST_F(SessionControllerClientTest, UserPrefsChange) {
// Create an object to test and connect it to our test interface. // Create an object to test and connect it to our test interface.
SessionControllerClient client; SessionControllerClient client;
......
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