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

Side by Side Diff: chromeos/dbus/fake_auth_policy_client.cc

Issue 2531063002: Implement FakeAuthPolicyClient::RefreshDevicePolicy() (Closed)
Patch Set: Polish Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4
4 #include "chromeos/dbus/fake_auth_policy_client.h" 5 #include "chromeos/dbus/fake_auth_policy_client.h"
5 6
7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/location.h"
11 #include "base/path_service.h"
12 #include "base/task_runner_util.h"
13 #include "base/threading/worker_pool.h"
14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
15 #include "chromeos/chromeos_paths.h"
16 #include "components/policy/proto/device_management_backend.pb.h"
17
18 namespace em = enterprise_management;
19
6 namespace chromeos { 20 namespace chromeos {
7 21
8 FakeAuthPolicyClient::FakeAuthPolicyClient() {} 22 FakeAuthPolicyClient::FakeAuthPolicyClient() {}
9 23
10 FakeAuthPolicyClient::~FakeAuthPolicyClient() {} 24 FakeAuthPolicyClient::~FakeAuthPolicyClient() {}
11 25
12 void FakeAuthPolicyClient::Init(dbus::Bus* bus) {} 26 void FakeAuthPolicyClient::Init(dbus::Bus* bus) {}
13 27
14 void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name, 28 void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name,
15 const std::string& user, 29 const std::string& user,
16 int password_fd, 30 int password_fd,
17 const JoinCallback& callback) { 31 const JoinCallback& callback) {
18 callback.Run(authpolicy::AD_JOIN_ERROR_NONE); 32 callback.Run(authpolicy::AD_JOIN_ERROR_NONE);
19 } 33 }
20 34
21 void FakeAuthPolicyClient::RefreshDevicePolicy( 35 void FakeAuthPolicyClient::RefreshDevicePolicy(
22 const RefreshPolicyCallback& callback) { 36 const RefreshPolicyCallback& callback) {
23 callback.Run(true); 37 if (!base::PostTaskAndReplyWithResult(
24 }; 38 base::WorkerPool::GetTaskRunner(false /* task_is_slow */).get(),
39 FROM_HERE, base::Bind(&FakeAuthPolicyClient::WriteDevicePolicyFile),
40 base::Bind(&FakeAuthPolicyClient::OnDevicePolicyFileWritten,
41 weak_factory_.GetWeakPtr(), callback))) {
42 callback.Run(false);
43 }
44 }
45
46 // static
47 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.
48 // Create minimal stub device policy file and drop it at the place where
49 // SessionManagerClientStubImpl is looking for it.
50 em::ChromeDeviceSettingsProto policy;
51 em::PolicyData data;
52 policy.SerializeToString(data.mutable_policy_value());
53 data.set_policy_type("google/chromeos/device");
54
55 em::PolicyFetchResponse response;
56 data.SerializeToString(response.mutable_policy_data());
57 std::string serialized_response;
58 response.SerializeToString(&serialized_response);
59
60 base::FilePath owner_key_path;
61 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.
62 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.
63 }
64 const base::FilePath device_policy_path =
65 owner_key_path.DirName().AppendASCII("stub_device_policy");
66
67 // Note that in theory there could be a short time window in which a
68 // concurrent reader sees a partial (and thus invalid) file, but given the
69 // small file size that seems very unlikely in practice.
70 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
71 serialized_response.size());
72 }
73
74 void FakeAuthPolicyClient::OnDevicePolicyFileWritten(
75 const RefreshPolicyCallback& callback,
76 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.
77 callback.Run(bytes_written != -1);
78 }
25 79
26 void FakeAuthPolicyClient::RefreshUserPolicy( 80 void FakeAuthPolicyClient::RefreshUserPolicy(
27 const std::string& account_id, 81 const std::string& account_id,
28 const RefreshPolicyCallback& callback) { 82 const RefreshPolicyCallback& callback) {
29 callback.Run(true); 83 callback.Run(true);
30 }; 84 }
31 85
32 } // namespace chromeos 86 } // namespace chromeos
OLDNEW
« chromeos/dbus/fake_auth_policy_client.h ('K') | « chromeos/dbus/fake_auth_policy_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698