Chromium Code Reviews| 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 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 | 78 |
| 79 local_auth_fd->PutValue(sockets[0]); | 79 local_auth_fd->PutValue(sockets[0]); |
| 80 local_auth_fd->CheckValidity(); | 80 local_auth_fd->CheckValidity(); |
| 81 | 81 |
| 82 remote_auth_fd->PutValue(sockets[1]); | 82 remote_auth_fd->PutValue(sockets[1]); |
| 83 remote_auth_fd->CheckValidity(); | 83 remote_auth_fd->CheckValidity(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void HandleDBusError(dbus::ErrorResponse* response) { | |
| 87 PLOG(ERROR) << "DBus error " << response->ToString(); | |
|
Daniel Erat
2016/08/25 02:13:19
LOG(ERROR) is the right thing to use here. PLOG is
achuithb
2016/08/25 21:10:02
Done.
Thanks for the explanation.
| |
| 88 } | |
| 89 | |
| 86 } // namespace | 90 } // namespace |
| 87 | 91 |
| 88 // The SessionManagerClient implementation used in production. | 92 // The SessionManagerClient implementation used in production. |
| 89 class SessionManagerClientImpl : public SessionManagerClient { | 93 class SessionManagerClientImpl : public SessionManagerClient { |
| 90 public: | 94 public: |
| 91 SessionManagerClientImpl() | 95 SessionManagerClientImpl() |
| 92 : session_manager_proxy_(NULL), | 96 : session_manager_proxy_(NULL), |
| 93 screen_is_locked_(false), | 97 screen_is_locked_(false), |
| 94 weak_ptr_factory_(this) {} | 98 weak_ptr_factory_(this) {} |
| 95 | 99 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 callback)); | 495 callback)); |
| 492 } | 496 } |
| 493 | 497 |
| 494 // Calls RestartJob to tell the session manager to restart the browser using | 498 // Calls RestartJob to tell the session manager to restart the browser using |
| 495 // the contents of |argv| as the command line, authorizing the call using | 499 // the contents of |argv| as the command line, authorizing the call using |
| 496 // credentials acquired via |remote_auth_fd|. Ownership of |local_auth_fd| is | 500 // credentials acquired via |remote_auth_fd|. Ownership of |local_auth_fd| is |
| 497 // held for the duration of the dbus call. | 501 // held for the duration of the dbus call. |
| 498 void CallRestartJobWithValidFd(dbus::ScopedFileDescriptor local_auth_fd, | 502 void CallRestartJobWithValidFd(dbus::ScopedFileDescriptor local_auth_fd, |
| 499 dbus::ScopedFileDescriptor remote_auth_fd, | 503 dbus::ScopedFileDescriptor remote_auth_fd, |
| 500 const std::vector<std::string>& argv) { | 504 const std::vector<std::string>& argv) { |
| 505 VLOG(1) << "CallRestartJobWithValidFd"; | |
| 501 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 506 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 502 login_manager::kSessionManagerRestartJob); | 507 login_manager::kSessionManagerRestartJob); |
| 503 dbus::MessageWriter writer(&method_call); | 508 dbus::MessageWriter writer(&method_call); |
| 504 writer.AppendFileDescriptor(*remote_auth_fd); | 509 writer.AppendFileDescriptor(*remote_auth_fd); |
| 505 writer.AppendArrayOfStrings(argv); | 510 writer.AppendArrayOfStrings(argv); |
| 506 | 511 |
| 507 // Ownership of local_auth_fd is passed to the callback that is to be | 512 // Ownership of local_auth_fd is passed to the callback that is to be |
| 508 // called on completion of this method call. This keeps the browser end | 513 // called on completion of this method call. This keeps the browser end |
| 509 // of the socket-pair alive for the duration of the RPC. | 514 // of the socket-pair alive for the duration of the RPC. |
| 510 session_manager_proxy_->CallMethod( | 515 session_manager_proxy_->CallMethodWithErrorCallback( |
| 511 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 516 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 512 base::Bind(&SessionManagerClientImpl::OnRestartJob, | 517 base::Bind(&SessionManagerClientImpl::OnRestartJob, |
| 513 weak_ptr_factory_.GetWeakPtr(), | 518 weak_ptr_factory_.GetWeakPtr(), |
| 514 base::Passed(&local_auth_fd))); | 519 base::Passed(&local_auth_fd)), |
| 520 base::Bind(HandleDBusError)); | |
| 515 } | 521 } |
| 516 | 522 |
| 517 // Called when kSessionManagerRestartJob method is complete. | 523 // Called when kSessionManagerRestartJob method is complete. |
| 518 // Now that the call is complete, local_auth_fd can be closed and discarded, | 524 // Now that the call is complete, local_auth_fd can be closed and discarded, |
| 519 // which will happen automatically when it goes out of scope. | 525 // which will happen automatically when it goes out of scope. |
| 520 void OnRestartJob(dbus::ScopedFileDescriptor local_auth_fd, | 526 void OnRestartJob(dbus::ScopedFileDescriptor local_auth_fd, |
| 521 dbus::Response* response) { | 527 dbus::Response* response) { |
| 522 LOG_IF(ERROR, !response) | 528 LOG_IF(ERROR, !response) |
| 523 << "Failed to call " | 529 << "Failed to call " |
| 524 << login_manager::kSessionManagerRestartJob; | 530 << login_manager::kSessionManagerRestartJob; |
|
Daniel Erat
2016/08/25 02:13:19
do you also want to add temporary logging on succe
achuithb
2016/08/25 21:10:02
Done.
| |
| 525 } | 531 } |
| 526 | 532 |
| 527 // Called when kSessionManagerStartSession method is complete. | 533 // Called when kSessionManagerStartSession method is complete. |
| 528 void OnStartSession(dbus::Response* response) { | 534 void OnStartSession(dbus::Response* response) { |
| 529 LOG_IF(ERROR, !response) | 535 LOG_IF(ERROR, !response) |
| 530 << "Failed to call " | 536 << "Failed to call " |
| 531 << login_manager::kSessionManagerStartSession; | 537 << login_manager::kSessionManagerStartSession; |
| 532 } | 538 } |
| 533 | 539 |
| 534 // Called when kSessionManagerStopSession method is complete. | 540 // Called when kSessionManagerStopSession method is complete. |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 971 | 977 |
| 972 SessionManagerClient* SessionManagerClient::Create( | 978 SessionManagerClient* SessionManagerClient::Create( |
| 973 DBusClientImplementationType type) { | 979 DBusClientImplementationType type) { |
| 974 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 980 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 975 return new SessionManagerClientImpl(); | 981 return new SessionManagerClientImpl(); |
| 976 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 982 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 977 return new SessionManagerClientStubImpl(); | 983 return new SessionManagerClientStubImpl(); |
| 978 } | 984 } |
| 979 | 985 |
| 980 } // namespace chromeos | 986 } // namespace chromeos |
| OLD | NEW |