Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Unified Diff: chrome/browser/ui/ash/session_controller_client.cc

Issue 2878723002: Merge "cros: Update ash when prefs related to lock are changed" (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_);
« no previous file with comments | « chrome/browser/ui/ash/session_controller_client.h ('k') | chrome/browser/ui/ash/session_controller_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698