| Index: chromeos/dbus/fake_auth_policy_client.cc
|
| diff --git a/chromeos/dbus/fake_auth_policy_client.cc b/chromeos/dbus/fake_auth_policy_client.cc
|
| index 0231e29fb2f6ccd1d6e9b67db672ce2d6b676710..a7c0fe053a454ff8320dd1eff112a4b3700e41be 100644
|
| --- a/chromeos/dbus/fake_auth_policy_client.cc
|
| +++ b/chromeos/dbus/fake_auth_policy_client.cc
|
| @@ -13,6 +13,7 @@
|
| #include "base/strings/string_split.h"
|
| #include "base/task_scheduler/post_task.h"
|
| #include "base/threading/platform_thread.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
|
| #include "chromeos/chromeos_paths.h"
|
| #include "chromeos/cryptohome/cryptohome_parameters.h"
|
| @@ -29,8 +30,8 @@ namespace {
|
| const size_t kMaxMachineNameLength = 15;
|
| const char kInvalidMachineNameCharacters[] = "\\/:*?\"<>|";
|
|
|
| -// Delay policy fetch to be more realistic.
|
| -constexpr int kPolicyFetchDelaySeconds = 5;
|
| +// Delay operations to be more realistic.
|
| +constexpr int kOperationDelaySeconds = 3;
|
|
|
| // Drop stub policy file of |policy_type| at |policy_path| containing
|
| // |serialized_payload|.
|
| @@ -38,7 +39,7 @@ bool WritePolicyFile(const base::FilePath& policy_path,
|
| const std::string& serialized_payload,
|
| const std::string& policy_type) {
|
| base::PlatformThread::Sleep(
|
| - base::TimeDelta::FromSeconds(kPolicyFetchDelaySeconds));
|
| + base::TimeDelta::FromSeconds(kOperationDelaySeconds));
|
|
|
| em::PolicyData data;
|
| data.set_policy_value(serialized_payload);
|
| @@ -62,6 +63,12 @@ bool WritePolicyFile(const base::FilePath& policy_path,
|
| return bytes_written == static_cast<int>(serialized_response.size());
|
| }
|
|
|
| +void PostDelayedClosure(base::OnceClosure closure) {
|
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
|
| + FROM_HERE, std::move(closure),
|
| + base::TimeDelta::FromSeconds(kOperationDelaySeconds));
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace chromeos {
|
| @@ -75,59 +82,53 @@ void FakeAuthPolicyClient::Init(dbus::Bus* bus) {}
|
| void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name,
|
| const std::string& user_principal_name,
|
| int password_fd,
|
| - const JoinCallback& callback) {
|
| + JoinCallback callback) {
|
| + authpolicy::ErrorType error = authpolicy::ERROR_NONE;
|
| if (!started_) {
|
| LOG(ERROR) << "authpolicyd not started";
|
| - callback.Run(authpolicy::ERROR_DBUS_FAILURE);
|
| - return;
|
| + error = authpolicy::ERROR_DBUS_FAILURE;
|
| + } else if (machine_name.size() > kMaxMachineNameLength) {
|
| + error = authpolicy::ERROR_MACHINE_NAME_TOO_LONG;
|
| + } else if (machine_name.empty() ||
|
| + machine_name.find_first_of(kInvalidMachineNameCharacters) !=
|
| + std::string::npos) {
|
| + error = authpolicy::ERROR_BAD_MACHINE_NAME;
|
| + } else {
|
| + std::vector<std::string> parts = base::SplitString(
|
| + user_principal_name, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
|
| + if (parts.size() != 2 || parts[0].empty() || parts[1].empty()) {
|
| + error = authpolicy::ERROR_PARSE_UPN_FAILED;
|
| + }
|
| }
|
| - if (machine_name.size() > kMaxMachineNameLength) {
|
| - callback.Run(authpolicy::ERROR_MACHINE_NAME_TOO_LONG);
|
| - return;
|
| - }
|
| -
|
| - if (machine_name.empty() ||
|
| - machine_name.find_first_of(kInvalidMachineNameCharacters) !=
|
| - std::string::npos) {
|
| - callback.Run(authpolicy::ERROR_BAD_MACHINE_NAME);
|
| - return;
|
| - }
|
| -
|
| - std::vector<std::string> parts = base::SplitString(
|
| - user_principal_name, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
|
| - if (parts.size() != 2 || parts[0].empty() || parts[1].empty()) {
|
| - callback.Run(authpolicy::ERROR_PARSE_UPN_FAILED);
|
| - return;
|
| - }
|
| -
|
| - callback.Run(authpolicy::ERROR_NONE);
|
| + PostDelayedClosure(base::BindOnce(std::move(callback), error));
|
| }
|
|
|
| void FakeAuthPolicyClient::AuthenticateUser(
|
| const std::string& user_principal_name,
|
| int password_fd,
|
| - const AuthCallback& callback) {
|
| + AuthCallback callback) {
|
| + authpolicy::ErrorType error = authpolicy::ERROR_NONE;
|
| authpolicy::ActiveDirectoryAccountData account_data;
|
| if (!started_) {
|
| LOG(ERROR) << "authpolicyd not started";
|
| - callback.Run(authpolicy::ERROR_DBUS_FAILURE, account_data);
|
| - return;
|
| + error = authpolicy::ERROR_DBUS_FAILURE;
|
| + } else {
|
| + if (auth_error_ == authpolicy::ERROR_NONE)
|
| + account_data.set_account_id(base::MD5String(user_principal_name));
|
| + error = auth_error_;
|
| }
|
| - if (auth_error_ == authpolicy::ERROR_NONE)
|
| - account_data.set_account_id(base::MD5String(user_principal_name));
|
| - callback.Run(auth_error_, account_data);
|
| + PostDelayedClosure(base::BindOnce(std::move(callback), error, account_data));
|
| }
|
|
|
| -void FakeAuthPolicyClient::RefreshDevicePolicy(
|
| - const RefreshPolicyCallback& callback) {
|
| +void FakeAuthPolicyClient::RefreshDevicePolicy(RefreshPolicyCallback callback) {
|
| if (!started_) {
|
| LOG(ERROR) << "authpolicyd not started";
|
| - callback.Run(false);
|
| + std::move(callback).Run(false);
|
| return;
|
| }
|
| base::FilePath policy_path;
|
| if (!PathService::Get(chromeos::FILE_OWNER_KEY, &policy_path)) {
|
| - callback.Run(false);
|
| + std::move(callback).Run(false);
|
| return;
|
| }
|
| policy_path = policy_path.DirName().AppendASCII("stub_device_policy");
|
| @@ -138,26 +139,27 @@ void FakeAuthPolicyClient::RefreshDevicePolicy(
|
|
|
| // Drop file for SessionManagerClientStubImpl to read.
|
| base::PostTaskWithTraitsAndReplyWithResult(
|
| - FROM_HERE, base::TaskTraits()
|
| - .WithShutdownBehavior(
|
| - base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
|
| - .WithPriority(base::TaskPriority::BACKGROUND)
|
| - .MayBlock(),
|
| - Bind(&WritePolicyFile, policy_path, payload, "google/chromeos/device"),
|
| - callback);
|
| + FROM_HERE,
|
| + base::TaskTraits()
|
| + .WithShutdownBehavior(
|
| + base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
|
| + .WithPriority(base::TaskPriority::BACKGROUND)
|
| + .MayBlock(),
|
| + base::BindOnce(&WritePolicyFile, policy_path, payload,
|
| + "google/chromeos/device"),
|
| + std::move(callback));
|
| }
|
|
|
| -void FakeAuthPolicyClient::RefreshUserPolicy(
|
| - const AccountId& account_id,
|
| - const RefreshPolicyCallback& callback) {
|
| +void FakeAuthPolicyClient::RefreshUserPolicy(const AccountId& account_id,
|
| + RefreshPolicyCallback callback) {
|
| if (!started_) {
|
| LOG(ERROR) << "authpolicyd not started";
|
| - callback.Run(false);
|
| + std::move(callback).Run(false);
|
| return;
|
| }
|
| base::FilePath policy_path;
|
| if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &policy_path)) {
|
| - callback.Run(false);
|
| + std::move(callback).Run(false);
|
| return;
|
| }
|
| const cryptohome::Identification cryptohome_identification(account_id);
|
| @@ -173,14 +175,15 @@ void FakeAuthPolicyClient::RefreshUserPolicy(
|
|
|
| // Drop file for SessionManagerClientStubImpl to read.
|
| base::PostTaskWithTraitsAndReplyWithResult(
|
| - FROM_HERE, base::TaskTraits()
|
| - .WithShutdownBehavior(
|
| - base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
|
| - .WithPriority(base::TaskPriority::BACKGROUND)
|
| - .MayBlock(),
|
| - base::Bind(&WritePolicyFile, policy_path, payload,
|
| - "google/chromeos/user"),
|
| - callback);
|
| + FROM_HERE,
|
| + base::TaskTraits()
|
| + .WithShutdownBehavior(
|
| + base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
|
| + .WithPriority(base::TaskPriority::BACKGROUND)
|
| + .MayBlock(),
|
| + base::BindOnce(&WritePolicyFile, policy_path, payload,
|
| + "google/chromeos/user"),
|
| + std::move(callback));
|
| }
|
|
|
| } // namespace chromeos
|
|
|