Chromium Code Reviews| Index: chrome/browser/ui/ash/session_controller_client.cc |
| diff --git a/chrome/browser/ui/ash/session_controller_client.cc b/chrome/browser/ui/ash/session_controller_client.cc |
| index 693ad99d7eb2ba529957e2d79a080588b3f3b4f7..8c56c944cf534bb604049f2e53710c61394dc049 100644 |
| --- a/chrome/browser/ui/ash/session_controller_client.cc |
| +++ b/chrome/browser/ui/ash/session_controller_client.cc |
| @@ -18,6 +18,9 @@ |
| #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.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/supervised_user/supervised_user_service.h" |
| +#include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| #include "chrome/browser/ui/ash/multi_user/user_switch_util.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/grit/theme_resources.h" |
| @@ -54,7 +57,8 @@ uint32_t GetSessionId(const User& user) { |
| // Creates a mojom::UserSession for the given user. Returns nullptr if there is |
| // no user session started for the given user. |
| -ash::mojom::UserSessionPtr UserToUserSession(const User& user) { |
| +ash::mojom::UserSessionPtr UserToUserSession(const User& user, |
| + Profile* login_profile) { |
| const uint32_t user_session_id = GetSessionId(user); |
| if (user_session_id == 0u) |
| return nullptr; |
| @@ -72,6 +76,13 @@ ash::mojom::UserSessionPtr UserToUserSession(const User& user) { |
| IDR_PROFILE_PICTURE_LOADING); |
| } |
| + if (user.IsSupervised() && login_profile) { |
| + SupervisedUserService* service = |
| + SupervisedUserServiceFactory::GetForProfile(login_profile); |
| + session->custodian_email = service->GetCustodianEmailAddress(); |
| + session->second_custodian_email = service->GetSecondCustodianEmailAddress(); |
| + } |
| + |
| chromeos::UserFlow* const user_flow = |
| chromeos::ChromeUserManager::Get()->GetUserFlow(user.GetAccountId()); |
| session->should_enable_settings = user_flow->ShouldEnableSettings(); |
| @@ -94,11 +105,8 @@ SessionControllerClient::SessionControllerClient() : binding_(this) { |
| registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| content::NotificationService::AllSources()); |
| - |
| - ConnectToSessionControllerAndSetClient(); |
| - SendSessionInfoIfChanged(); |
| - // User sessions and their order will be sent via UserSessionStateObserver |
| - // even for crash-n-restart. |
| + registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| + content::NotificationService::AllSources()); |
| DCHECK(!g_instance); |
| g_instance = this; |
| @@ -108,11 +116,23 @@ SessionControllerClient::~SessionControllerClient() { |
| DCHECK_EQ(this, g_instance); |
| g_instance = nullptr; |
| + if (login_profile_) { |
| + SupervisedUserServiceFactory::GetForProfile(login_profile_) |
| + ->RemoveObserver(this); |
| + } |
| SessionManager::Get()->RemoveObserver(this); |
| UserManager::Get()->RemoveObserver(this); |
| UserManager::Get()->RemoveSessionStateObserver(this); |
| } |
| +void SessionControllerClient::Init() { |
| + ConnectToSessionController(); |
| + session_controller_->SetClient(binding_.CreateInterfacePtrAndBind()); |
| + SendSessionInfoIfChanged(); |
| + // User sessions and their order will be sent via UserSessionStateObserver |
| + // even for crash-n-restart. |
| +} |
| + |
| // static |
| SessionControllerClient* SessionControllerClient::Get() { |
| return g_instance; |
| @@ -273,21 +293,51 @@ void SessionControllerClient::OnSessionStateChanged() { |
| SendSessionInfoIfChanged(); |
| } |
| +void SessionControllerClient::OnCustodianInfoChanged() { |
| + SendActiveUserSession(); |
|
xiyuan
2017/04/21 23:14:35
Is this safe because supervised user is not allowe
James Cook
2017/04/24 17:47:26
How does this look?
xiyuan
2017/04/24 18:10:09
Looks good.
|
| +} |
| + |
| void SessionControllerClient::Observe( |
| int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| - DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type); |
| - session_controller_->NotifyChromeTerminating(); |
| + switch (type) { |
| + case chrome::NOTIFICATION_APP_TERMINATING: |
| + session_controller_->NotifyChromeTerminating(); |
| + break; |
| + case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: { |
| + Profile* profile = content::Details<Profile>(details).ptr(); |
| + OnLoginUserProfilePrepared(profile); |
| + break; |
| + } |
| + default: |
| + NOTREACHED() << "Unexpected notification " << type; |
| + break; |
| + } |
| +} |
| + |
| +void SessionControllerClient::OnLoginUserProfilePrepared(Profile* profile) { |
| + DCHECK(!login_profile_); |
| + login_profile_ = profile; |
| + |
| + // Update the user session data with information from the profile. |
| + SendActiveUserSession(); |
| + |
| + // Watch for changes to supervised user manager/custodians. Supervised users |
| + // cannot use multiprofile so we don't need to worry about profile switching |
| + // and adding/removing observers. |
| + SupervisedUserServiceFactory::GetForProfile(login_profile_) |
| + ->AddObserver(this); |
| } |
| -void SessionControllerClient::ConnectToSessionControllerAndSetClient() { |
| +void SessionControllerClient::ConnectToSessionController() { |
| + // Tests may bind to their own SessionController. |
| + if (session_controller_) |
| + return; |
| + |
| content::ServiceManagerConnection::GetForProcess() |
| ->GetConnector() |
| ->BindInterface(ash::mojom::kServiceName, &session_controller_); |
| - |
| - // Set as |session_controller_|'s client. |
| - session_controller_->SetClient(binding_.CreateInterfacePtrAndBind()); |
| } |
| void SessionControllerClient::SendSessionInfoIfChanged() { |
| @@ -306,7 +356,8 @@ void SessionControllerClient::SendSessionInfoIfChanged() { |
| } |
| void SessionControllerClient::SendUserSession(const User& user) { |
| - ash::mojom::UserSessionPtr user_session = UserToUserSession(user); |
| + ash::mojom::UserSessionPtr user_session = |
| + UserToUserSession(user, login_profile_); |
| // Bail if the user has no session. Currently the only code path that hits |
| // this condition is from OnUserImageChanged when user images are changed |
| @@ -315,9 +366,17 @@ void SessionControllerClient::SendUserSession(const User& user) { |
| if (!user_session) |
| return; |
| + // TODO(jamescook): Only send if it changed. This will require an Equals() |
| + // method for gfx::ImageSkia to allow mojom::UserSession comparison. |
|
xiyuan
2017/04/21 23:14:35
We can use ImageSkia::BackedBySameObjectAs to impl
James Cook
2017/04/24 17:47:26
Is it OK if I do this in a separate CL?
|
| session_controller_->UpdateUserSession(std::move(user_session)); |
| } |
| +void SessionControllerClient::SendActiveUserSession() { |
| + User* active_user = UserManager::Get()->GetActiveUser(); |
| + DCHECK(active_user); |
| + SendUserSession(*active_user); |
| +} |
| + |
| void SessionControllerClient::SendUserSessionOrder() { |
| UserManager* const user_manager = UserManager::Get(); |