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 <sys/socket.h> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | |
| 8 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 13 #include "base/location.h" |
| 11 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 12 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 14 #include "base/task_runner_util.h" | 17 #include "base/task_runner_util.h" |
| 15 #include "base/threading/worker_pool.h" | 18 #include "base/threading/worker_pool.h" |
| 16 #include "chromeos/chromeos_paths.h" | 19 #include "chromeos/chromeos_paths.h" |
| 17 #include "chromeos/dbus/blocking_method_caller.h" | 20 #include "chromeos/dbus/blocking_method_caller.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 // Helper to write a file in a background thread. | 54 // Helper to write a file in a background thread. |
| 52 void StoreFile(const base::FilePath& path, const std::string& data) { | 55 void StoreFile(const base::FilePath& path, const std::string& data) { |
| 53 const int size = static_cast<int>(data.size()); | 56 const int size = static_cast<int>(data.size()); |
| 54 if (path.empty() || | 57 if (path.empty() || |
| 55 !base::CreateDirectory(path.DirName()) || | 58 !base::CreateDirectory(path.DirName()) || |
| 56 base::WriteFile(path, data.data(), size) != size) { | 59 base::WriteFile(path, data.data(), size) != size) { |
| 57 LOG(WARNING) << "Failed to write to " << path.value(); | 60 LOG(WARNING) << "Failed to write to " << path.value(); |
| 58 } | 61 } |
| 59 } | 62 } |
| 60 | 63 |
| 64 // Creates a pair of file descriptors that form a conduit for trustworthy | |
| 65 // transfer of credentials between Chrome and the session_manager | |
| 66 void CreateValidCredConduit(dbus::FileDescriptor* local_auth_fd, | |
| 67 dbus::FileDescriptor* remote_auth_fd) { | |
| 68 int sockets[2] = {-1, -1}; | |
| 69 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) < 0) { | |
| 70 PLOG(ERROR) << "Failed to create a unix domain socketpair"; | |
| 71 return; | |
| 72 } | |
| 73 | |
| 74 local_auth_fd->PutValue(sockets[0]); | |
| 75 local_auth_fd->CheckValidity(); | |
| 76 | |
| 77 remote_auth_fd->PutValue(sockets[1]); | |
| 78 remote_auth_fd->CheckValidity(); | |
| 79 } | |
| 80 | |
| 61 } // namespace | 81 } // namespace |
| 62 | 82 |
| 63 // The SessionManagerClient implementation used in production. | 83 // The SessionManagerClient implementation used in production. |
| 64 class SessionManagerClientImpl : public SessionManagerClient { | 84 class SessionManagerClientImpl : public SessionManagerClient { |
| 65 public: | 85 public: |
| 66 SessionManagerClientImpl() | 86 SessionManagerClientImpl() |
| 67 : session_manager_proxy_(NULL), | 87 : session_manager_proxy_(NULL), |
| 68 screen_is_locked_(false), | 88 screen_is_locked_(false), |
| 69 weak_ptr_factory_(this) {} | 89 weak_ptr_factory_(this) {} |
| 70 | 90 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 89 | 109 |
| 90 bool IsScreenLocked() const override { return screen_is_locked_; } | 110 bool IsScreenLocked() const override { return screen_is_locked_; } |
| 91 | 111 |
| 92 void EmitLoginPromptVisible() override { | 112 void EmitLoginPromptVisible() override { |
| 93 SimpleMethodCallToSessionManager( | 113 SimpleMethodCallToSessionManager( |
| 94 login_manager::kSessionManagerEmitLoginPromptVisible); | 114 login_manager::kSessionManagerEmitLoginPromptVisible); |
| 95 FOR_EACH_OBSERVER(Observer, observers_, EmitLoginPromptVisibleCalled()); | 115 FOR_EACH_OBSERVER(Observer, observers_, EmitLoginPromptVisibleCalled()); |
| 96 } | 116 } |
| 97 | 117 |
| 98 void RestartJob(int pid, const std::string& command_line) override { | 118 void RestartJob(int pid, const std::string& command_line) override { |
| 99 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 119 dbus::ScopedFileDescriptor local_auth_fd(new dbus::FileDescriptor()); |
| 100 login_manager::kSessionManagerRestartJob); | 120 dbus::ScopedFileDescriptor remote_auth_fd(new dbus::FileDescriptor()); |
| 101 dbus::MessageWriter writer(&method_call); | 121 |
| 102 writer.AppendInt32(pid); | 122 base::Closure pipe_creator = base::Bind( |
| 103 writer.AppendString(command_line); | 123 &CreateValidCredConduit, local_auth_fd.get(), remote_auth_fd.get()); |
| 104 session_manager_proxy_->CallMethod( | 124 dbus::ObjectProxy::ResponseCallback on_restart_job = base::Bind( |
| 105 &method_call, | 125 &SessionManagerClientImpl::OnRestartJob, weak_ptr_factory_.GetWeakPtr(), |
| 106 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 126 base::Passed(&local_auth_fd)); |
| 107 base::Bind(&SessionManagerClientImpl::OnRestartJob, | 127 base::Closure call_performer = |
| 108 weak_ptr_factory_.GetWeakPtr())); | 128 base::Bind(&SessionManagerClientImpl::CallRestartJobWithValidFd, |
| 129 weak_ptr_factory_.GetWeakPtr(), | |
| 130 base::Passed(&remote_auth_fd), command_line, on_restart_job); | |
| 131 | |
| 132 base::WorkerPool::PostTaskAndReply(FROM_HERE, pipe_creator, call_performer, | |
| 133 false); | |
|
stevenjb
2015/04/28 01:25:26
This is all pretty confusing. I'm pretty sure I fo
| |
| 109 } | 134 } |
| 110 | 135 |
| 111 void StartSession(const std::string& user_email) override { | 136 void StartSession(const std::string& user_email) override { |
| 112 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 137 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 113 login_manager::kSessionManagerStartSession); | 138 login_manager::kSessionManagerStartSession); |
| 114 dbus::MessageWriter writer(&method_call); | 139 dbus::MessageWriter writer(&method_call); |
| 115 writer.AppendString(user_email); | 140 writer.AppendString(user_email); |
| 116 writer.AppendString(""); // Unique ID is deprecated | 141 writer.AppendString(""); // Unique ID is deprecated |
| 117 session_manager_proxy_->CallMethod( | 142 session_manager_proxy_->CallMethod( |
| 118 &method_call, | 143 &method_call, |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 session_manager_proxy_->CallMethod( | 397 session_manager_proxy_->CallMethod( |
| 373 &method_call, | 398 &method_call, |
| 374 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 399 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 375 base::Bind( | 400 base::Bind( |
| 376 &SessionManagerClientImpl::OnStorePolicy, | 401 &SessionManagerClientImpl::OnStorePolicy, |
| 377 weak_ptr_factory_.GetWeakPtr(), | 402 weak_ptr_factory_.GetWeakPtr(), |
| 378 method_name, | 403 method_name, |
| 379 callback)); | 404 callback)); |
| 380 } | 405 } |
| 381 | 406 |
| 407 void CallRestartJobWithValidFd(dbus::ScopedFileDescriptor remote_auth_fd, | |
| 408 const std::string& command_line, | |
| 409 dbus::ObjectProxy::ResponseCallback callback) { | |
| 410 dbus::MethodCall method_call( | |
| 411 login_manager::kSessionManagerInterface, | |
| 412 login_manager::kSessionManagerRestartJobWithAuth); | |
| 413 dbus::MessageWriter writer(&method_call); | |
| 414 writer.AppendFileDescriptor(*remote_auth_fd); | |
| 415 writer.AppendString(command_line); | |
| 416 session_manager_proxy_->CallMethod( | |
| 417 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, callback); | |
| 418 } | |
| 419 | |
| 382 // Called when kSessionManagerRestartJob method is complete. | 420 // Called when kSessionManagerRestartJob method is complete. |
| 383 void OnRestartJob(dbus::Response* response) { | 421 void OnRestartJob(dbus::ScopedFileDescriptor local_auth_fd, |
| 422 dbus::Response* response) { | |
| 384 LOG_IF(ERROR, !response) | 423 LOG_IF(ERROR, !response) |
| 385 << "Failed to call " | 424 << "Failed to call " |
| 386 << login_manager::kSessionManagerRestartJob; | 425 << login_manager::kSessionManagerRestartJob; |
| 387 } | 426 } |
| 388 | 427 |
| 389 // Called when kSessionManagerStartSession method is complete. | 428 // Called when kSessionManagerStartSession method is complete. |
| 390 void OnStartSession(dbus::Response* response) { | 429 void OnStartSession(dbus::Response* response) { |
| 391 LOG_IF(ERROR, !response) | 430 LOG_IF(ERROR, !response) |
| 392 << "Failed to call " | 431 << "Failed to call " |
| 393 << login_manager::kSessionManagerStartSession; | 432 << login_manager::kSessionManagerStartSession; |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 744 | 783 |
| 745 SessionManagerClient* SessionManagerClient::Create( | 784 SessionManagerClient* SessionManagerClient::Create( |
| 746 DBusClientImplementationType type) { | 785 DBusClientImplementationType type) { |
| 747 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 786 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 748 return new SessionManagerClientImpl(); | 787 return new SessionManagerClientImpl(); |
| 749 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 788 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 750 return new SessionManagerClientStubImpl(); | 789 return new SessionManagerClientStubImpl(); |
| 751 } | 790 } |
| 752 | 791 |
| 753 } // namespace chromeos | 792 } // namespace chromeos |
| OLD | NEW |