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 LOG(ERROR) << "DBus error " << response->ToString(); |
| 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) { |
| 528 VLOG(1) << "OnRestartJob"; |
522 LOG_IF(ERROR, !response) | 529 LOG_IF(ERROR, !response) |
523 << "Failed to call " | 530 << "Failed to call " |
524 << login_manager::kSessionManagerRestartJob; | 531 << login_manager::kSessionManagerRestartJob; |
525 } | 532 } |
526 | 533 |
527 // Called when kSessionManagerStartSession method is complete. | 534 // Called when kSessionManagerStartSession method is complete. |
528 void OnStartSession(dbus::Response* response) { | 535 void OnStartSession(dbus::Response* response) { |
529 LOG_IF(ERROR, !response) | 536 LOG_IF(ERROR, !response) |
530 << "Failed to call " | 537 << "Failed to call " |
531 << login_manager::kSessionManagerStartSession; | 538 << login_manager::kSessionManagerStartSession; |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 | 978 |
972 SessionManagerClient* SessionManagerClient::Create( | 979 SessionManagerClient* SessionManagerClient::Create( |
973 DBusClientImplementationType type) { | 980 DBusClientImplementationType type) { |
974 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 981 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
975 return new SessionManagerClientImpl(); | 982 return new SessionManagerClientImpl(); |
976 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 983 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
977 return new SessionManagerClientStubImpl(); | 984 return new SessionManagerClientStubImpl(); |
978 } | 985 } |
979 | 986 |
980 } // namespace chromeos | 987 } // namespace chromeos |
OLD | NEW |