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

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

Issue 2801993002: Abandon user sign in when policy is retrieved before session started (Closed)
Patch Set: Fixed review comments Created 3 years, 7 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_session_manager_client.h" 5 #include "chromeos/dbus/fake_session_manager_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/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "chromeos/chromeos_paths.h" 16 #include "chromeos/chromeos_paths.h"
17 #include "chromeos/dbus/cryptohome_client.h" 17 #include "chromeos/dbus/cryptohome_client.h"
18 #include "components/policy/proto/device_management_backend.pb.h" 18 #include "components/policy/proto/device_management_backend.pb.h"
19 19
20 using RetrievePolicyResponseType =
21 chromeos::FakeSessionManagerClient::RetrievePolicyResponseType;
22
20 namespace chromeos { 23 namespace chromeos {
21 24
22 namespace { 25 namespace {
23 26
24 // Store the owner key in a file on the disk, so that it can be loaded by 27 // Store the owner key in a file on the disk, so that it can be loaded by
25 // DeviceSettingsService and used e.g. for validating policy signatures in the 28 // DeviceSettingsService and used e.g. for validating policy signatures in the
26 // integration tests. This is done on behalf of the real session manager, that 29 // integration tests. This is done on behalf of the real session manager, that
27 // would be managing the owner key file on Chrome OS. 30 // would be managing the owner key file on Chrome OS.
28 bool StoreOwnerKey(const std::string& public_key) { 31 bool StoreOwnerKey(const std::string& public_key) {
29 base::FilePath owner_key_path; 32 base::FilePath owner_key_path;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 124
122 void FakeSessionManagerClient::RetrieveActiveSessions( 125 void FakeSessionManagerClient::RetrieveActiveSessions(
123 const ActiveSessionsCallback& callback) { 126 const ActiveSessionsCallback& callback) {
124 base::ThreadTaskRunnerHandle::Get()->PostTask( 127 base::ThreadTaskRunnerHandle::Get()->PostTask(
125 FROM_HERE, base::Bind(callback, user_sessions_, true)); 128 FROM_HERE, base::Bind(callback, user_sessions_, true));
126 } 129 }
127 130
128 void FakeSessionManagerClient::RetrieveDevicePolicy( 131 void FakeSessionManagerClient::RetrieveDevicePolicy(
129 const RetrievePolicyCallback& callback) { 132 const RetrievePolicyCallback& callback) {
130 base::ThreadTaskRunnerHandle::Get()->PostTask( 133 base::ThreadTaskRunnerHandle::Get()->PostTask(
131 FROM_HERE, base::Bind(callback, device_policy_)); 134 FROM_HERE, base::Bind(callback, device_policy_,
135 RetrievePolicyResponseType::SUCCESS));
132 } 136 }
133 137
134 std::string FakeSessionManagerClient::BlockingRetrieveDevicePolicy() { 138 RetrievePolicyResponseType
135 return device_policy_; 139 FakeSessionManagerClient::BlockingRetrieveDevicePolicy(
140 std::string* policy_out) {
141 *policy_out = device_policy_;
142 return RetrievePolicyResponseType::SUCCESS;
136 } 143 }
137 144
138 void FakeSessionManagerClient::RetrievePolicyForUser( 145 void FakeSessionManagerClient::RetrievePolicyForUser(
139 const cryptohome::Identification& cryptohome_id, 146 const cryptohome::Identification& cryptohome_id,
140 const RetrievePolicyCallback& callback) { 147 const RetrievePolicyCallback& callback) {
141 base::ThreadTaskRunnerHandle::Get()->PostTask( 148 base::ThreadTaskRunnerHandle::Get()->PostTask(
142 FROM_HERE, base::Bind(callback, user_policies_[cryptohome_id])); 149 FROM_HERE, base::Bind(callback, user_policies_[cryptohome_id],
150 RetrievePolicyResponseType::SUCCESS));
143 } 151 }
144 152
145 std::string FakeSessionManagerClient::BlockingRetrievePolicyForUser( 153 RetrievePolicyResponseType
146 const cryptohome::Identification& cryptohome_id) { 154 FakeSessionManagerClient::BlockingRetrievePolicyForUser(
147 return user_policies_[cryptohome_id]; 155 const cryptohome::Identification& cryptohome_id,
156 std::string* policy_out) {
157 *policy_out = user_policies_[cryptohome_id];
158 return RetrievePolicyResponseType::SUCCESS;
148 } 159 }
149 160
150 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy( 161 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy(
151 const std::string& account_id, 162 const std::string& account_id,
152 const RetrievePolicyCallback& callback) { 163 const RetrievePolicyCallback& callback) {
153 base::ThreadTaskRunnerHandle::Get()->PostTask( 164 base::ThreadTaskRunnerHandle::Get()->PostTask(
154 FROM_HERE, 165 FROM_HERE, base::Bind(callback, device_local_account_policy_[account_id],
155 base::Bind(callback, device_local_account_policy_[account_id])); 166 RetrievePolicyResponseType::SUCCESS));
156 } 167 }
157 168
158 std::string FakeSessionManagerClient::BlockingRetrieveDeviceLocalAccountPolicy( 169 RetrievePolicyResponseType
159 const std::string& account_id) { 170 FakeSessionManagerClient::BlockingRetrieveDeviceLocalAccountPolicy(
160 return device_local_account_policy_[account_id]; 171 const std::string& account_id,
172 std::string* policy_out) {
173 *policy_out = device_local_account_policy_[account_id];
174 return RetrievePolicyResponseType::SUCCESS;
161 } 175 }
162 176
163 void FakeSessionManagerClient::StoreDevicePolicy( 177 void FakeSessionManagerClient::StoreDevicePolicy(
164 const std::string& policy_blob, 178 const std::string& policy_blob,
165 const StorePolicyCallback& callback) { 179 const StorePolicyCallback& callback) {
166 enterprise_management::PolicyFetchResponse policy; 180 enterprise_management::PolicyFetchResponse policy;
167 if (!policy.ParseFromString(policy_blob)) { 181 if (!policy.ParseFromString(policy_blob)) {
168 LOG(ERROR) << "Unable to parse policy protobuf"; 182 LOG(ERROR) << "Unable to parse policy protobuf";
169 base::ThreadTaskRunnerHandle::Get()->PostTask( 183 base::ThreadTaskRunnerHandle::Get()->PostTask(
170 FROM_HERE, base::Bind(callback, false /* success */)); 184 FROM_HERE, base::Bind(callback, false /* success */));
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 const std::string& policy_blob) { 318 const std::string& policy_blob) {
305 device_local_account_policy_[account_id] = policy_blob; 319 device_local_account_policy_[account_id] = policy_blob;
306 } 320 }
307 321
308 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) { 322 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) {
309 for (auto& observer : observers_) 323 for (auto& observer : observers_)
310 observer.PropertyChangeComplete(success); 324 observer.PropertyChangeComplete(success);
311 } 325 }
312 326
313 } // namespace chromeos 327 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_session_manager_client.h ('k') | chromeos/dbus/mock_session_manager_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698