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

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

Issue 231123002: Notify about major session changes events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tests Created 6 years, 8 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_state_delegate_chromeos.cc
diff --git a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc
index 2341781f58215f13df01b9658a63e56a04f33597..c71f5c5c005669c434fc230e9dd3965184ccac59 100644
--- a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc
+++ b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc
@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
+#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/screen_locker.h"
#include "chrome/browser/chromeos/login/user.h"
#include "chrome/browser/chromeos/login/user_adding_screen.h"
@@ -20,13 +21,31 @@
#include "chromeos/chromeos_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
+#include "chromeos/login/login_state.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
#include "google_apis/gaia/gaia_auth_util.h"
-SessionStateDelegateChromeos::SessionStateDelegateChromeos() {
+SessionStateDelegateChromeos::SessionStateDelegateChromeos()
+ : session_state_(STATE_UNKNOWN) {
Daniel Erat 2014/04/10 16:30:32 it'd be better to have a separate "initialized" me
Nikita (slow) 2014/04/10 17:22:51 Done.
+ chromeos::LoginState::Get()->AddObserver(this);
+ chromeos::DBusThreadManager::Get()->
+ GetSessionManagerClient()->AddObserver(this);
chromeos::UserManager::Get()->AddSessionStateObserver(this);
+ chromeos::UserAddingScreen::Get()->AddObserver(this);
+ notification_registrar_.Add(this,
+ chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
+ content::NotificationService::AllSources());
+ LoggedInStateChanged();
}
SessionStateDelegateChromeos::~SessionStateDelegateChromeos() {
+ chromeos::LoginState::Get()->RemoveObserver(this);
+ chromeos::DBusThreadManager::Get()->
+ GetSessionManagerClient()->RemoveObserver(this);
+ chromeos::UserManager::Get()->RemoveSessionStateObserver(this);
+ chromeos::UserAddingScreen::Get()->RemoveObserver(this);
}
content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex(
@@ -111,6 +130,11 @@ bool SessionStateDelegateChromeos::IsUserSessionBlocked() const {
chromeos::UserAddingScreen::Get()->IsRunning();
}
+ash::SessionStateDelegate::SessionState
+SessionStateDelegateChromeos::GetSessionState() const {
+ return session_state_;
+}
+
const base::string16 SessionStateDelegateChromeos::GetUserDisplayName(
ash::MultiProfileIndex index) const {
DCHECK_LT(index, NumberOfLoggedInUsers());
@@ -208,8 +232,24 @@ void SessionStateDelegateChromeos::RemoveSessionStateObserver(
session_state_observer_list_.RemoveObserver(observer);
}
+void SessionStateDelegateChromeos::LoggedInStateChanged() {
+ if (chromeos::LoginState::Get()->IsUserLoggedIn())
+ SetSessionState(STATE_SESSION);
Daniel Erat 2014/04/10 16:30:32 nit: SetSessionState(chromeos::LoginState::Get(
Nikita (slow) 2014/04/10 17:22:51 Done.
+ else
+ SetSessionState(STATE_LOGIN_PRIMARY);
+}
+
+void SessionStateDelegateChromeos::ScreenIsLocked() {
+ SetSessionState(STATE_LOCK);
+}
+
+void SessionStateDelegateChromeos::ScreenIsUnlocked() {
+ SetSessionState(STATE_SESSION);
+}
+
void SessionStateDelegateChromeos::ActiveUserChanged(
const chromeos::User* active_user) {
+ SetSessionState(STATE_SESSION);
Daniel Erat 2014/04/10 16:30:32 why is this necessary? shouldn't LoggedInStateChan
Nikita (slow) 2014/04/10 17:22:51 Done.
Nikita (slow) 2014/04/10 17:22:51 Done.
FOR_EACH_OBSERVER(ash::SessionStateObserver,
session_state_observer_list_,
ActiveUserChanged(active_user->email()));
@@ -217,7 +257,47 @@ void SessionStateDelegateChromeos::ActiveUserChanged(
void SessionStateDelegateChromeos::UserAddedToSession(
const chromeos::User* added_user) {
+ SetSessionState(STATE_SESSION);
Daniel Erat 2014/04/10 16:30:32 why is this necessary? shouldn't OnUserAddingFinis
Nikita (slow) 2014/04/10 17:22:51 Done.
FOR_EACH_OBSERVER(ash::SessionStateObserver,
session_state_observer_list_,
UserAddedToSession(added_user->email()));
}
+
+void SessionStateDelegateChromeos::OnUserAddingStarted() {
+ SetSessionState(STATE_LOGIN_SECONDARY);
+}
+
+void SessionStateDelegateChromeos::OnUserAddingFinished() {
+ SetSessionState(STATE_SESSION);
+}
+
+void SessionStateDelegateChromeos::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: {
Daniel Erat 2014/04/10 16:30:32 this seems ugly. do we really need to watch for bo
Nikita (slow) 2014/04/10 17:22:51 Turns out ScreenLockerTest only creates ScreenLock
+ bool locked = *content::Details<bool>(details).ptr();
+ SetSessionState(locked ? STATE_LOCK : STATE_SESSION);
+ break;
+ }
+ default: {
+ NOTREACHED() << "Unknown notification type";
+ break;
+ }
+ }
+}
+
+void SessionStateDelegateChromeos::SetSessionState(SessionState new_state) {
+ if (session_state_ == new_state)
+ return;
+
+ session_state_ = new_state;
+ NotifySessionStateChanged();
+}
+
+void SessionStateDelegateChromeos::NotifySessionStateChanged() {
+ FOR_EACH_OBSERVER(ash::SessionStateObserver,
+ session_state_observer_list_,
+ SessionStateChanged(session_state_));
+}

Powered by Google App Engine
This is Rietveld 408576698