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 696beea7bbe550cc7a42cb7011e68df6d4717842..0309d50847d180a4d8b2239b14b4338527767177 100644 |
--- a/chrome/browser/ui/ash/session_controller_client.cc |
+++ b/chrome/browser/ui/ash/session_controller_client.cc |
@@ -12,6 +12,8 @@ |
#include "base/bind.h" |
#include "base/logging.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "base/threading/thread_task_runner_handle.h" |
+#include "chrome/browser/chrome_notification_types.h" |
#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" |
@@ -20,8 +22,10 @@ |
#include "chrome/grit/theme_resources.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
#include "chromeos/dbus/session_manager_client.h" |
+#include "components/prefs/pref_change_registrar.h" |
#include "components/prefs/pref_service.h" |
#include "components/session_manager/core/session_manager.h" |
+#include "content/public/browser/notification_service.h" |
#include "content/public/common/service_manager_connection.h" |
#include "content/public/common/service_names.mojom.h" |
#include "services/service_manager/public/cpp/connector.h" |
@@ -77,20 +81,27 @@ void DoSwitchUser(const AccountId& account_id) { |
} // namespace |
-SessionControllerClient::SessionControllerClient() : binding_(this) { |
+SessionControllerClient::SessionControllerClient() |
+ : binding_(this), weak_ptr_factory_(this) { |
SessionManager::Get()->AddObserver(this); |
UserManager::Get()->AddSessionStateObserver(this); |
UserManager::Get()->AddObserver(this); |
- 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; |
} |
+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. |
+} |
+ |
SessionControllerClient::~SessionControllerClient() { |
DCHECK_EQ(this, g_instance); |
g_instance = nullptr; |
@@ -256,7 +267,44 @@ void SessionControllerClient::OnSessionStateChanged() { |
SendSessionInfoIfChanged(); |
} |
-void SessionControllerClient::ConnectToSessionControllerAndSetClient() { |
+void SessionControllerClient::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ switch (type) { |
+ 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) { |
+ const User* user = chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
+ DCHECK(user); |
+ |
+ base::Closure session_info_changed_closure = |
+ base::Bind(&SessionControllerClient::SendSessionInfoIfChanged, |
+ weak_ptr_factory_.GetWeakPtr()); |
+ std::unique_ptr<PrefChangeRegistrar> pref_change_registrar = |
+ base::MakeUnique<PrefChangeRegistrar>(); |
+ pref_change_registrar->Init(profile->GetPrefs()); |
+ pref_change_registrar->Add(prefs::kAllowScreenLock, |
+ session_info_changed_closure); |
+ pref_change_registrar->Add(prefs::kEnableAutoScreenLock, |
+ session_info_changed_closure); |
+ pref_change_registrars_.push_back(std::move(pref_change_registrar)); |
+} |
+ |
+void SessionControllerClient::ConnectToSessionController() { |
+ // Tests may bind to their own SessionController. |
+ if (session_controller_) |
+ return; |
+ |
content::ServiceManagerConnection::GetForProcess() |
->GetConnector() |
->BindInterface(ash::mojom::kServiceName, &session_controller_); |