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

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: Added comments to new functions 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>
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 return policy; 222 return policy;
223 } 223 }
224 224
225 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, 225 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id,
226 const RetrievePolicyCallback& callback) override { 226 const RetrievePolicyCallback& callback) override {
227 CallRetrievePolicyByUsername( 227 CallRetrievePolicyByUsername(
228 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(), 228 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(),
229 callback); 229 callback);
230 } 230 }
231 231
232 void RetrievePolicyForUserWithErrorCallback(
233 const cryptohome::Identification& cryptohome_id,
234 const RetrievePolicyCallback& callback,
235 const ErrorCallback& error_callback) override {
236 CallRetrievePolicyByUsernameWithErrorCallback(
237 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(),
238 callback, error_callback);
239 }
240
232 std::string BlockingRetrievePolicyForUser( 241 std::string BlockingRetrievePolicyForUser(
233 const cryptohome::Identification& cryptohome_id) override { 242 const cryptohome::Identification& cryptohome_id) override {
234 dbus::MethodCall method_call( 243 dbus::MethodCall method_call(
235 login_manager::kSessionManagerInterface, 244 login_manager::kSessionManagerInterface,
236 login_manager::kSessionManagerRetrievePolicyForUser); 245 login_manager::kSessionManagerRetrievePolicyForUser);
237 dbus::MessageWriter writer(&method_call); 246 dbus::MessageWriter writer(&method_call);
238 writer.AppendString(cryptohome_id.id()); 247 writer.AppendString(cryptohome_id.id());
239 std::unique_ptr<dbus::Response> response = 248 std::unique_ptr<dbus::Response> response =
240 blocking_method_caller_->CallMethodAndBlock(&method_call); 249 blocking_method_caller_->CallMethodAndBlock(&method_call);
241 std::string policy; 250 std::string policy;
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 session_manager_proxy_->CallMethod( 507 session_manager_proxy_->CallMethod(
499 &method_call, 508 &method_call,
500 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 509 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
501 base::Bind( 510 base::Bind(
502 &SessionManagerClientImpl::OnRetrievePolicy, 511 &SessionManagerClientImpl::OnRetrievePolicy,
503 weak_ptr_factory_.GetWeakPtr(), 512 weak_ptr_factory_.GetWeakPtr(),
504 method_name, 513 method_name,
505 callback)); 514 callback));
506 } 515 }
507 516
517 void CallRetrievePolicyByUsernameWithErrorCallback(
518 const std::string& method_name,
519 const std::string& account_id,
520 const RetrievePolicyCallback& callback,
521 const ErrorCallback& error_callback) {
522 dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
523 method_name);
524 dbus::MessageWriter writer(&method_call);
525 writer.AppendString(account_id);
Daniel Erat 2017/04/10 18:59:26 please avoid copy-and-pasting code (i.e. the exist
igorcov 2017/04/18 10:23:18 Done.
526 session_manager_proxy_->CallMethodWithErrorCallback(
527 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
528 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy,
529 weak_ptr_factory_.GetWeakPtr(), method_name, callback),
530 base::Bind(&SessionManagerClientImpl::OnRetrievePolicyWithError,
531 weak_ptr_factory_.GetWeakPtr(), error_callback));
532 }
533
508 void CallStorePolicyByUsername(const std::string& method_name, 534 void CallStorePolicyByUsername(const std::string& method_name,
509 const std::string& account_id, 535 const std::string& account_id,
510 const std::string& policy_blob, 536 const std::string& policy_blob,
511 const StorePolicyCallback& callback) { 537 const StorePolicyCallback& callback) {
512 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, 538 dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
513 method_name); 539 method_name);
514 dbus::MessageWriter writer(&method_call); 540 dbus::MessageWriter writer(&method_call);
515 writer.AppendString(account_id); 541 writer.AppendString(account_id);
516 // static_cast does not work due to signedness. 542 // static_cast does not work due to signedness.
517 writer.AppendArrayOfBytes( 543 writer.AppendArrayOfBytes(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 // Called when kSessionManagerRetrievePolicy or 642 // Called when kSessionManagerRetrievePolicy or
617 // kSessionManagerRetrievePolicyForUser method is complete. 643 // kSessionManagerRetrievePolicyForUser method is complete.
618 void OnRetrievePolicy(const std::string& method_name, 644 void OnRetrievePolicy(const std::string& method_name,
619 const RetrievePolicyCallback& callback, 645 const RetrievePolicyCallback& callback,
620 dbus::Response* response) { 646 dbus::Response* response) {
621 std::string serialized_proto; 647 std::string serialized_proto;
622 ExtractString(method_name, response, &serialized_proto); 648 ExtractString(method_name, response, &serialized_proto);
623 callback.Run(serialized_proto); 649 callback.Run(serialized_proto);
624 } 650 }
625 651
652 void OnRetrievePolicyWithError(const ErrorCallback& callback,
653 dbus::ErrorResponse* response) {
654 std::string error_name;
655 std::string error_message;
656 dbus::MessageReader reader(response);
657 error_name = response->GetErrorName();
658 reader.PopString(&error_message);
659 callback.Run(error_name, error_message);
660 }
661
626 // Called when kSessionManagerStorePolicy or kSessionManagerStorePolicyForUser 662 // Called when kSessionManagerStorePolicy or kSessionManagerStorePolicyForUser
627 // method is complete. 663 // method is complete.
628 void OnStorePolicy(const std::string& method_name, 664 void OnStorePolicy(const std::string& method_name,
629 const StorePolicyCallback& callback, 665 const StorePolicyCallback& callback,
630 dbus::Response* response) { 666 dbus::Response* response) {
631 bool success = false; 667 bool success = false;
632 if (!response) { 668 if (!response) {
633 LOG(ERROR) << "Failed to call " << method_name; 669 LOG(ERROR) << "Failed to call " << method_name;
634 } else { 670 } else {
635 dbus::MessageReader reader(response); 671 dbus::MessageReader reader(response);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 base::PostTaskWithTraitsAndReplyWithResult( 923 base::PostTaskWithTraitsAndReplyWithResult(
888 FROM_HERE, 924 FROM_HERE,
889 base::TaskTraits() 925 base::TaskTraits()
890 .WithShutdownBehavior( 926 .WithShutdownBehavior(
891 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) 927 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
892 .MayBlock(), 928 .MayBlock(),
893 base::Bind(&GetFileContent, 929 base::Bind(&GetFileContent,
894 GetUserFilePath(cryptohome_id, kStubPolicyFile)), 930 GetUserFilePath(cryptohome_id, kStubPolicyFile)),
895 callback); 931 callback);
896 } 932 }
933 void RetrievePolicyForUserWithErrorCallback(
934 const cryptohome::Identification& cryptohome_id,
935 const RetrievePolicyCallback& callback,
936 const ErrorCallback& error_callback) override {
937 RetrievePolicyForUser(cryptohome_id, callback);
938 }
897 std::string BlockingRetrievePolicyForUser( 939 std::string BlockingRetrievePolicyForUser(
898 const cryptohome::Identification& cryptohome_id) override { 940 const cryptohome::Identification& cryptohome_id) override {
899 return GetFileContent(GetUserFilePath(cryptohome_id, kStubPolicyFile)); 941 return GetFileContent(GetUserFilePath(cryptohome_id, kStubPolicyFile));
900 } 942 }
901 void RetrieveDeviceLocalAccountPolicy( 943 void RetrieveDeviceLocalAccountPolicy(
902 const std::string& account_id, 944 const std::string& account_id,
903 const RetrievePolicyCallback& callback) override { 945 const RetrievePolicyCallback& callback) override {
904 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id), 946 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id),
905 callback); 947 callback);
906 } 948 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 1095
1054 SessionManagerClient* SessionManagerClient::Create( 1096 SessionManagerClient* SessionManagerClient::Create(
1055 DBusClientImplementationType type) { 1097 DBusClientImplementationType type) {
1056 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 1098 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
1057 return new SessionManagerClientImpl(); 1099 return new SessionManagerClientImpl();
1058 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); 1100 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type);
1059 return new SessionManagerClientStubImpl(); 1101 return new SessionManagerClientStubImpl();
1060 } 1102 }
1061 1103
1062 } // namespace chromeos 1104 } // namespace chromeos
OLDNEW
« chromeos/dbus/session_manager_client.h ('K') | « chromeos/dbus/session_manager_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698