Chromium Code Reviews| 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..9da03eb28128da8d472d9c0cf1923fe1d39e5338 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,11 @@ bool WritePolicyFile(const base::FilePath& policy_path, |
| return bytes_written == static_cast<int>(serialized_response.size()); |
| } |
| +void PostDelayedClosure(const base::Closure& closure) { |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, closure, base::TimeDelta::FromSeconds(kOperationDelaySeconds)); |
| +} |
| + |
| } // namespace |
| namespace chromeos { |
| @@ -78,29 +84,32 @@ void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name, |
| const JoinCallback& callback) { |
| if (!started_) { |
|
ljusten (tachyonic)
2017/03/31 15:19:33
This would get rid of a bunch of repetitions:
if
Roman Sorokin (ftl)
2017/04/04 10:10:49
Done.
|
| LOG(ERROR) << "authpolicyd not started"; |
| - callback.Run(authpolicy::ERROR_DBUS_FAILURE); |
| + PostDelayedClosure(base::Bind(callback, authpolicy::ERROR_DBUS_FAILURE)); |
| return; |
| } |
| if (machine_name.size() > kMaxMachineNameLength) { |
| - callback.Run(authpolicy::ERROR_MACHINE_NAME_TOO_LONG); |
| + PostDelayedClosure( |
| + base::Bind(callback, 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); |
| + PostDelayedClosure( |
| + base::Bind(callback, 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); |
| + PostDelayedClosure( |
| + base::Bind(callback, authpolicy::ERROR_PARSE_UPN_FAILED)); |
| return; |
| } |
| - callback.Run(authpolicy::ERROR_NONE); |
| + PostDelayedClosure(base::Bind(callback, authpolicy::ERROR_NONE)); |
| } |
| void FakeAuthPolicyClient::AuthenticateUser( |
| @@ -110,12 +119,13 @@ void FakeAuthPolicyClient::AuthenticateUser( |
| authpolicy::ActiveDirectoryAccountData account_data; |
| if (!started_) { |
| LOG(ERROR) << "authpolicyd not started"; |
| - callback.Run(authpolicy::ERROR_DBUS_FAILURE, account_data); |
| + PostDelayedClosure( |
| + base::Bind(callback, authpolicy::ERROR_DBUS_FAILURE, account_data)); |
| return; |
| } |
| if (auth_error_ == authpolicy::ERROR_NONE) |
| account_data.set_account_id(base::MD5String(user_principal_name)); |
| - callback.Run(auth_error_, account_data); |
| + PostDelayedClosure(base::Bind(callback, auth_error_, account_data)); |
| } |
| void FakeAuthPolicyClient::RefreshDevicePolicy( |