| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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 |
| 5 #include "chromeos/dbus/fake_auth_policy_client.h" | 5 #include "chromeos/dbus/fake_auth_policy_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/md5.h" | 11 #include "base/md5.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/task_runner_util.h" | 13 #include "base/task_scheduler/post_task.h" |
| 14 #include "base/threading/worker_pool.h" | |
| 15 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 16 #include "chromeos/chromeos_paths.h" | 15 #include "chromeos/chromeos_paths.h" |
| 17 #include "chromeos/cryptohome/cryptohome_parameters.h" | 16 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 18 #include "chromeos/dbus/cryptohome_client.h" | 17 #include "chromeos/dbus/cryptohome_client.h" |
| 19 #include "components/policy/proto/cloud_policy.pb.h" | 18 #include "components/policy/proto/cloud_policy.pb.h" |
| 20 #include "components/policy/proto/device_management_backend.pb.h" | 19 #include "components/policy/proto/device_management_backend.pb.h" |
| 21 #include "components/signin/core/account_id/account_id.h" | 20 #include "components/signin/core/account_id/account_id.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 23 | 22 |
| 24 namespace em = enterprise_management; | 23 namespace em = enterprise_management; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 callback.Run(false); | 82 callback.Run(false); |
| 84 return; | 83 return; |
| 85 } | 84 } |
| 86 policy_path = policy_path.DirName().AppendASCII("stub_device_policy"); | 85 policy_path = policy_path.DirName().AppendASCII("stub_device_policy"); |
| 87 | 86 |
| 88 em::ChromeDeviceSettingsProto policy; | 87 em::ChromeDeviceSettingsProto policy; |
| 89 std::string payload; | 88 std::string payload; |
| 90 CHECK(policy.SerializeToString(&payload)); | 89 CHECK(policy.SerializeToString(&payload)); |
| 91 | 90 |
| 92 // Drop file for SessionManagerClientStubImpl to read. | 91 // Drop file for SessionManagerClientStubImpl to read. |
| 93 if (!base::PostTaskAndReplyWithResult( | 92 base::PostTaskWithTraitsAndReplyWithResult( |
| 94 base::WorkerPool::GetTaskRunner(false /* task_is_slow */).get(), | 93 FROM_HERE, base::TaskTraits() |
| 95 FROM_HERE, base::Bind(&WritePolicyFile, policy_path, payload, | 94 .WithShutdownBehavior( |
| 96 "google/chromeos/device"), | 95 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 97 callback)) { | 96 .WithPriority(base::TaskPriority::BACKGROUND) |
| 98 callback.Run(false); | 97 .MayBlock(), |
| 99 } | 98 Bind(&WritePolicyFile, policy_path, payload, "google/chromeos/device"), |
| 99 callback); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void FakeAuthPolicyClient::RefreshUserPolicy( | 102 void FakeAuthPolicyClient::RefreshUserPolicy( |
| 103 const AccountId& account_id, | 103 const AccountId& account_id, |
| 104 const RefreshPolicyCallback& callback) { | 104 const RefreshPolicyCallback& callback) { |
| 105 base::FilePath policy_path; | 105 base::FilePath policy_path; |
| 106 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &policy_path)) { | 106 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &policy_path)) { |
| 107 callback.Run(false); | 107 callback.Run(false); |
| 108 return; | 108 return; |
| 109 } | 109 } |
| 110 const cryptohome::Identification cryptohome_identification(account_id); | 110 const cryptohome::Identification cryptohome_identification(account_id); |
| 111 const std::string sanitized_username = | 111 const std::string sanitized_username = |
| 112 chromeos::CryptohomeClient::GetStubSanitizedUsername( | 112 chromeos::CryptohomeClient::GetStubSanitizedUsername( |
| 113 cryptohome_identification); | 113 cryptohome_identification); |
| 114 policy_path = policy_path.AppendASCII(sanitized_username); | 114 policy_path = policy_path.AppendASCII(sanitized_username); |
| 115 policy_path = policy_path.AppendASCII("stub_policy"); | 115 policy_path = policy_path.AppendASCII("stub_policy"); |
| 116 | 116 |
| 117 em::CloudPolicySettings policy; | 117 em::CloudPolicySettings policy; |
| 118 std::string payload; | 118 std::string payload; |
| 119 CHECK(policy.SerializeToString(&payload)); | 119 CHECK(policy.SerializeToString(&payload)); |
| 120 | 120 |
| 121 // Drop file for SessionManagerClientStubImpl to read. | 121 // Drop file for SessionManagerClientStubImpl to read. |
| 122 if (!base::PostTaskAndReplyWithResult( | 122 base::PostTaskWithTraitsAndReplyWithResult( |
| 123 base::WorkerPool::GetTaskRunner(false /* task_is_slow */).get(), | 123 FROM_HERE, base::TaskTraits() |
| 124 FROM_HERE, base::Bind(&WritePolicyFile, policy_path, payload, | 124 .WithShutdownBehavior( |
| 125 "google/chromeos/user"), | 125 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 126 callback)) { | 126 .WithPriority(base::TaskPriority::BACKGROUND) |
| 127 callback.Run(false); | 127 .MayBlock(), |
| 128 } | 128 base::Bind(&WritePolicyFile, policy_path, payload, |
| 129 "google/chromeos/user"), |
| 130 callback); |
| 129 } | 131 } |
| 130 | 132 |
| 131 } // namespace chromeos | 133 } // namespace chromeos |
| OLD | NEW |