summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-06 01:21:21 +0000
committermnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-06 01:21:21 +0000
commit328a9784a4f4b1790eeb2c223d4773c0d4904d4c (patch)
treee35ec478f163a28a68b0224d361343b4fa36d82a
parenta2b886affc41cc08c10e712b5985d0bb6afd8b25 (diff)
downloadchromium_src-328a9784a4f4b1790eeb2c223d4773c0d4904d4c.zip
chromium_src-328a9784a4f4b1790eeb2c223d4773c0d4904d4c.tar.gz
chromium_src-328a9784a4f4b1790eeb2c223d4773c0d4904d4c.tar.bz2
Implement GetServerBackedStateKeys API in SessionManagerClient.
This call is used to request the current server-backed state keys from session_manager. BUG=chromium:358213 TEST=None Review URL: https://codereview.chromium.org/240373003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268360 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/settings/device_settings_test_helper.cc3
-rw-r--r--chrome/browser/chromeos/settings/device_settings_test_helper.h2
-rw-r--r--chromeos/dbus/fake_session_manager_client.cc6
-rw-r--r--chromeos/dbus/fake_session_manager_client.h11
-rw-r--r--chromeos/dbus/mock_session_manager_client.h1
-rw-r--r--chromeos/dbus/session_manager_client.cc60
-rw-r--r--chromeos/dbus/session_manager_client.h13
7 files changed, 96 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/settings/device_settings_test_helper.cc b/chrome/browser/chromeos/settings/device_settings_test_helper.cc
index 70acbd0..922dc29 100644
--- a/chrome/browser/chromeos/settings/device_settings_test_helper.cc
+++ b/chrome/browser/chromeos/settings/device_settings_test_helper.cc
@@ -181,6 +181,9 @@ void DeviceSettingsTestHelper::SetFlagsForUser(
const std::string& account_id,
const std::vector<std::string>& flags) {}
+void DeviceSettingsTestHelper::GetServerBackedStateKeys(
+ const StateKeysCallback& callback) {}
+
DeviceSettingsTestHelper::PolicyState::PolicyState()
: store_result_(true) {}
diff --git a/chrome/browser/chromeos/settings/device_settings_test_helper.h b/chrome/browser/chromeos/settings/device_settings_test_helper.h
index cb299d8..af683d0 100644
--- a/chrome/browser/chromeos/settings/device_settings_test_helper.h
+++ b/chrome/browser/chromeos/settings/device_settings_test_helper.h
@@ -119,6 +119,8 @@ class DeviceSettingsTestHelper : public SessionManagerClient {
virtual void SetFlagsForUser(
const std::string& account_id,
const std::vector<std::string>& flags) OVERRIDE;
+ virtual void GetServerBackedStateKeys(
+ const StateKeysCallback& callback) OVERRIDE;
private:
struct PolicyState {
diff --git a/chromeos/dbus/fake_session_manager_client.cc b/chromeos/dbus/fake_session_manager_client.cc
index ade94f52..e2f9404 100644
--- a/chromeos/dbus/fake_session_manager_client.cc
+++ b/chromeos/dbus/fake_session_manager_client.cc
@@ -135,6 +135,12 @@ void FakeSessionManagerClient::SetFlagsForUser(
const std::vector<std::string>& flags) {
}
+void FakeSessionManagerClient::GetServerBackedStateKeys(
+ const StateKeysCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, server_backed_state_keys_));
+}
+
const std::string& FakeSessionManagerClient::device_policy() const {
return device_policy_;
}
diff --git a/chromeos/dbus/fake_session_manager_client.h b/chromeos/dbus/fake_session_manager_client.h
index 1be814a..1a6c782 100644
--- a/chromeos/dbus/fake_session_manager_client.h
+++ b/chromeos/dbus/fake_session_manager_client.h
@@ -7,6 +7,7 @@
#include <map>
#include <string>
+#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
@@ -60,6 +61,8 @@ class FakeSessionManagerClient : public SessionManagerClient {
const StorePolicyCallback& callback) OVERRIDE;
virtual void SetFlagsForUser(const std::string& username,
const std::vector<std::string>& flags) OVERRIDE;
+ virtual void GetServerBackedStateKeys(const StateKeysCallback& callback)
+ OVERRIDE;
const std::string& device_policy() const;
void set_device_policy(const std::string& policy_blob);
@@ -76,6 +79,13 @@ class FakeSessionManagerClient : public SessionManagerClient {
// Notify observers about a property change completion.
void OnPropertyChangeComplete(bool success);
+ // Configures the list of state keys used to satisfy
+ // GetServerBackedStateKeys() requests.
+ void set_server_backed_state_keys(
+ const std::vector<std::string>& state_keys) {
+ server_backed_state_keys_ = state_keys;
+ }
+
int start_device_wipe_call_count() const {
return start_device_wipe_call_count_;
}
@@ -96,6 +106,7 @@ class FakeSessionManagerClient : public SessionManagerClient {
std::map<std::string, std::string> device_local_account_policy_;
ObserverList<Observer> observers_;
SessionManagerClient::ActiveSessionsMap user_sessions_;
+ std::vector<std::string> server_backed_state_keys_;
int start_device_wipe_call_count_;
int notify_lock_screen_shown_call_count_;
diff --git a/chromeos/dbus/mock_session_manager_client.h b/chromeos/dbus/mock_session_manager_client.h
index 7d679b8..6847ee0 100644
--- a/chromeos/dbus/mock_session_manager_client.h
+++ b/chromeos/dbus/mock_session_manager_client.h
@@ -54,6 +54,7 @@ class MockSessionManagerClient : public SessionManagerClient {
MOCK_METHOD2(SetFlagsForUser,
void(const std::string&,
const std::vector<std::string>&));
+ MOCK_METHOD1(GetServerBackedStateKeys, void(const StateKeysCallback&));
};
} // namespace chromeos
diff --git a/chromeos/dbus/session_manager_client.cc b/chromeos/dbus/session_manager_client.cc
index 44d1e0c..c5693a8 100644
--- a/chromeos/dbus/session_manager_client.cc
+++ b/chromeos/dbus/session_manager_client.cc
@@ -10,12 +10,14 @@
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/path_service.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task_runner_util.h"
#include "base/threading/worker_pool.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/blocking_method_caller.h"
#include "chromeos/dbus/cryptohome_client.h"
+#include "crypto/sha2.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_path.h"
@@ -269,6 +271,20 @@ class SessionManagerClientImpl : public SessionManagerClient {
dbus::ObjectProxy::EmptyResponseCallback());
}
+ virtual void GetServerBackedStateKeys(const StateKeysCallback& callback)
+ OVERRIDE {
+ dbus::MethodCall method_call(
+ login_manager::kSessionManagerInterface,
+ login_manager::kSessionManagerGetServerBackedStateKeys);
+
+ session_manager_proxy_->CallMethod(
+ &method_call,
+ dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&SessionManagerClientImpl::OnGetServerBackedStateKeys,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
+ }
+
protected:
virtual void Init(dbus::Bus* bus) OVERRIDE {
session_manager_proxy_ = bus->GetObjectProxy(
@@ -515,6 +531,39 @@ class SessionManagerClientImpl : public SessionManagerClient {
LOG_IF(ERROR, !success) << "Failed to connect to " << signal_name;
}
+ // Called when kSessionManagerGetServerBackedStateKeys method is complete.
+ void OnGetServerBackedStateKeys(const StateKeysCallback& callback,
+ dbus::Response* response) {
+ std::vector<std::string> state_keys;
+ if (!response) {
+ LOG(ERROR) << "Failed to call "
+ << login_manager::kSessionManagerStartSession;
+ } else {
+ dbus::MessageReader reader(response);
+ dbus::MessageReader array_reader(NULL);
+
+ if (!reader.PopArray(&array_reader)) {
+ LOG(ERROR) << "Bad response: " << response->ToString();
+ } else {
+ while (array_reader.HasMoreData()) {
+ const uint8* data = NULL;
+ size_t size = 0;
+ if (!array_reader.PopArrayOfBytes(&data, &size)) {
+ LOG(ERROR) << "Bad response: " << response->ToString();
+ state_keys.clear();
+ break;
+ }
+ state_keys.push_back(
+ std::string(reinterpret_cast<const char*>(data), size));
+ }
+ }
+ }
+
+ if (!callback.is_null())
+ callback.Run(state_keys);
+ }
+
+
dbus::ObjectProxy* session_manager_proxy_;
scoped_ptr<BlockingMethodCaller> blocking_method_caller_;
ObserverList<Observer> observers_;
@@ -681,6 +730,17 @@ class SessionManagerClientStubImpl : public SessionManagerClient {
virtual void SetFlagsForUser(const std::string& username,
const std::vector<std::string>& flags) OVERRIDE {
}
+
+ virtual void GetServerBackedStateKeys(const StateKeysCallback& callback)
+ OVERRIDE {
+ std::vector<std::string> state_keys;
+ for (int i = 0; i < 5; ++i)
+ state_keys.push_back(crypto::SHA256HashString(base::IntToString(i)));
+
+ if (!callback.is_null())
+ callback.Run(state_keys);
+ }
+
private:
StubDelegate* delegate_; // Weak pointer; may be NULL.
ObserverList<Observer> observers_;
diff --git a/chromeos/dbus/session_manager_client.h b/chromeos/dbus/session_manager_client.h
index 2a5792d..a9ae670 100644
--- a/chromeos/dbus/session_manager_client.h
+++ b/chromeos/dbus/session_manager_client.h
@@ -7,6 +7,7 @@
#include <map>
#include <string>
+#include <vector>
#include "base/callback.h"
#include "base/observer_list.h"
@@ -172,6 +173,18 @@ class CHROMEOS_EXPORT SessionManagerClient : public DBusClient {
virtual void SetFlagsForUser(const std::string& username,
const std::vector<std::string>& flags) = 0;
+ typedef base::Callback<void(const std::vector<std::string>& state_keys)>
+ StateKeysCallback;
+
+ // Get the currently valid server-backed state keys for the device.
+ // Server-backed state keys are opaque, device-unique, time-dependent,
+ // client-determined identifiers that are used for keying state in the cloud
+ // for the device to retrieve after a device factory reset.
+ //
+ // The state keys are returned asynchronously via |callback|. The callback
+ // will be invoked with an empty state key vector in case of errors.
+ virtual void GetServerBackedStateKeys(const StateKeysCallback& callback) = 0;
+
// Creates the instance.
static SessionManagerClient* Create(DBusClientImplementationType type);