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 edcf52857d7b7d204e333fc71bf0a3470840f50b..32bf318ffab6245ecdabfd166081bff456f006ac 100644 |
--- a/chromeos/dbus/fake_auth_policy_client.cc |
+++ b/chromeos/dbus/fake_auth_policy_client.cc |
@@ -1,8 +1,22 @@ |
// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+ |
#include "chromeos/dbus/fake_auth_policy_client.h" |
+#include "base/bind.h" |
+#include "base/files/file_path.h" |
+#include "base/files/file_util.h" |
+#include "base/location.h" |
+#include "base/path_service.h" |
+#include "base/task_runner_util.h" |
+#include "base/threading/worker_pool.h" |
+#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
+#include "chromeos/chromeos_paths.h" |
+#include "components/policy/proto/device_management_backend.pb.h" |
+ |
+namespace em = enterprise_management; |
+ |
namespace chromeos { |
FakeAuthPolicyClient::FakeAuthPolicyClient() {} |
@@ -20,13 +34,53 @@ void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name, |
void FakeAuthPolicyClient::RefreshDevicePolicy( |
const RefreshPolicyCallback& callback) { |
- callback.Run(true); |
-}; |
+ if (!base::PostTaskAndReplyWithResult( |
+ base::WorkerPool::GetTaskRunner(false /* task_is_slow */).get(), |
+ FROM_HERE, base::Bind(&FakeAuthPolicyClient::WriteDevicePolicyFile), |
+ base::Bind(&FakeAuthPolicyClient::OnDevicePolicyFileWritten, |
+ weak_factory_.GetWeakPtr(), callback))) { |
+ callback.Run(false); |
+ } |
+} |
+ |
+// static |
+int FakeAuthPolicyClient::WriteDevicePolicyFile() { |
achuithb
2016/11/30 19:23:34
move to anonymous namespace.
I think it's better
Thiemo Nagel
2016/11/30 20:06:36
Done.
|
+ // Create minimal stub device policy file and drop it at the place where |
+ // SessionManagerClientStubImpl is looking for it. |
+ em::ChromeDeviceSettingsProto policy; |
+ em::PolicyData data; |
+ policy.SerializeToString(data.mutable_policy_value()); |
+ data.set_policy_type("google/chromeos/device"); |
+ |
+ em::PolicyFetchResponse response; |
+ data.SerializeToString(response.mutable_policy_data()); |
+ std::string serialized_response; |
+ response.SerializeToString(&serialized_response); |
+ |
+ base::FilePath owner_key_path; |
+ if (!PathService::Get(FILE_OWNER_KEY, &owner_key_path)) { |
achuithb
2016/11/30 19:23:34
Drop {}
Thiemo Nagel
2016/11/30 20:06:36
Done.
|
+ return -1; |
achuithb
2016/11/30 19:23:34
I think you should return false here.
Thiemo Nagel
2016/11/30 20:06:36
Done.
|
+ } |
+ const base::FilePath device_policy_path = |
+ owner_key_path.DirName().AppendASCII("stub_device_policy"); |
+ |
+ // Note that in theory there could be a short time window in which a |
+ // concurrent reader sees a partial (and thus invalid) file, but given the |
+ // small file size that seems very unlikely in practice. |
+ return base::WriteFile(device_policy_path, serialized_response.c_str(), |
achuithb
2016/11/30 19:23:34
I think you should return
base::WriteFile(...) ==
Thiemo Nagel
2016/11/30 20:06:36
Done. (Due to type mismatch some more code is nee
|
+ serialized_response.size()); |
+} |
+ |
+void FakeAuthPolicyClient::OnDevicePolicyFileWritten( |
+ const RefreshPolicyCallback& callback, |
+ int bytes_written) { |
achuithb
2016/11/30 19:23:34
I'd change this to bool success or something simil
Thiemo Nagel
2016/11/30 20:06:36
Done.
|
+ callback.Run(bytes_written != -1); |
+} |
void FakeAuthPolicyClient::RefreshUserPolicy( |
const std::string& account_id, |
const RefreshPolicyCallback& callback) { |
callback.Run(true); |
-}; |
+} |
} // namespace chromeos |