| OLD | NEW |
| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 LOG(ERROR) << "Invalid method_name: " << method_name; | 145 LOG(ERROR) << "Invalid method_name: " << method_name; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace | 149 } // namespace |
| 150 | 150 |
| 151 // The SessionManagerClient implementation used in production. | 151 // The SessionManagerClient implementation used in production. |
| 152 class SessionManagerClientImpl : public SessionManagerClient { | 152 class SessionManagerClientImpl : public SessionManagerClient { |
| 153 public: | 153 public: |
| 154 SessionManagerClientImpl() | 154 SessionManagerClientImpl() |
| 155 : session_manager_proxy_(NULL), | 155 : weak_ptr_factory_(this) {} |
| 156 screen_is_locked_(false), | |
| 157 weak_ptr_factory_(this) {} | |
| 158 | 156 |
| 159 ~SessionManagerClientImpl() override {} | 157 ~SessionManagerClientImpl() override = default; |
| 160 | 158 |
| 161 // SessionManagerClient overrides: | 159 // SessionManagerClient overrides: |
| 162 void SetStubDelegate(StubDelegate* delegate) override { | 160 void SetStubDelegate(StubDelegate* delegate) override { |
| 163 // Do nothing; this isn't a stub implementation. | 161 // Do nothing; this isn't a stub implementation. |
| 164 } | 162 } |
| 165 | 163 |
| 166 void AddObserver(Observer* observer) override { | 164 void AddObserver(Observer* observer) override { |
| 167 observers_.AddObserver(observer); | 165 observers_.AddObserver(observer); |
| 168 } | 166 } |
| 169 | 167 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 200 | 198 |
| 201 void StartSession(const cryptohome::Identification& cryptohome_id) override { | 199 void StartSession(const cryptohome::Identification& cryptohome_id) override { |
| 202 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 200 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 203 login_manager::kSessionManagerStartSession); | 201 login_manager::kSessionManagerStartSession); |
| 204 dbus::MessageWriter writer(&method_call); | 202 dbus::MessageWriter writer(&method_call); |
| 205 writer.AppendString(cryptohome_id.id()); | 203 writer.AppendString(cryptohome_id.id()); |
| 206 writer.AppendString(""); // Unique ID is deprecated | 204 writer.AppendString(""); // Unique ID is deprecated |
| 207 session_manager_proxy_->CallMethod( | 205 session_manager_proxy_->CallMethod( |
| 208 &method_call, | 206 &method_call, |
| 209 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 207 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 210 base::Bind(&SessionManagerClientImpl::OnStartSession, | 208 dbus::ObjectProxy::EmptyResponseCallback()); |
| 211 weak_ptr_factory_.GetWeakPtr())); | |
| 212 } | 209 } |
| 213 | 210 |
| 214 void StopSession() override { | 211 void StopSession() override { |
| 215 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 212 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 216 login_manager::kSessionManagerStopSession); | 213 login_manager::kSessionManagerStopSession); |
| 217 dbus::MessageWriter writer(&method_call); | 214 dbus::MessageWriter writer(&method_call); |
| 218 writer.AppendString(""); // Unique ID is deprecated | 215 writer.AppendString(""); // Unique ID is deprecated |
| 219 session_manager_proxy_->CallMethod( | 216 session_manager_proxy_->CallMethod( |
| 220 &method_call, | 217 &method_call, |
| 221 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 218 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 222 base::Bind(&SessionManagerClientImpl::OnStopSession, | 219 dbus::ObjectProxy::EmptyResponseCallback()); |
| 223 weak_ptr_factory_.GetWeakPtr())); | |
| 224 } | 220 } |
| 225 | 221 |
| 226 void StartDeviceWipe() override { | 222 void StartDeviceWipe() override { |
| 227 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 223 SimpleMethodCallToSessionManager( |
| 228 login_manager::kSessionManagerStartDeviceWipe); | 224 login_manager::kSessionManagerStartDeviceWipe); |
| 229 session_manager_proxy_->CallMethod( | |
| 230 &method_call, | |
| 231 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 232 base::Bind(&SessionManagerClientImpl::OnDeviceWipe, | |
| 233 weak_ptr_factory_.GetWeakPtr())); | |
| 234 } | 225 } |
| 235 | 226 |
| 236 void RequestLockScreen() override { | 227 void RequestLockScreen() override { |
| 237 SimpleMethodCallToSessionManager(login_manager::kSessionManagerLockScreen); | 228 SimpleMethodCallToSessionManager(login_manager::kSessionManagerLockScreen); |
| 238 } | 229 } |
| 239 | 230 |
| 240 void NotifyLockScreenShown() override { | 231 void NotifyLockScreenShown() override { |
| 241 SimpleMethodCallToSessionManager( | 232 SimpleMethodCallToSessionManager( |
| 242 login_manager::kSessionManagerHandleLockScreenShown); | 233 login_manager::kSessionManagerHandleLockScreenShown); |
| 243 } | 234 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 333 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 343 login_manager::kSessionManagerStorePolicy); | 334 login_manager::kSessionManagerStorePolicy); |
| 344 dbus::MessageWriter writer(&method_call); | 335 dbus::MessageWriter writer(&method_call); |
| 345 // static_cast does not work due to signedness. | 336 // static_cast does not work due to signedness. |
| 346 writer.AppendArrayOfBytes( | 337 writer.AppendArrayOfBytes( |
| 347 reinterpret_cast<const uint8_t*>(policy_blob.data()), | 338 reinterpret_cast<const uint8_t*>(policy_blob.data()), |
| 348 policy_blob.size()); | 339 policy_blob.size()); |
| 349 session_manager_proxy_->CallMethod( | 340 session_manager_proxy_->CallMethod( |
| 350 &method_call, | 341 &method_call, |
| 351 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 342 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 352 base::Bind(&SessionManagerClientImpl::OnStorePolicy, | 343 base::Bind(&SessionManagerClientImpl::OnNoOutputParamResponse, |
| 353 weak_ptr_factory_.GetWeakPtr(), | 344 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 354 login_manager::kSessionManagerStorePolicy, | |
| 355 callback)); | |
| 356 } | 345 } |
| 357 | 346 |
| 358 void StorePolicyForUser(const cryptohome::Identification& cryptohome_id, | 347 void StorePolicyForUser(const cryptohome::Identification& cryptohome_id, |
| 359 const std::string& policy_blob, | 348 const std::string& policy_blob, |
| 360 const StorePolicyCallback& callback) override { | 349 const StorePolicyCallback& callback) override { |
| 361 CallStorePolicyByUsername(login_manager::kSessionManagerStorePolicyForUser, | 350 CallStorePolicyByUsername(login_manager::kSessionManagerStorePolicyForUser, |
| 362 cryptohome_id.id(), policy_blob, callback); | 351 cryptohome_id.id(), policy_blob, callback); |
| 363 } | 352 } |
| 364 | 353 |
| 365 void StoreDeviceLocalAccountPolicy( | 354 void StoreDeviceLocalAccountPolicy( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 weak_ptr_factory_.GetWeakPtr(), callback), | 422 weak_ptr_factory_.GetWeakPtr(), callback), |
| 434 base::Bind(&SessionManagerClientImpl::OnStartArcInstanceFailed, | 423 base::Bind(&SessionManagerClientImpl::OnStartArcInstanceFailed, |
| 435 weak_ptr_factory_.GetWeakPtr(), callback)); | 424 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 436 } | 425 } |
| 437 | 426 |
| 438 void StopArcInstance(const ArcCallback& callback) override { | 427 void StopArcInstance(const ArcCallback& callback) override { |
| 439 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 428 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 440 login_manager::kSessionManagerStopArcInstance); | 429 login_manager::kSessionManagerStopArcInstance); |
| 441 session_manager_proxy_->CallMethod( | 430 session_manager_proxy_->CallMethod( |
| 442 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 431 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 443 base::Bind(&SessionManagerClientImpl::OnArcMethod, | 432 base::Bind(&SessionManagerClientImpl::OnNoOutputParamResponse, |
| 444 weak_ptr_factory_.GetWeakPtr(), | 433 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 445 login_manager::kSessionManagerStopArcInstance, callback)); | |
| 446 } | 434 } |
| 447 | 435 |
| 448 void SetArcCpuRestriction( | 436 void SetArcCpuRestriction( |
| 449 login_manager::ContainerCpuRestrictionState restriction_state, | 437 login_manager::ContainerCpuRestrictionState restriction_state, |
| 450 const ArcCallback& callback) override { | 438 const ArcCallback& callback) override { |
| 451 dbus::MethodCall method_call( | 439 dbus::MethodCall method_call( |
| 452 login_manager::kSessionManagerInterface, | 440 login_manager::kSessionManagerInterface, |
| 453 login_manager::kSessionManagerSetArcCpuRestriction); | 441 login_manager::kSessionManagerSetArcCpuRestriction); |
| 454 dbus::MessageWriter writer(&method_call); | 442 dbus::MessageWriter writer(&method_call); |
| 455 writer.AppendUint32(restriction_state); | 443 writer.AppendUint32(restriction_state); |
| 456 session_manager_proxy_->CallMethod( | 444 session_manager_proxy_->CallMethod( |
| 457 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 445 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 458 base::Bind(&SessionManagerClientImpl::OnArcMethod, | 446 base::Bind(&SessionManagerClientImpl::OnNoOutputParamResponse, |
| 459 weak_ptr_factory_.GetWeakPtr(), | 447 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 460 login_manager::kSessionManagerSetArcCpuRestriction, | |
| 461 callback)); | |
| 462 } | 448 } |
| 463 | 449 |
| 464 void EmitArcBooted(const cryptohome::Identification& cryptohome_id, | 450 void EmitArcBooted(const cryptohome::Identification& cryptohome_id, |
| 465 const ArcCallback& callback) override { | 451 const ArcCallback& callback) override { |
| 466 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 452 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 467 login_manager::kSessionManagerEmitArcBooted); | 453 login_manager::kSessionManagerEmitArcBooted); |
| 468 dbus::MessageWriter writer(&method_call); | 454 dbus::MessageWriter writer(&method_call); |
| 469 writer.AppendString(cryptohome_id.id()); | 455 writer.AppendString(cryptohome_id.id()); |
| 470 session_manager_proxy_->CallMethod( | 456 session_manager_proxy_->CallMethod( |
| 471 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 457 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 472 base::Bind(&SessionManagerClientImpl::OnArcMethod, | 458 base::Bind(&SessionManagerClientImpl::OnNoOutputParamResponse, |
| 473 weak_ptr_factory_.GetWeakPtr(), | 459 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 474 login_manager::kSessionManagerEmitArcBooted, callback)); | |
| 475 } | 460 } |
| 476 | 461 |
| 477 void GetArcStartTime(const GetArcStartTimeCallback& callback) override { | 462 void GetArcStartTime(const GetArcStartTimeCallback& callback) override { |
| 478 dbus::MethodCall method_call( | 463 dbus::MethodCall method_call( |
| 479 login_manager::kSessionManagerInterface, | 464 login_manager::kSessionManagerInterface, |
| 480 login_manager::kSessionManagerGetArcStartTimeTicks); | 465 login_manager::kSessionManagerGetArcStartTimeTicks); |
| 481 | 466 |
| 482 session_manager_proxy_->CallMethod( | 467 session_manager_proxy_->CallMethod( |
| 483 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 468 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 484 base::Bind(&SessionManagerClientImpl::OnGetArcStartTime, | 469 base::Bind(&SessionManagerClientImpl::OnGetArcStartTime, |
| 485 weak_ptr_factory_.GetWeakPtr(), callback)); | 470 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 486 } | 471 } |
| 487 | 472 |
| 488 void RemoveArcData(const cryptohome::Identification& cryptohome_id, | 473 void RemoveArcData(const cryptohome::Identification& cryptohome_id, |
| 489 const ArcCallback& callback) override { | 474 const ArcCallback& callback) override { |
| 490 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 475 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 491 login_manager::kSessionManagerRemoveArcData); | 476 login_manager::kSessionManagerRemoveArcData); |
| 492 dbus::MessageWriter writer(&method_call); | 477 dbus::MessageWriter writer(&method_call); |
| 493 writer.AppendString(cryptohome_id.id()); | 478 writer.AppendString(cryptohome_id.id()); |
| 494 session_manager_proxy_->CallMethod( | 479 session_manager_proxy_->CallMethod( |
| 495 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 480 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 496 base::Bind(&SessionManagerClientImpl::OnArcMethod, | 481 base::Bind(&SessionManagerClientImpl::OnNoOutputParamResponse, |
| 497 weak_ptr_factory_.GetWeakPtr(), | 482 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 498 login_manager::kSessionManagerRemoveArcData, callback)); | |
| 499 } | 483 } |
| 500 | 484 |
| 501 protected: | 485 protected: |
| 502 void Init(dbus::Bus* bus) override { | 486 void Init(dbus::Bus* bus) override { |
| 503 session_manager_proxy_ = bus->GetObjectProxy( | 487 session_manager_proxy_ = bus->GetObjectProxy( |
| 504 login_manager::kSessionManagerServiceName, | 488 login_manager::kSessionManagerServiceName, |
| 505 dbus::ObjectPath(login_manager::kSessionManagerServicePath)); | 489 dbus::ObjectPath(login_manager::kSessionManagerServicePath)); |
| 506 blocking_method_caller_.reset( | 490 blocking_method_caller_.reset( |
| 507 new BlockingMethodCaller(bus, session_manager_proxy_)); | 491 new BlockingMethodCaller(bus, session_manager_proxy_)); |
| 508 | 492 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 // response. | 533 // response. |
| 550 void SimpleMethodCallToSessionManager(const std::string& method_name) { | 534 void SimpleMethodCallToSessionManager(const std::string& method_name) { |
| 551 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 535 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 552 method_name); | 536 method_name); |
| 553 session_manager_proxy_->CallMethod( | 537 session_manager_proxy_->CallMethod( |
| 554 &method_call, | 538 &method_call, |
| 555 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 539 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 556 dbus::ObjectProxy::EmptyResponseCallback()); | 540 dbus::ObjectProxy::EmptyResponseCallback()); |
| 557 } | 541 } |
| 558 | 542 |
| 543 // Calls given callback (if non-null), with the |success| boolean |
| 544 // representing the dbus call was successful or not. |
| 545 void OnNoOutputParamResponse( |
| 546 const base::Callback<void(bool success)>& callback, |
| 547 dbus::Response* response) { |
| 548 if (!callback.is_null()) |
| 549 callback.Run(response != nullptr); |
| 550 } |
| 551 |
| 559 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser. | 552 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser. |
| 560 void CallRetrievePolicyByUsername(const std::string& method_name, | 553 void CallRetrievePolicyByUsername(const std::string& method_name, |
| 561 const std::string& account_id, | 554 const std::string& account_id, |
| 562 const RetrievePolicyCallback& callback) { | 555 const RetrievePolicyCallback& callback) { |
| 563 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 556 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 564 method_name); | 557 method_name); |
| 565 dbus::MessageWriter writer(&method_call); | 558 dbus::MessageWriter writer(&method_call); |
| 566 writer.AppendString(account_id); | 559 writer.AppendString(account_id); |
| 567 session_manager_proxy_->CallMethodWithErrorCallback( | 560 session_manager_proxy_->CallMethodWithErrorCallback( |
| 568 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 561 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 dbus::MessageWriter writer(&method_call); | 601 dbus::MessageWriter writer(&method_call); |
| 609 writer.AppendString(account_id); | 602 writer.AppendString(account_id); |
| 610 // static_cast does not work due to signedness. | 603 // static_cast does not work due to signedness. |
| 611 writer.AppendArrayOfBytes( | 604 writer.AppendArrayOfBytes( |
| 612 reinterpret_cast<const uint8_t*>(policy_blob.data()), | 605 reinterpret_cast<const uint8_t*>(policy_blob.data()), |
| 613 policy_blob.size()); | 606 policy_blob.size()); |
| 614 session_manager_proxy_->CallMethod( | 607 session_manager_proxy_->CallMethod( |
| 615 &method_call, | 608 &method_call, |
| 616 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 609 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 617 base::Bind( | 610 base::Bind( |
| 618 &SessionManagerClientImpl::OnStorePolicy, | 611 &SessionManagerClientImpl::OnNoOutputParamResponse, |
| 619 weak_ptr_factory_.GetWeakPtr(), | 612 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 620 method_name, | |
| 621 callback)); | |
| 622 } | 613 } |
| 623 | 614 |
| 624 // Called when kSessionManagerRestartJob method is complete. | 615 // Called when kSessionManagerRestartJob method is complete. |
| 625 void OnRestartJob(const VoidDBusMethodCallback& callback, | 616 void OnRestartJob(const VoidDBusMethodCallback& callback, |
| 626 dbus::Response* response) { | 617 dbus::Response* response) { |
| 627 LOG_IF(ERROR, !response) | 618 LOG_IF(ERROR, !response) |
| 628 << "Failed to call " | 619 << "Failed to call " |
| 629 << login_manager::kSessionManagerRestartJob; | 620 << login_manager::kSessionManagerRestartJob; |
| 630 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS | 621 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS |
| 631 : DBUS_METHOD_CALL_FAILURE); | 622 : DBUS_METHOD_CALL_FAILURE); |
| 632 } | 623 } |
| 633 | 624 |
| 634 // Called when kSessionManagerStartSession method is complete. | |
| 635 void OnStartSession(dbus::Response* response) { | |
| 636 LOG_IF(ERROR, !response) | |
| 637 << "Failed to call " | |
| 638 << login_manager::kSessionManagerStartSession; | |
| 639 } | |
| 640 | |
| 641 // Called when kSessionManagerStopSession method is complete. | |
| 642 void OnStopSession(dbus::Response* response) { | |
| 643 LOG_IF(ERROR, !response) | |
| 644 << "Failed to call " | |
| 645 << login_manager::kSessionManagerStopSession; | |
| 646 } | |
| 647 | |
| 648 // Called when kSessionManagerStopSession method is complete. | |
| 649 void OnDeviceWipe(dbus::Response* response) { | |
| 650 LOG_IF(ERROR, !response) | |
| 651 << "Failed to call " | |
| 652 << login_manager::kSessionManagerStartDeviceWipe; | |
| 653 } | |
| 654 | |
| 655 // Called when kSessionManagerRetrieveActiveSessions method is complete. | 625 // Called when kSessionManagerRetrieveActiveSessions method is complete. |
| 656 void OnRetrieveActiveSessions(const std::string& method_name, | 626 void OnRetrieveActiveSessions(const std::string& method_name, |
| 657 const ActiveSessionsCallback& callback, | 627 const ActiveSessionsCallback& callback, |
| 658 dbus::Response* response) { | 628 dbus::Response* response) { |
| 659 ActiveSessionsMap sessions; | 629 ActiveSessionsMap sessions; |
| 660 bool success = false; | 630 bool success = false; |
| 661 if (!response) { | 631 if (!response) { |
| 662 LOG(ERROR) << "Failed to call " << method_name; | |
| 663 callback.Run(sessions, success); | 632 callback.Run(sessions, success); |
| 664 return; | 633 return; |
| 665 } | 634 } |
| 666 | 635 |
| 667 dbus::MessageReader reader(response); | 636 dbus::MessageReader reader(response); |
| 668 dbus::MessageReader array_reader(NULL); | 637 dbus::MessageReader array_reader(nullptr); |
| 669 | 638 |
| 670 if (!reader.PopArray(&array_reader)) { | 639 if (!reader.PopArray(&array_reader)) { |
| 671 LOG(ERROR) << method_name << " response is incorrect: " | 640 LOG(ERROR) << method_name << " response is incorrect: " |
| 672 << response->ToString(); | 641 << response->ToString(); |
| 673 } else { | 642 } else { |
| 674 while (array_reader.HasMoreData()) { | 643 while (array_reader.HasMoreData()) { |
| 675 dbus::MessageReader dict_entry_reader(NULL); | 644 dbus::MessageReader dict_entry_reader(nullptr); |
| 676 std::string key; | 645 std::string key; |
| 677 std::string value; | 646 std::string value; |
| 678 if (!array_reader.PopDictEntry(&dict_entry_reader) || | 647 if (!array_reader.PopDictEntry(&dict_entry_reader) || |
| 679 !dict_entry_reader.PopString(&key) || | 648 !dict_entry_reader.PopString(&key) || |
| 680 !dict_entry_reader.PopString(&value)) { | 649 !dict_entry_reader.PopString(&value)) { |
| 681 LOG(ERROR) << method_name << " response is incorrect: " | 650 LOG(ERROR) << method_name << " response is incorrect: " |
| 682 << response->ToString(); | 651 << response->ToString(); |
| 683 } else { | 652 } else { |
| 684 sessions[cryptohome::Identification::FromString(key)] = value; | 653 sessions[cryptohome::Identification::FromString(key)] = value; |
| 685 } | 654 } |
| 686 } | 655 } |
| 687 success = true; | 656 success = true; |
| 688 } | 657 } |
| 689 callback.Run(sessions, success); | 658 callback.Run(sessions, success); |
| 690 } | 659 } |
| 691 | 660 |
| 692 void ExtractString(const std::string& method_name, | 661 void ExtractString(const std::string& method_name, |
| 693 dbus::Response* response, | 662 dbus::Response* response, |
| 694 std::string* extracted) { | 663 std::string* extracted) { |
| 695 if (!response) { | 664 if (!response) { |
| 696 LOG(ERROR) << "Failed to call " << method_name; | 665 LOG(ERROR) << "Failed to call " << method_name; |
| 697 return; | 666 return; |
| 698 } | 667 } |
| 699 dbus::MessageReader reader(response); | 668 dbus::MessageReader reader(response); |
| 700 const uint8_t* values = NULL; | 669 const uint8_t* values = nullptr; |
| 701 size_t length = 0; | 670 size_t length = 0; |
| 702 if (!reader.PopArrayOfBytes(&values, &length)) { | 671 if (!reader.PopArrayOfBytes(&values, &length)) { |
| 703 LOG(ERROR) << "Invalid response: " << response->ToString(); | 672 LOG(ERROR) << "Invalid response: " << response->ToString(); |
| 704 return; | 673 return; |
| 705 } | 674 } |
| 706 // static_cast does not work due to signedness. | 675 // static_cast does not work due to signedness. |
| 707 extracted->assign(reinterpret_cast<const char*>(values), length); | 676 extracted->assign(reinterpret_cast<const char*>(values), length); |
| 708 } | 677 } |
| 709 | 678 |
| 710 // Called when kSessionManagerRetrievePolicy or | 679 // Called when kSessionManagerRetrievePolicy or |
| (...skipping 13 matching lines...) Expand all Loading... |
| 724 void OnRetrievePolicyError(const std::string& method_name, | 693 void OnRetrievePolicyError(const std::string& method_name, |
| 725 const RetrievePolicyCallback& callback, | 694 const RetrievePolicyCallback& callback, |
| 726 dbus::ErrorResponse* response) { | 695 dbus::ErrorResponse* response) { |
| 727 RetrievePolicyResponseType response_type = | 696 RetrievePolicyResponseType response_type = |
| 728 GetResponseTypeBasedOnError(response->GetErrorName()); | 697 GetResponseTypeBasedOnError(response->GetErrorName()); |
| 729 callback.Run(std::string(), response_type); | 698 callback.Run(std::string(), response_type); |
| 730 | 699 |
| 731 LogPolicyResponseUma(method_name, response_type); | 700 LogPolicyResponseUma(method_name, response_type); |
| 732 } | 701 } |
| 733 | 702 |
| 734 // Called when kSessionManagerStorePolicy or kSessionManagerStorePolicyForUser | |
| 735 // method is complete. | |
| 736 void OnStorePolicy(const std::string& method_name, | |
| 737 const StorePolicyCallback& callback, | |
| 738 dbus::Response* response) { | |
| 739 bool success = response != nullptr; | |
| 740 LOG_IF(ERROR, !success) << "Failed to call " << method_name; | |
| 741 callback.Run(success); | |
| 742 } | |
| 743 | |
| 744 // Called when the owner key set signal is received. | 703 // Called when the owner key set signal is received. |
| 745 void OwnerKeySetReceived(dbus::Signal* signal) { | 704 void OwnerKeySetReceived(dbus::Signal* signal) { |
| 746 dbus::MessageReader reader(signal); | 705 dbus::MessageReader reader(signal); |
| 747 std::string result_string; | 706 std::string result_string; |
| 748 if (!reader.PopString(&result_string)) { | 707 if (!reader.PopString(&result_string)) { |
| 749 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | 708 LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
| 750 return; | 709 return; |
| 751 } | 710 } |
| 752 const bool success = base::StartsWith(result_string, "success", | 711 const bool success = base::StartsWith(result_string, "success", |
| 753 base::CompareCase::INSENSITIVE_ASCII); | 712 base::CompareCase::INSENSITIVE_ASCII); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 void SignalConnected(const std::string& interface_name, | 755 void SignalConnected(const std::string& interface_name, |
| 797 const std::string& signal_name, | 756 const std::string& signal_name, |
| 798 bool success) { | 757 bool success) { |
| 799 LOG_IF(ERROR, !success) << "Failed to connect to " << signal_name; | 758 LOG_IF(ERROR, !success) << "Failed to connect to " << signal_name; |
| 800 } | 759 } |
| 801 | 760 |
| 802 // Called when kSessionManagerGetServerBackedStateKeys method is complete. | 761 // Called when kSessionManagerGetServerBackedStateKeys method is complete. |
| 803 void OnGetServerBackedStateKeys(const StateKeysCallback& callback, | 762 void OnGetServerBackedStateKeys(const StateKeysCallback& callback, |
| 804 dbus::Response* response) { | 763 dbus::Response* response) { |
| 805 std::vector<std::string> state_keys; | 764 std::vector<std::string> state_keys; |
| 806 if (!response) { | 765 if (response) { |
| 807 LOG(ERROR) << "Failed to call " | |
| 808 << login_manager::kSessionManagerGetServerBackedStateKeys; | |
| 809 } else { | |
| 810 dbus::MessageReader reader(response); | 766 dbus::MessageReader reader(response); |
| 811 dbus::MessageReader array_reader(NULL); | 767 dbus::MessageReader array_reader(nullptr); |
| 812 | 768 |
| 813 if (!reader.PopArray(&array_reader)) { | 769 if (!reader.PopArray(&array_reader)) { |
| 814 LOG(ERROR) << "Bad response: " << response->ToString(); | 770 LOG(ERROR) << "Bad response: " << response->ToString(); |
| 815 } else { | 771 } else { |
| 816 while (array_reader.HasMoreData()) { | 772 while (array_reader.HasMoreData()) { |
| 817 const uint8_t* data = NULL; | 773 const uint8_t* data = nullptr; |
| 818 size_t size = 0; | 774 size_t size = 0; |
| 819 if (!array_reader.PopArrayOfBytes(&data, &size)) { | 775 if (!array_reader.PopArrayOfBytes(&data, &size)) { |
| 820 LOG(ERROR) << "Bad response: " << response->ToString(); | 776 LOG(ERROR) << "Bad response: " << response->ToString(); |
| 821 state_keys.clear(); | 777 state_keys.clear(); |
| 822 break; | 778 break; |
| 823 } | 779 } |
| 824 state_keys.push_back( | 780 state_keys.emplace_back(reinterpret_cast<const char*>(data), size); |
| 825 std::string(reinterpret_cast<const char*>(data), size)); | |
| 826 } | 781 } |
| 827 } | 782 } |
| 828 } | 783 } |
| 829 | 784 |
| 830 if (!callback.is_null()) | 785 if (!callback.is_null()) |
| 831 callback.Run(state_keys); | 786 callback.Run(state_keys); |
| 832 } | 787 } |
| 833 | 788 |
| 834 // Called when kSessionManagerCheckArcAvailability method is complete. | 789 // Called when kSessionManagerCheckArcAvailability method is complete. |
| 835 void OnCheckArcAvailability(const ArcCallback& callback, | 790 void OnCheckArcAvailability(const ArcCallback& callback, |
| 836 dbus::Response* response) { | 791 dbus::Response* response) { |
| 837 bool available = false; | 792 bool available = false; |
| 838 if (!response) { | 793 if (response) { |
| 839 LOG(ERROR) << "Failed to call " | |
| 840 << login_manager::kSessionManagerCheckArcAvailability; | |
| 841 } else { | |
| 842 dbus::MessageReader reader(response); | 794 dbus::MessageReader reader(response); |
| 843 if (!reader.PopBool(&available)) | 795 if (!reader.PopBool(&available)) |
| 844 LOG(ERROR) << "Invalid response: " << response->ToString(); | 796 LOG(ERROR) << "Invalid response: " << response->ToString(); |
| 845 } | 797 } |
| 846 if (!callback.is_null()) | 798 if (!callback.is_null()) |
| 847 callback.Run(available); | 799 callback.Run(available); |
| 848 } | 800 } |
| 849 | 801 |
| 850 void OnGetArcStartTime(const GetArcStartTimeCallback& callback, | 802 void OnGetArcStartTime(const GetArcStartTimeCallback& callback, |
| 851 dbus::Response* response) { | 803 dbus::Response* response) { |
| 852 bool success = false; | 804 bool success = false; |
| 853 base::TimeTicks arc_start_time; | 805 base::TimeTicks arc_start_time; |
| 854 if (!response) { | 806 if (response) { |
| 855 LOG(ERROR) << "Failed to call " | |
| 856 << login_manager::kSessionManagerGetArcStartTimeTicks; | |
| 857 } else { | |
| 858 dbus::MessageReader reader(response); | 807 dbus::MessageReader reader(response); |
| 859 int64_t ticks = 0; | 808 int64_t ticks = 0; |
| 860 if (reader.PopInt64(&ticks)) { | 809 if (reader.PopInt64(&ticks)) { |
| 861 success = true; | 810 success = true; |
| 862 arc_start_time = base::TimeTicks::FromInternalValue(ticks); | 811 arc_start_time = base::TimeTicks::FromInternalValue(ticks); |
| 863 } else { | 812 } else { |
| 864 LOG(ERROR) << "Invalid response: " << response->ToString(); | 813 LOG(ERROR) << "Invalid response: " << response->ToString(); |
| 865 } | 814 } |
| 866 } | 815 } |
| 867 callback.Run(success, arc_start_time); | 816 callback.Run(success, arc_start_time); |
| 868 } | 817 } |
| 869 | 818 |
| 870 // Called when kSessionManagerStartArcInstance or | |
| 871 // kSessionManagerStopArcInstance methods complete. | |
| 872 void OnArcMethod(const std::string& method_name, | |
| 873 const ArcCallback& callback, | |
| 874 dbus::Response* response) { | |
| 875 bool success = false; | |
| 876 if (!response) { | |
| 877 LOG(ERROR) << "Failed to call " << method_name; | |
| 878 } else { | |
| 879 success = true; | |
| 880 } | |
| 881 | |
| 882 if (!callback.is_null()) | |
| 883 callback.Run(success); | |
| 884 } | |
| 885 | |
| 886 void OnStartArcInstanceSucceeded(const StartArcInstanceCallback& callback, | 819 void OnStartArcInstanceSucceeded(const StartArcInstanceCallback& callback, |
| 887 dbus::Response* response) { | 820 dbus::Response* response) { |
| 888 if (!callback.is_null()) | 821 if (!callback.is_null()) |
| 889 callback.Run(StartArcInstanceResult::SUCCESS); | 822 callback.Run(StartArcInstanceResult::SUCCESS); |
| 890 } | 823 } |
| 891 | 824 |
| 892 void OnStartArcInstanceFailed(const StartArcInstanceCallback& callback, | 825 void OnStartArcInstanceFailed(const StartArcInstanceCallback& callback, |
| 893 dbus::ErrorResponse* response) { | 826 dbus::ErrorResponse* response) { |
| 894 LOG(ERROR) << "Failed to call StartArcInstance: " | 827 LOG(ERROR) << "Failed to call StartArcInstance: " |
| 895 << (response ? response->ToString() : "(null)"); | 828 << (response ? response->ToString() : "(null)"); |
| 896 if (!callback.is_null()) { | 829 if (!callback.is_null()) { |
| 897 callback.Run(response && response->GetErrorName() == | 830 callback.Run(response && response->GetErrorName() == |
| 898 login_manager::dbus_error::kLowFreeDisk | 831 login_manager::dbus_error::kLowFreeDisk |
| 899 ? StartArcInstanceResult::LOW_FREE_DISK_SPACE | 832 ? StartArcInstanceResult::LOW_FREE_DISK_SPACE |
| 900 : StartArcInstanceResult::UNKNOWN_ERROR); | 833 : StartArcInstanceResult::UNKNOWN_ERROR); |
| 901 } | 834 } |
| 902 } | 835 } |
| 903 | 836 |
| 904 dbus::ObjectProxy* session_manager_proxy_; | 837 dbus::ObjectProxy* session_manager_proxy_ = nullptr; |
| 905 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; | 838 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; |
| 906 base::ObserverList<Observer> observers_; | 839 base::ObserverList<Observer> observers_; |
| 907 | 840 |
| 908 // Most recent screen-lock state received from session_manager. | 841 // Most recent screen-lock state received from session_manager. |
| 909 bool screen_is_locked_; | 842 bool screen_is_locked_ = false; |
| 910 | 843 |
| 911 // Note: This should remain the last member so it'll be destroyed and | 844 // Note: This should remain the last member so it'll be destroyed and |
| 912 // invalidate its weak pointers before any other members are destroyed. | 845 // invalidate its weak pointers before any other members are destroyed. |
| 913 base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; | 846 base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; |
| 914 | 847 |
| 915 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientImpl); | 848 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientImpl); |
| 916 }; | 849 }; |
| 917 | 850 |
| 918 // The SessionManagerClient implementation used on Linux desktop, | 851 // The SessionManagerClient implementation used on Linux desktop, |
| 919 // which does nothing. | 852 // which does nothing. |
| 920 class SessionManagerClientStubImpl : public SessionManagerClient { | 853 class SessionManagerClientStubImpl : public SessionManagerClient { |
| 921 public: | 854 public: |
| 922 SessionManagerClientStubImpl() : delegate_(NULL), screen_is_locked_(false) {} | 855 SessionManagerClientStubImpl() = default; |
| 923 ~SessionManagerClientStubImpl() override {} | 856 ~SessionManagerClientStubImpl() override = default; |
| 924 | 857 |
| 925 // SessionManagerClient overrides | 858 // SessionManagerClient overrides |
| 926 void Init(dbus::Bus* bus) override {} | 859 void Init(dbus::Bus* bus) override {} |
| 927 void SetStubDelegate(StubDelegate* delegate) override { | 860 void SetStubDelegate(StubDelegate* delegate) override { |
| 928 delegate_ = delegate; | 861 delegate_ = delegate; |
| 929 } | 862 } |
| 930 void AddObserver(Observer* observer) override { | 863 void AddObserver(Observer* observer) override { |
| 931 observers_.AddObserver(observer); | 864 observers_.AddObserver(observer); |
| 932 } | 865 } |
| 933 void RemoveObserver(Observer* observer) override { | 866 void RemoveObserver(Observer* observer) override { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 | 1066 |
| 1134 void RemoveArcData(const cryptohome::Identification& cryptohome_id, | 1067 void RemoveArcData(const cryptohome::Identification& cryptohome_id, |
| 1135 const ArcCallback& callback) override { | 1068 const ArcCallback& callback) override { |
| 1136 if (callback.is_null()) | 1069 if (callback.is_null()) |
| 1137 return; | 1070 return; |
| 1138 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 1071 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 1139 base::Bind(callback, false)); | 1072 base::Bind(callback, false)); |
| 1140 } | 1073 } |
| 1141 | 1074 |
| 1142 private: | 1075 private: |
| 1143 StubDelegate* delegate_; // Weak pointer; may be NULL. | 1076 StubDelegate* delegate_ = nullptr; // Weak pointer; may be nullptr. |
| 1144 base::ObserverList<Observer> observers_; | 1077 base::ObserverList<Observer> observers_; |
| 1145 std::string device_policy_; | 1078 std::string device_policy_; |
| 1146 bool screen_is_locked_; | 1079 bool screen_is_locked_ = false; |
| 1147 | 1080 |
| 1148 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientStubImpl); | 1081 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientStubImpl); |
| 1149 }; | 1082 }; |
| 1150 | 1083 |
| 1151 SessionManagerClient::SessionManagerClient() { | 1084 SessionManagerClient::SessionManagerClient() { |
| 1152 } | 1085 } |
| 1153 | 1086 |
| 1154 SessionManagerClient::~SessionManagerClient() { | 1087 SessionManagerClient::~SessionManagerClient() { |
| 1155 } | 1088 } |
| 1156 | 1089 |
| 1157 SessionManagerClient* SessionManagerClient::Create( | 1090 SessionManagerClient* SessionManagerClient::Create( |
| 1158 DBusClientImplementationType type) { | 1091 DBusClientImplementationType type) { |
| 1159 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 1092 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 1160 return new SessionManagerClientImpl(); | 1093 return new SessionManagerClientImpl(); |
| 1161 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 1094 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
| 1162 return new SessionManagerClientStubImpl(); | 1095 return new SessionManagerClientStubImpl(); |
| 1163 } | 1096 } |
| 1164 | 1097 |
| 1165 } // namespace chromeos | 1098 } // namespace chromeos |
| OLD | NEW |