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

Unified Diff: chromeos/dbus/session_manager_client.cc

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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: chromeos/dbus/session_manager_client.cc
diff --git a/chromeos/dbus/session_manager_client.cc b/chromeos/dbus/session_manager_client.cc
index 0854875d0aeb974c262b0a34963aaf48c4d79c3c..273f84c0f7edd0075f7b0dd30510d41b570d031c 100644
--- a/chromeos/dbus/session_manager_client.cc
+++ b/chromeos/dbus/session_manager_client.cc
@@ -19,6 +19,7 @@
#include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/blocking_method_caller.h"
#include "chromeos/dbus/cryptohome_client.h"
+#include "components/user_manager/user_id.h"
#include "crypto/sha2.h"
#include "dbus/bus.h"
#include "dbus/message.h"
@@ -34,13 +35,13 @@ namespace {
// Returns a location for |file| that is specific to the given |username|.
// These paths will be relative to DIR_USER_POLICY_KEYS, and can be used only
// to store stub files.
-base::FilePath GetUserFilePath(const std::string& username, const char* file) {
+base::FilePath GetUserFilePath(const user_manager::UserID& user_id, const char* file) {
base::FilePath keys_path;
if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &keys_path))
return base::FilePath();
- const std::string sanitized =
- CryptohomeClient::GetStubSanitizedUsername(username);
- return keys_path.AppendASCII(sanitized).AppendASCII(file);
+ const std::string hash =
+ CryptohomeClient::GetStubSanitizedUsername(user_id);
+ return keys_path.AppendASCII(hash).AppendASCII(file);
}
// Helper to asynchronously retrieve a file's content.
@@ -150,11 +151,11 @@ class SessionManagerClientImpl : public SessionManagerClient {
false);
}
- void StartSession(const std::string& user_email) override {
+ void StartSession(const user_manager::UserID& user_id) override {
dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
login_manager::kSessionManagerStartSession);
dbus::MessageWriter writer(&method_call);
- writer.AppendString(user_email);
+ writer.AppendString(user_id.GetUserEmail());
writer.AppendString(""); // Unique ID is deprecated
session_manager_proxy_->CallMethod(
&method_call,
@@ -235,21 +236,21 @@ class SessionManagerClientImpl : public SessionManagerClient {
callback));
}
- void RetrievePolicyForUser(const std::string& username,
+ void RetrievePolicyForUser(const user_manager::UserID& user_id,
const RetrievePolicyCallback& callback) override {
CallRetrievePolicyByUsername(
login_manager::kSessionManagerRetrievePolicyForUser,
- username,
+ user_id.GetUserEmail(),
callback);
}
std::string BlockingRetrievePolicyForUser(
- const std::string& username) override {
+ const user_manager::UserID& user_id) override {
dbus::MethodCall method_call(
login_manager::kSessionManagerInterface,
login_manager::kSessionManagerRetrievePolicyForUser);
dbus::MessageWriter writer(&method_call);
- writer.AppendString(username);
+ writer.AppendString(user_id.GetUserEmail());
scoped_ptr<dbus::Response> response =
blocking_method_caller_->CallMethodAndBlock(&method_call);
std::string policy;
@@ -285,11 +286,11 @@ class SessionManagerClientImpl : public SessionManagerClient {
callback));
}
- void StorePolicyForUser(const std::string& username,
+ void StorePolicyForUser(const user_manager::UserID& user_id,
const std::string& policy_blob,
const StorePolicyCallback& callback) override {
CallStorePolicyByUsername(login_manager::kSessionManagerStorePolicyForUser,
- username,
+ user_id.GetUserEmail(),
policy_blob,
callback);
}
@@ -305,12 +306,12 @@ class SessionManagerClientImpl : public SessionManagerClient {
callback);
}
- void SetFlagsForUser(const std::string& username,
+ void SetFlagsForUser(const user_manager::UserID& user_id,
const std::vector<std::string>& flags) override {
dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
login_manager::kSessionManagerSetFlagsForUser);
dbus::MessageWriter writer(&method_call);
- writer.AppendString(username);
+ writer.AppendString(user_id.GetUserEmail());
writer.AppendArrayOfStrings(flags);
session_manager_proxy_->CallMethod(
&method_call,
@@ -383,9 +384,10 @@ class SessionManagerClientImpl : public SessionManagerClient {
}
// Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser.
+ // |username| is either UserEmail or DeviceLocalAccountID.
void CallRetrievePolicyByUsername(const std::string& method_name,
- const std::string& username,
- const RetrievePolicyCallback& callback) {
+ const std::string& username,
+ const RetrievePolicyCallback& callback) {
dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
method_name);
dbus::MessageWriter writer(&method_call);
@@ -400,10 +402,11 @@ class SessionManagerClientImpl : public SessionManagerClient {
callback));
}
+ // |username| is either UserEmail or DeviceLocalAccountID.
void CallStorePolicyByUsername(const std::string& method_name,
- const std::string& username,
- const std::string& policy_blob,
- const StorePolicyCallback& callback) {
+ const std::string& username,
+ const std::string& policy_blob,
+ const StorePolicyCallback& callback) {
dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
method_name);
dbus::MessageWriter writer(&method_call);
@@ -505,7 +508,8 @@ class SessionManagerClientImpl : public SessionManagerClient {
LOG(ERROR) << method_name << " response is incorrect: "
<< response->ToString();
} else {
- sessions[key] = value;
+ const user_manager::UserID user_id(std::string() /* gaia_id */, key);
+ sessions[user_id] = value;
}
}
success = true;
@@ -669,7 +673,7 @@ class SessionManagerClientStubImpl : public SessionManagerClient {
bool IsScreenLocked() const override { return screen_is_locked_; }
void EmitLoginPromptVisible() override {}
void RestartJob(int pid, const std::string& command_line) override {}
- void StartSession(const std::string& user_email) override {}
+ void StartSession(const user_manager::UserID& user_id) override {}
void StopSession() override {}
void NotifySupervisedUserCreationStarted() override {}
void NotifySupervisedUserCreationFinished() override {}
@@ -702,22 +706,23 @@ class SessionManagerClientStubImpl : public SessionManagerClient {
base::Bind(&GetFileContent, device_policy_path),
callback);
}
- void RetrievePolicyForUser(const std::string& username,
+ void RetrievePolicyForUser(const user_manager::UserID& user_id,
const RetrievePolicyCallback& callback) override {
base::PostTaskAndReplyWithResult(
base::WorkerPool::GetTaskRunner(false).get(),
FROM_HERE,
- base::Bind(&GetFileContent, GetUserFilePath(username, "stub_policy")),
+ base::Bind(&GetFileContent, GetUserFilePath(user_id, "stub_policy")),
callback);
}
std::string BlockingRetrievePolicyForUser(
- const std::string& username) override {
- return GetFileContent(GetUserFilePath(username, "stub_policy"));
+ const user_manager::UserID& user_id) override {
+ return GetFileContent(GetUserFilePath(user_id, "stub_policy"));
}
void RetrieveDeviceLocalAccountPolicy(
const std::string& account_name,
const RetrievePolicyCallback& callback) override {
- RetrievePolicyForUser(account_name, callback);
+ const user_manager::UserID fake_user_id(std::string() /* gaia_id */, account_name);
+ RetrievePolicyForUser(fake_user_id, callback);
}
void StoreDevicePolicy(const std::string& policy_blob,
const StorePolicyCallback& callback) override {
@@ -749,7 +754,7 @@ class SessionManagerClientStubImpl : public SessionManagerClient {
base::Bind(callback, true),
false);
}
- void StorePolicyForUser(const std::string& username,
+ void StorePolicyForUser(const user_manager::UserID& user_id,
const std::string& policy_blob,
const StorePolicyCallback& callback) override {
// The session manager writes the user policy key to a well-known
@@ -762,7 +767,7 @@ class SessionManagerClientStubImpl : public SessionManagerClient {
}
if (response.has_new_public_key()) {
- base::FilePath key_path = GetUserFilePath(username, "policy.pub");
+ base::FilePath key_path = GetUserFilePath(user_id, "policy.pub");
base::WorkerPool::PostTask(
FROM_HERE,
base::Bind(&StoreFile, key_path, response.new_public_key()),
@@ -771,7 +776,7 @@ class SessionManagerClientStubImpl : public SessionManagerClient {
// This file isn't read directly by Chrome, but is used by this class to
// reload the user policy across restarts.
- base::FilePath stub_policy_path = GetUserFilePath(username, "stub_policy");
+ base::FilePath stub_policy_path = GetUserFilePath(user_id, "stub_policy");
base::WorkerPool::PostTaskAndReply(
FROM_HERE,
base::Bind(&StoreFile, stub_policy_path, policy_blob),
@@ -782,9 +787,10 @@ class SessionManagerClientStubImpl : public SessionManagerClient {
const std::string& account_name,
const std::string& policy_blob,
const StorePolicyCallback& callback) override {
- StorePolicyForUser(account_name, policy_blob, callback);
+ const user_manager::UserID fake_user_id(std::string() /* gaia_id */, account_name);
+ StorePolicyForUser(fake_user_id, policy_blob, callback);
}
- void SetFlagsForUser(const std::string& username,
+ void SetFlagsForUser(const user_manager::UserID& user_id,
const std::vector<std::string>& flags) override {}
void GetServerBackedStateKeys(const StateKeysCallback& callback) override {

Powered by Google App Engine
This is Rietveld 408576698