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