OLD | NEW |
---|---|
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/files/file_path.h" | |
8 #include "base/files/file_util.h" | |
9 #include "base/path_service.h" | |
10 #include "base/threading/thread_restrictions.h" | |
11 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | |
12 #include "chromeos/chromeos_paths.h" | |
13 #include "components/policy/proto/device_management_backend.pb.h" | |
14 | |
15 namespace em = enterprise_management; | |
16 | |
6 namespace chromeos { | 17 namespace chromeos { |
7 | 18 |
8 FakeAuthPolicyClient::FakeAuthPolicyClient() {} | 19 FakeAuthPolicyClient::FakeAuthPolicyClient() {} |
9 | 20 |
10 FakeAuthPolicyClient::~FakeAuthPolicyClient() {} | 21 FakeAuthPolicyClient::~FakeAuthPolicyClient() {} |
11 | 22 |
12 void FakeAuthPolicyClient::Init(dbus::Bus* bus) {} | 23 void FakeAuthPolicyClient::Init(dbus::Bus* bus) {} |
13 | 24 |
14 void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name, | 25 void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name, |
15 const std::string& user, | 26 const std::string& user, |
16 int password_fd, | 27 int password_fd, |
17 const JoinCallback& callback) { | 28 const JoinCallback& callback) { |
18 callback.Run(authpolicy::AD_JOIN_ERROR_NONE); | 29 callback.Run(authpolicy::AD_JOIN_ERROR_NONE); |
19 } | 30 } |
20 | 31 |
21 void FakeAuthPolicyClient::RefreshDevicePolicy( | 32 void FakeAuthPolicyClient::RefreshDevicePolicy( |
22 const RefreshPolicyCallback& callback) { | 33 const RefreshPolicyCallback& callback) { |
23 callback.Run(true); | 34 // Create minimal stub device policy file and drop it at the place where |
24 }; | 35 // SessionManagerClientStubImpl is looking for it. |
36 em::ChromeDeviceSettingsProto policy; | |
37 em::PolicyData data; | |
38 policy.SerializeToString(data.mutable_policy_value()); | |
39 data.set_policy_type("google/chromeos/device"); | |
40 | |
41 em::PolicyFetchResponse response; | |
42 data.SerializeToString(response.mutable_policy_data()); | |
43 std::string serialized_response; | |
44 response.SerializeToString(&serialized_response); | |
45 | |
46 base::FilePath owner_key_path; | |
47 if (!PathService::Get(FILE_OWNER_KEY, &owner_key_path)) { | |
48 callback.Run(false); | |
49 return; | |
50 } | |
51 base::FilePath device_policy_path = | |
achuithb
2016/11/28 09:05:51
nit const
Thiemo Nagel
2016/11/30 19:11:58
Done.
| |
52 owner_key_path.DirName().AppendASCII("stub_device_policy"); | |
53 | |
54 base::ThreadRestrictions::ScopedAllowIO permit_io_within_current_scope; | |
Thiemo Nagel
2016/11/25 15:07:03
Do I really need to post to a different thread in
achuithb
2016/11/28 09:05:51
Yeah, pretty sure you can't use this. Isn't there
| |
55 int bytes_written = | |
achuithb
2016/11/28 09:05:51
nit const
Thiemo Nagel
2016/11/30 19:11:58
That variable has been removed.
| |
56 base::WriteFile(device_policy_path, serialized_response.c_str(), | |
57 serialized_response.size()); | |
58 callback.Run(bytes_written != -1); | |
59 } | |
25 | 60 |
26 void FakeAuthPolicyClient::RefreshUserPolicy( | 61 void FakeAuthPolicyClient::RefreshUserPolicy( |
27 const std::string& account_id, | 62 const std::string& account_id, |
28 const RefreshPolicyCallback& callback) { | 63 const RefreshPolicyCallback& callback) { |
29 callback.Run(true); | 64 callback.Run(true); |
30 }; | 65 } |
31 | 66 |
32 } // namespace chromeos | 67 } // namespace chromeos |
OLD | NEW |