summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus
diff options
context:
space:
mode:
authornkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-23 16:10:16 +0000
committernkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-23 16:10:16 +0000
commit0fbe5d660903cdf965b5982f60ac31e24e5fa236 (patch)
treec64a11acc0bafa7a571b1a8c1e614c665e5a766f /chromeos/dbus
parent8549668280f4f2fdf1042d7dd9ff2d7ebe17be8c (diff)
downloadchromium_src-0fbe5d660903cdf965b5982f60ac31e24e5fa236.zip
chromium_src-0fbe5d660903cdf965b5982f60ac31e24e5fa236.tar.gz
chromium_src-0fbe5d660903cdf965b5982f60ac31e24e5fa236.tar.bz2
Call session_manager RetrieveActiveSessions on restart after crash
Depends on https://codereview.chromium.org/15566003/ BUG=238998 NOTRY=true Review URL: https://chromiumcodereview.appspot.com/15576002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201814 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus')
-rw-r--r--chromeos/dbus/fake_session_manager_client.cc9
-rw-r--r--chromeos/dbus/fake_session_manager_client.h2
-rw-r--r--chromeos/dbus/mock_session_manager_client.h1
-rw-r--r--chromeos/dbus/session_manager_client.cc54
-rw-r--r--chromeos/dbus/session_manager_client.h24
5 files changed, 88 insertions, 2 deletions
diff --git a/chromeos/dbus/fake_session_manager_client.cc b/chromeos/dbus/fake_session_manager_client.cc
index 166f564..e979c00 100644
--- a/chromeos/dbus/fake_session_manager_client.cc
+++ b/chromeos/dbus/fake_session_manager_client.cc
@@ -69,6 +69,15 @@ void FakeSessionManagerClient::NotifyLockScreenDismissed() {
notify_lock_screen_dismissed_call_count_++;
}
+void FakeSessionManagerClient::RetrieveActiveSessions(
+ const ActiveSessionsCallback& callback) {
+ ActiveSessionsMap sessions;
+ MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(callback,
+ sessions,
+ true));
+}
+
void FakeSessionManagerClient::RetrieveDevicePolicy(
const RetrievePolicyCallback& callback) {
MessageLoop::current()->PostTask(FROM_HERE,
diff --git a/chromeos/dbus/fake_session_manager_client.h b/chromeos/dbus/fake_session_manager_client.h
index 88c048c7..6ff37cc 100644
--- a/chromeos/dbus/fake_session_manager_client.h
+++ b/chromeos/dbus/fake_session_manager_client.h
@@ -37,6 +37,8 @@ class FakeSessionManagerClient : public chromeos::SessionManagerClient {
virtual void NotifyLockScreenShown() OVERRIDE;
virtual void RequestUnlockScreen() OVERRIDE;
virtual void NotifyLockScreenDismissed() OVERRIDE;
+ virtual void RetrieveActiveSessions(
+ const ActiveSessionsCallback& callback) OVERRIDE;
virtual void RetrieveDevicePolicy(
const RetrievePolicyCallback& callback) OVERRIDE;
virtual void RetrievePolicyForUser(
diff --git a/chromeos/dbus/mock_session_manager_client.h b/chromeos/dbus/mock_session_manager_client.h
index f5b915f..c57d5d1 100644
--- a/chromeos/dbus/mock_session_manager_client.h
+++ b/chromeos/dbus/mock_session_manager_client.h
@@ -31,6 +31,7 @@ class MockSessionManagerClient : public SessionManagerClient {
MOCK_METHOD0(NotifyLockScreenShown, void(void));
MOCK_METHOD0(RequestUnlockScreen, void(void));
MOCK_METHOD0(NotifyLockScreenDismissed, void(void));
+ MOCK_METHOD1(RetrieveActiveSessions, void(const ActiveSessionsCallback&));
MOCK_METHOD1(RetrieveDevicePolicy, void(const RetrievePolicyCallback&));
MOCK_METHOD2(RetrievePolicyForUser,
void(const std::string&,
diff --git a/chromeos/dbus/session_manager_client.cc b/chromeos/dbus/session_manager_client.cc
index 646c495..0c23f43 100644
--- a/chromeos/dbus/session_manager_client.cc
+++ b/chromeos/dbus/session_manager_client.cc
@@ -186,6 +186,21 @@ class SessionManagerClientImpl : public SessionManagerClient {
login_manager::kSessionManagerHandleLockScreenDismissed);
}
+ virtual void RetrieveActiveSessions(
+ const ActiveSessionsCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(
+ login_manager::kSessionManagerInterface,
+ login_manager::kSessionManagerRetrieveActiveSessions);
+
+ session_manager_proxy_->CallMethod(
+ &method_call,
+ dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&SessionManagerClientImpl::OnRetrieveActiveSessions,
+ weak_ptr_factory_.GetWeakPtr(),
+ login_manager::kSessionManagerRetrieveActiveSessions,
+ callback));
+ }
+
virtual void RetrieveDevicePolicy(
const RetrievePolicyCallback& callback) OVERRIDE {
dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
@@ -335,6 +350,43 @@ class SessionManagerClientImpl : public SessionManagerClient {
<< login_manager::kSessionManagerStartDeviceWipe;
}
+ // Called when kSessionManagerRetrieveActiveSessions method is complete.
+ void OnRetrieveActiveSessions(const std::string& method_name,
+ const ActiveSessionsCallback& callback,
+ dbus::Response* response) {
+ ActiveSessionsMap sessions;
+ bool success = false;
+ if (!response) {
+ LOG(ERROR) << "Failed to call " << method_name;
+ callback.Run(sessions, success);
+ return;
+ }
+
+ dbus::MessageReader reader(response);
+ dbus::MessageReader array_reader(NULL);
+
+ if (!reader.PopArray(&array_reader)) {
+ LOG(ERROR) << method_name << " response is incorrect: "
+ << response->ToString();
+ } else {
+ while (array_reader.HasMoreData()) {
+ dbus::MessageReader dict_entry_reader(NULL);
+ std::string key;
+ std::string value;
+ if (!array_reader.PopDictEntry(&dict_entry_reader) ||
+ !dict_entry_reader.PopString(&key) ||
+ !dict_entry_reader.PopString(&value)) {
+ LOG(ERROR) << method_name << " response is incorrect: "
+ << response->ToString();
+ } else {
+ sessions[key] = value;
+ }
+ }
+ success = true;
+ }
+ callback.Run(sessions, success);
+ }
+
// Called when kSessionManagerRetrievePolicy or
// kSessionManagerRetrievePolicyForUser method is complete.
void OnRetrievePolicy(const std::string& method_name,
@@ -483,6 +535,8 @@ class SessionManagerClientStubImpl : public SessionManagerClient {
virtual void NotifyLockScreenDismissed() OVERRIDE {
FOR_EACH_OBSERVER(Observer, observers_, ScreenIsUnlocked());
}
+ virtual void RetrieveActiveSessions(
+ const ActiveSessionsCallback& callback) OVERRIDE {}
virtual void RetrieveDevicePolicy(
const RetrievePolicyCallback& callback) OVERRIDE {
callback.Run(device_policy_);
diff --git a/chromeos/dbus/session_manager_client.h b/chromeos/dbus/session_manager_client.h
index 64eaefa..70ca3f4 100644
--- a/chromeos/dbus/session_manager_client.h
+++ b/chromeos/dbus/session_manager_client.h
@@ -5,13 +5,14 @@
#ifndef CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_
#define CHROMEOS_DBUS_SESSION_MANAGER_CLIENT_H_
+#include <map>
+#include <string>
+
#include "base/callback.h"
#include "base/observer_list.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/dbus_client_implementation_type.h"
-#include <string>
-
namespace dbus {
class Bus;
} // namespace
@@ -89,6 +90,25 @@ class CHROMEOS_EXPORT SessionManagerClient {
// Notifies that the lock screen is dismissed.
virtual void NotifyLockScreenDismissed() = 0;
+ // Map that is used to describe the set of active user sessions where |key|
+ // is user_id and |value| is user_id_hash.
+ typedef std::map<std::string, std::string> ActiveSessionsMap;
+
+ // The ActiveSessionsCallback is used for the RetrieveActiveSessions()
+ // method. It receives |sessions| argument where the keys are user_ids for
+ // all users that are currently active and |success| argument which indicates
+ // whether or not the request succeded.
+ typedef base::Callback<void(const ActiveSessionsMap& sessions,
+ bool success)> ActiveSessionsCallback;
+
+ // Enumerates active user sessions. Usually Chrome naturally keeps track of
+ // active users when they are added into current session. When Chrome is
+ // restarted after crash by session_manager it only receives user_id and
+ // user_id_hash for one user. This method is used to retrieve list of all
+ // active users.
+ virtual void RetrieveActiveSessions(
+ const ActiveSessionsCallback& callback) = 0;
+
// Used for RetrieveDevicePolicy, RetrievePolicyForUser and
// RetrieveDeviceLocalAccountPolicy. Takes a serialized protocol buffer as
// string. Upon success, we will pass a protobuf to the callback. On