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

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

Issue 2801993002: Abandon user sign in when policy is retrieved before session started (Closed)
Patch Set: Nits Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/session_manager_client.h" 5 #include "chromeos/dbus/session_manager_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/metrics/histogram_macros.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/task_scheduler/post_task.h" 22 #include "base/task_scheduler/post_task.h"
22 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
23 #include "chromeos/chromeos_paths.h" 24 #include "chromeos/chromeos_paths.h"
24 #include "chromeos/cryptohome/cryptohome_parameters.h" 25 #include "chromeos/cryptohome/cryptohome_parameters.h"
25 #include "chromeos/dbus/blocking_method_caller.h" 26 #include "chromeos/dbus/blocking_method_caller.h"
26 #include "chromeos/dbus/cryptohome_client.h" 27 #include "chromeos/dbus/cryptohome_client.h"
27 #include "components/policy/proto/device_management_backend.pb.h" 28 #include "components/policy/proto/device_management_backend.pb.h"
28 #include "crypto/sha2.h" 29 #include "crypto/sha2.h"
29 #include "dbus/bus.h" 30 #include "dbus/bus.h"
30 #include "dbus/message.h" 31 #include "dbus/message.h"
31 #include "dbus/object_path.h" 32 #include "dbus/object_path.h"
32 #include "dbus/object_proxy.h" 33 #include "dbus/object_proxy.h"
34 #include "dbus/scoped_dbus_error.h"
33 #include "third_party/cros_system_api/dbus/service_constants.h" 35 #include "third_party/cros_system_api/dbus/service_constants.h"
34 36
35 namespace chromeos { 37 namespace chromeos {
36 38
37 namespace { 39 namespace {
38 40
39 // TODO(hidehiko): Share the constant between Chrome and ChromeOS.
40 constexpr char kArcLowDiskError[] =
41 "org.chromium.SessionManagerInterface.LowFreeDisk";
42
43 constexpr char kStubPolicyFile[] = "stub_policy"; 41 constexpr char kStubPolicyFile[] = "stub_policy";
44 constexpr char kStubDevicePolicyFile[] = "stub_device_policy"; 42 constexpr char kStubDevicePolicyFile[] = "stub_device_policy";
45 constexpr char kStubStateKeysFile[] = "stub_state_keys"; 43 constexpr char kStubStateKeysFile[] = "stub_state_keys";
46 44
47 // Returns a location for |file| that is specific to the given |cryptohome_id|. 45 // Returns a location for |file| that is specific to the given |cryptohome_id|.
48 // These paths will be relative to DIR_USER_POLICY_KEYS, and can be used only 46 // These paths will be relative to DIR_USER_POLICY_KEYS, and can be used only
49 // to store stub files. 47 // to store stub files.
50 base::FilePath GetUserFilePath(const cryptohome::Identification& cryptohome_id, 48 base::FilePath GetUserFilePath(const cryptohome::Identification& cryptohome_id,
51 const char* file) { 49 const char* file) {
52 base::FilePath keys_path; 50 base::FilePath keys_path;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 94 }
97 return state_keys; 95 return state_keys;
98 } 96 }
99 97
100 // Turn pass-by-value into pass-by-reference as expected by StateKeysCallback. 98 // Turn pass-by-value into pass-by-reference as expected by StateKeysCallback.
101 void RunStateKeysCallbackStub(SessionManagerClient::StateKeysCallback callback, 99 void RunStateKeysCallbackStub(SessionManagerClient::StateKeysCallback callback,
102 std::vector<std::string> state_keys) { 100 std::vector<std::string> state_keys) {
103 callback.Run(state_keys); 101 callback.Run(state_keys);
104 } 102 }
105 103
104 // Helper to notify the callback with SUCCESS, to be used by the stub.
105 void NotifyOnRetrievePolicySuccess(
106 const SessionManagerClient::RetrievePolicyCallback& callback,
107 const std::string& protobuf) {
108 callback.Run(protobuf, SessionManagerClient::SUCCESS);
109 }
110
111 // Helper to get the enum type of RetrievePolicyResponseType based on error
112 // name.
113 SessionManagerClient::RetrievePolicyResponseType GetResponseTypeBasedOnError(
114 const std::string& error_name) {
115 if (error_name == login_manager::dbus_error::kNone) {
116 return SessionManagerClient::SUCCESS;
117 } else if (error_name == login_manager::dbus_error::kSessionDoesNotExist) {
emaxx 2017/04/21 00:01:52 nit: Sorry for not pointing this out before, but i
igorcov 2017/04/21 11:36:21 Done.
118 return SessionManagerClient::SESSION_DOES_NOT_EXIST;
119 } else if (error_name == login_manager::dbus_error::kSigEncodeFail) {
120 return SessionManagerClient::SIG_ENCODE_FAIL;
121 } else {
122 return SessionManagerClient::OTHER_ERROR;
123 }
124 }
125
126 // Logs UMA stat for retrieve policy request, corresponding to D-Bus method name
127 // used.
128 void LogUma(const std::string& method_name,
emaxx 2017/04/21 00:01:52 nit: Give this function a more specific name, e.g.
igorcov 2017/04/21 11:36:21 Done.
129 SessionManagerClient::RetrievePolicyResponseType response) {
130 std::string stat_name;
131 if (method_name ==
132 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy) {
133 stat_name = "RetrieveDeviceLocalAccountPolicyResponse";
134 } else if (method_name == login_manager::kSessionManagerRetrievePolicy) {
135 stat_name = "RetrieveDevicePolicyResponse";
136 } else if (method_name ==
137 login_manager::kSessionManagerRetrievePolicyForUser) {
138 stat_name = "RetrieveUserPolicyResponse";
139 } else {
140 LOG(ERROR) << "Invalid method_name: " << method_name;
141 return;
142 }
143
144 UMA_HISTOGRAM_ENUMERATION(
145 "Enterprise." + stat_name, response,
emaxx 2017/04/21 00:01:52 I doubt that it will work as expected. The |name|
igorcov 2017/04/21 11:36:21 Changed to have separate calls. Thanks.
146 SessionManagerClient::RETRIEVE_POLICY_RESPONSE_TYPE_COUNT);
147 }
148
106 } // namespace 149 } // namespace
107 150
108 // The SessionManagerClient implementation used in production. 151 // The SessionManagerClient implementation used in production.
109 class SessionManagerClientImpl : public SessionManagerClient { 152 class SessionManagerClientImpl : public SessionManagerClient {
110 public: 153 public:
111 SessionManagerClientImpl() 154 SessionManagerClientImpl()
112 : session_manager_proxy_(NULL), 155 : session_manager_proxy_(NULL),
113 screen_is_locked_(false), 156 screen_is_locked_(false),
114 weak_ptr_factory_(this) {} 157 weak_ptr_factory_(this) {}
115 158
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 267 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
225 base::Bind(&SessionManagerClientImpl::OnRetrieveActiveSessions, 268 base::Bind(&SessionManagerClientImpl::OnRetrieveActiveSessions,
226 weak_ptr_factory_.GetWeakPtr(), 269 weak_ptr_factory_.GetWeakPtr(),
227 login_manager::kSessionManagerRetrieveActiveSessions, 270 login_manager::kSessionManagerRetrieveActiveSessions,
228 callback)); 271 callback));
229 } 272 }
230 273
231 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { 274 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override {
232 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, 275 dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
233 login_manager::kSessionManagerRetrievePolicy); 276 login_manager::kSessionManagerRetrievePolicy);
234 session_manager_proxy_->CallMethod( 277 session_manager_proxy_->CallMethodWithErrorCallback(
235 &method_call, 278 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
236 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 279 base::Bind(&SessionManagerClientImpl::OnRetrievePolicySuccess,
237 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy,
238 weak_ptr_factory_.GetWeakPtr(), 280 weak_ptr_factory_.GetWeakPtr(),
239 login_manager::kSessionManagerRetrievePolicy, 281 login_manager::kSessionManagerRetrievePolicy, callback),
240 callback)); 282 base::Bind(&SessionManagerClientImpl::OnRetrievePolicyError,
283 weak_ptr_factory_.GetWeakPtr(),
284 login_manager::kSessionManagerRetrievePolicy, callback));
241 } 285 }
242 286
243 std::string BlockingRetrieveDevicePolicy() override { 287 RetrievePolicyResponseType BlockingRetrieveDevicePolicy(
288 std::string* policy) override {
244 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, 289 dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
245 login_manager::kSessionManagerRetrievePolicy); 290 login_manager::kSessionManagerRetrievePolicy);
291 dbus::ScopedDBusError error;
246 std::unique_ptr<dbus::Response> response = 292 std::unique_ptr<dbus::Response> response =
247 blocking_method_caller_->CallMethodAndBlock(&method_call); 293 blocking_method_caller_->CallMethodAndBlockWithError(&method_call,
248 std::string policy; 294 &error);
249 ExtractString(login_manager::kSessionManagerRetrievePolicy, response.get(), 295 RetrievePolicyResponseType result = RetrievePolicyResponseType::SUCCESS;
250 &policy); 296 if (error.is_set() && error.name()) {
251 return policy; 297 result = GetResponseTypeBasedOnError(error.name());
298 }
299 if (result == RetrievePolicyResponseType::SUCCESS) {
300 ExtractString(login_manager::kSessionManagerRetrievePolicy,
301 response.get(), policy);
302 }
303 LogUma(login_manager::kSessionManagerRetrievePolicy, result);
304 return result;
252 } 305 }
253 306
254 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, 307 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id,
255 const RetrievePolicyCallback& callback) override { 308 const RetrievePolicyCallback& callback) override {
256 CallRetrievePolicyByUsername( 309 CallRetrievePolicyByUsername(
257 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(), 310 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(),
258 callback); 311 callback);
259 } 312 }
260 313
261 std::string BlockingRetrievePolicyForUser( 314 RetrievePolicyResponseType BlockingRetrievePolicyForUser(
262 const cryptohome::Identification& cryptohome_id) override { 315 const cryptohome::Identification& cryptohome_id,
263 dbus::MethodCall method_call( 316 std::string* policy) override {
264 login_manager::kSessionManagerInterface, 317 return BlockingRetrievePolicyByUsername(
265 login_manager::kSessionManagerRetrievePolicyForUser); 318 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(),
266 dbus::MessageWriter writer(&method_call); 319 policy);
267 writer.AppendString(cryptohome_id.id());
268 std::unique_ptr<dbus::Response> response =
269 blocking_method_caller_->CallMethodAndBlock(&method_call);
270 std::string policy;
271 ExtractString(login_manager::kSessionManagerRetrievePolicyForUser,
272 response.get(),
273 &policy);
274 return policy;
275 } 320 }
276 321
277 void RetrieveDeviceLocalAccountPolicy( 322 void RetrieveDeviceLocalAccountPolicy(
278 const std::string& account_name, 323 const std::string& account_name,
279 const RetrievePolicyCallback& callback) override { 324 const RetrievePolicyCallback& callback) override {
280 CallRetrievePolicyByUsername( 325 CallRetrievePolicyByUsername(
281 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, 326 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy,
282 account_name, 327 account_name, callback);
283 callback);
284 } 328 }
285 329
286 std::string BlockingRetrieveDeviceLocalAccountPolicy( 330 RetrievePolicyResponseType BlockingRetrieveDeviceLocalAccountPolicy(
287 const std::string& account_name) override { 331 const std::string& account_name,
288 dbus::MethodCall method_call( 332 std::string* policy) override {
289 login_manager::kSessionManagerInterface, 333 return BlockingRetrievePolicyByUsername(
290 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy);
291 dbus::MessageWriter writer(&method_call);
292 writer.AppendString(account_name);
293 std::unique_ptr<dbus::Response> response =
294 blocking_method_caller_->CallMethodAndBlock(&method_call);
295 std::string policy;
296 ExtractString(
297 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, 334 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy,
298 response.get(), &policy); 335 account_name, policy);
299 return policy;
300 } 336 }
301 337
302 void StoreDevicePolicy(const std::string& policy_blob, 338 void StoreDevicePolicy(const std::string& policy_blob,
303 const StorePolicyCallback& callback) override { 339 const StorePolicyCallback& callback) override {
304 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, 340 dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
305 login_manager::kSessionManagerStorePolicy); 341 login_manager::kSessionManagerStorePolicy);
306 dbus::MessageWriter writer(&method_call); 342 dbus::MessageWriter writer(&method_call);
307 // static_cast does not work due to signedness. 343 // static_cast does not work due to signedness.
308 writer.AppendArrayOfBytes( 344 writer.AppendArrayOfBytes(
309 reinterpret_cast<const uint8_t*>(policy_blob.data()), 345 reinterpret_cast<const uint8_t*>(policy_blob.data()),
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 } 553 }
518 554
519 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser. 555 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser.
520 void CallRetrievePolicyByUsername(const std::string& method_name, 556 void CallRetrievePolicyByUsername(const std::string& method_name,
521 const std::string& account_id, 557 const std::string& account_id,
522 const RetrievePolicyCallback& callback) { 558 const RetrievePolicyCallback& callback) {
523 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, 559 dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
524 method_name); 560 method_name);
525 dbus::MessageWriter writer(&method_call); 561 dbus::MessageWriter writer(&method_call);
526 writer.AppendString(account_id); 562 writer.AppendString(account_id);
527 session_manager_proxy_->CallMethod( 563 session_manager_proxy_->CallMethodWithErrorCallback(
528 &method_call, 564 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
529 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 565 base::Bind(&SessionManagerClientImpl::OnRetrievePolicySuccess,
530 base::Bind( 566 weak_ptr_factory_.GetWeakPtr(), method_name, callback),
531 &SessionManagerClientImpl::OnRetrievePolicy, 567 base::Bind(&SessionManagerClientImpl::OnRetrievePolicyError,
532 weak_ptr_factory_.GetWeakPtr(), 568 weak_ptr_factory_.GetWeakPtr(), method_name, callback));
533 method_name, 569 }
534 callback)); 570
571 // Helper for blocking RetrievePolicyForUser and
572 // RetrieveDeviceLocalAccountPolicy.
573 RetrievePolicyResponseType BlockingRetrievePolicyByUsername(
574 const std::string& method_name,
575 const std::string& account_name,
576 std::string* policy) {
577 dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
578 method_name);
579 dbus::MessageWriter writer(&method_call);
580 writer.AppendString(account_name);
581 dbus::ScopedDBusError error;
582 std::unique_ptr<dbus::Response> response =
583 blocking_method_caller_->CallMethodAndBlockWithError(&method_call,
584 &error);
585 RetrievePolicyResponseType result = RetrievePolicyResponseType::SUCCESS;
586 if (error.is_set() && error.name()) {
587 result = GetResponseTypeBasedOnError(error.name());
588 }
589 if (result == RetrievePolicyResponseType::SUCCESS) {
590 ExtractString(method_name, response.get(), policy);
591 }
592 LogUma(method_name, result);
593 return result;
535 } 594 }
536 595
537 void CallStorePolicyByUsername(const std::string& method_name, 596 void CallStorePolicyByUsername(const std::string& method_name,
538 const std::string& account_id, 597 const std::string& account_id,
539 const std::string& policy_blob, 598 const std::string& policy_blob,
540 const StorePolicyCallback& callback) { 599 const StorePolicyCallback& callback) {
541 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, 600 dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
542 method_name); 601 method_name);
543 dbus::MessageWriter writer(&method_call); 602 dbus::MessageWriter writer(&method_call);
544 writer.AppendString(account_id); 603 writer.AppendString(account_id);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 size_t length = 0; 695 size_t length = 0;
637 if (!reader.PopArrayOfBytes(&values, &length)) { 696 if (!reader.PopArrayOfBytes(&values, &length)) {
638 LOG(ERROR) << "Invalid response: " << response->ToString(); 697 LOG(ERROR) << "Invalid response: " << response->ToString();
639 return; 698 return;
640 } 699 }
641 // static_cast does not work due to signedness. 700 // static_cast does not work due to signedness.
642 extracted->assign(reinterpret_cast<const char*>(values), length); 701 extracted->assign(reinterpret_cast<const char*>(values), length);
643 } 702 }
644 703
645 // Called when kSessionManagerRetrievePolicy or 704 // Called when kSessionManagerRetrievePolicy or
646 // kSessionManagerRetrievePolicyForUser method is complete. 705 // kSessionManagerRetrievePolicyForUser method is successfully complete.
647 void OnRetrievePolicy(const std::string& method_name, 706 void OnRetrievePolicySuccess(const std::string& method_name,
648 const RetrievePolicyCallback& callback, 707 const RetrievePolicyCallback& callback,
649 dbus::Response* response) { 708 dbus::Response* response) {
650 std::string serialized_proto; 709 std::string serialized_proto;
651 ExtractString(method_name, response, &serialized_proto); 710 ExtractString(method_name, response, &serialized_proto);
652 callback.Run(serialized_proto); 711 callback.Run(serialized_proto, SUCCESS);
712
713 LogUma(method_name, SUCCESS);
714 }
715
716 // Called when kSessionManagerRetrievePolicy or
717 // kSessionManagerRetrievePolicyForUser method fails.
718 void OnRetrievePolicyError(const std::string& method_name,
719 const RetrievePolicyCallback& callback,
720 dbus::ErrorResponse* response) {
721 RetrievePolicyResponseType response_type =
722 GetResponseTypeBasedOnError(response->GetErrorName());
723 callback.Run(std::string(), response_type);
724
725 LogUma(method_name, response_type);
653 } 726 }
654 727
655 // Called when kSessionManagerStorePolicy or kSessionManagerStorePolicyForUser 728 // Called when kSessionManagerStorePolicy or kSessionManagerStorePolicyForUser
656 // method is complete. 729 // method is complete.
657 void OnStorePolicy(const std::string& method_name, 730 void OnStorePolicy(const std::string& method_name,
658 const StorePolicyCallback& callback, 731 const StorePolicyCallback& callback,
659 dbus::Response* response) { 732 dbus::Response* response) {
660 bool success = false; 733 bool success = false;
661 if (!response) { 734 if (!response) {
662 LOG(ERROR) << "Failed to call " << method_name; 735 LOG(ERROR) << "Failed to call " << method_name;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 void OnStartArcInstanceSucceeded(const StartArcInstanceCallback& callback, 886 void OnStartArcInstanceSucceeded(const StartArcInstanceCallback& callback,
814 dbus::Response* response) { 887 dbus::Response* response) {
815 if (!callback.is_null()) 888 if (!callback.is_null())
816 callback.Run(StartArcInstanceResult::SUCCESS); 889 callback.Run(StartArcInstanceResult::SUCCESS);
817 } 890 }
818 891
819 void OnStartArcInstanceFailed(const StartArcInstanceCallback& callback, 892 void OnStartArcInstanceFailed(const StartArcInstanceCallback& callback,
820 dbus::ErrorResponse* response) { 893 dbus::ErrorResponse* response) {
821 LOG(ERROR) << "Failed to call StartArcInstance: " 894 LOG(ERROR) << "Failed to call StartArcInstance: "
822 << (response ? response->ToString() : "(null)"); 895 << (response ? response->ToString() : "(null)");
823 if (!callback.is_null()) 896 if (!callback.is_null())
Daniel Erat 2017/04/20 21:06:39 not your fault, but please add curly brackets here
igorcov 2017/04/21 11:36:21 Done.
824 callback.Run(response && response->GetErrorName() == kArcLowDiskError 897 callback.Run(response && response->GetErrorName() ==
898 login_manager::dbus_error::kLowFreeDisk
825 ? StartArcInstanceResult::LOW_FREE_DISK_SPACE 899 ? StartArcInstanceResult::LOW_FREE_DISK_SPACE
826 : StartArcInstanceResult::UNKNOWN_ERROR); 900 : StartArcInstanceResult::UNKNOWN_ERROR);
827 } 901 }
828 902
829 dbus::ObjectProxy* session_manager_proxy_; 903 dbus::ObjectProxy* session_manager_proxy_;
830 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; 904 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_;
831 base::ObserverList<Observer> observers_; 905 base::ObserverList<Observer> observers_;
832 906
833 // Most recent screen-lock state received from session_manager. 907 // Most recent screen-lock state received from session_manager.
834 bool screen_is_locked_; 908 bool screen_is_locked_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 void NotifyLockScreenDismissed() override { 957 void NotifyLockScreenDismissed() override {
884 screen_is_locked_ = false; 958 screen_is_locked_ = false;
885 for (auto& observer : observers_) 959 for (auto& observer : observers_)
886 observer.ScreenIsUnlocked(); 960 observer.ScreenIsUnlocked();
887 } 961 }
888 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override { 962 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override {
889 } 963 }
890 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { 964 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override {
891 base::FilePath owner_key_path; 965 base::FilePath owner_key_path;
892 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { 966 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) {
893 callback.Run(""); 967 callback.Run("", SUCCESS);
894 return; 968 return;
895 } 969 }
896 base::FilePath device_policy_path = 970 base::FilePath device_policy_path =
897 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); 971 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile);
898 base::PostTaskWithTraitsAndReplyWithResult( 972 base::PostTaskWithTraitsAndReplyWithResult(
899 FROM_HERE, base::TaskTraits() 973 FROM_HERE,
900 .WithShutdownBehavior( 974 base::TaskTraits()
901 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) 975 .WithShutdownBehavior(
902 .MayBlock(), 976 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
903 base::Bind(&GetFileContent, device_policy_path), callback); 977 .MayBlock(),
978 base::Bind(&GetFileContent, device_policy_path),
979 base::Bind(&NotifyOnRetrievePolicySuccess, callback));
904 } 980 }
905 std::string BlockingRetrieveDevicePolicy() override { 981 RetrievePolicyResponseType BlockingRetrieveDevicePolicy(
982 std::string* policy) override {
906 base::FilePath owner_key_path; 983 base::FilePath owner_key_path;
907 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { 984 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) {
908 return ""; 985 *policy = "";
986 return SUCCESS;
909 } 987 }
910 base::FilePath device_policy_path = 988 base::FilePath device_policy_path =
911 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); 989 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile);
912 return GetFileContent(device_policy_path); 990 *policy = GetFileContent(device_policy_path);
991 return SUCCESS;
913 } 992 }
914 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, 993 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id,
915 const RetrievePolicyCallback& callback) override { 994 const RetrievePolicyCallback& callback) override {
916 base::PostTaskWithTraitsAndReplyWithResult( 995 base::PostTaskWithTraitsAndReplyWithResult(
917 FROM_HERE, 996 FROM_HERE,
918 base::TaskTraits() 997 base::TaskTraits()
919 .WithShutdownBehavior( 998 .WithShutdownBehavior(
920 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) 999 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
921 .MayBlock(), 1000 .MayBlock(),
922 base::Bind(&GetFileContent, 1001 base::Bind(&GetFileContent,
923 GetUserFilePath(cryptohome_id, kStubPolicyFile)), 1002 GetUserFilePath(cryptohome_id, kStubPolicyFile)),
924 callback); 1003 base::Bind(&NotifyOnRetrievePolicySuccess, callback));
925 } 1004 }
926 std::string BlockingRetrievePolicyForUser( 1005 RetrievePolicyResponseType BlockingRetrievePolicyForUser(
927 const cryptohome::Identification& cryptohome_id) override { 1006 const cryptohome::Identification& cryptohome_id,
928 return GetFileContent(GetUserFilePath(cryptohome_id, kStubPolicyFile)); 1007 std::string* policy) override {
1008 *policy = GetFileContent(GetUserFilePath(cryptohome_id, kStubPolicyFile));
1009 return SUCCESS;
929 } 1010 }
930 void RetrieveDeviceLocalAccountPolicy( 1011 void RetrieveDeviceLocalAccountPolicy(
931 const std::string& account_id, 1012 const std::string& account_id,
932 const RetrievePolicyCallback& callback) override { 1013 const RetrievePolicyCallback& callback) override {
933 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id), 1014 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id),
934 callback); 1015 callback);
935 } 1016 }
936 std::string BlockingRetrieveDeviceLocalAccountPolicy( 1017 RetrievePolicyResponseType BlockingRetrieveDeviceLocalAccountPolicy(
937 const std::string& account_id) override { 1018 const std::string& account_id,
1019 std::string* policy) override {
938 return BlockingRetrievePolicyForUser( 1020 return BlockingRetrievePolicyForUser(
939 cryptohome::Identification::FromString(account_id)); 1021 cryptohome::Identification::FromString(account_id), policy);
940 } 1022 }
941 void StoreDevicePolicy(const std::string& policy_blob, 1023 void StoreDevicePolicy(const std::string& policy_blob,
942 const StorePolicyCallback& callback) override { 1024 const StorePolicyCallback& callback) override {
943 enterprise_management::PolicyFetchResponse response; 1025 enterprise_management::PolicyFetchResponse response;
944 base::FilePath owner_key_path; 1026 base::FilePath owner_key_path;
945 if (!response.ParseFromString(policy_blob) || 1027 if (!response.ParseFromString(policy_blob) ||
946 !PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { 1028 !PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) {
947 callback.Run(false); 1029 callback.Run(false);
948 return; 1030 return;
949 } 1031 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 1170
1089 SessionManagerClient* SessionManagerClient::Create( 1171 SessionManagerClient* SessionManagerClient::Create(
1090 DBusClientImplementationType type) { 1172 DBusClientImplementationType type) {
1091 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 1173 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
1092 return new SessionManagerClientImpl(); 1174 return new SessionManagerClientImpl();
1093 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); 1175 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type);
1094 return new SessionManagerClientStubImpl(); 1176 return new SessionManagerClientStubImpl();
1095 } 1177 }
1096 1178
1097 } // namespace chromeos 1179 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698