Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/fake_permission_broker_client.h" | 5 #include "chromeos/dbus/fake_permission_broker_client.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/posix/eintr_wrapper.h" | 14 #include "base/posix/eintr_wrapper.h" |
| 15 #include "base/strings/stringprintf.h" | |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/threading/worker_pool.h" | 17 #include "base/threading/worker_pool.h" |
| 17 #include "dbus/file_descriptor.h" | 18 #include "dbus/file_descriptor.h" |
| 18 | 19 |
| 19 namespace chromeos { | 20 namespace chromeos { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // So that real devices can be accessed by tests and "Chromium OS on Linux" this | 24 // So that real devices can be accessed by tests and "Chromium OS on Linux" this |
| 24 // function implements a simplified version of the method implemented by the | 25 // function implements a simplified version of the method implemented by the |
| 25 // permission broker by opening the path specified and returning the resulting | 26 // permission broker by opening the path specified and returning the resulting |
| 26 // file descriptor. | 27 // file descriptor. |
| 27 void OpenPathAndValidate( | 28 void OpenPathAndValidate( |
| 28 const std::string& path, | 29 const std::string& path, |
| 29 const PermissionBrokerClient::OpenPathCallback& callback, | 30 const PermissionBrokerClient::OpenPathCallback& callback, |
| 31 const PermissionBrokerClient::ErrorCallback& error_callback, | |
| 30 scoped_refptr<base::TaskRunner> task_runner) { | 32 scoped_refptr<base::TaskRunner> task_runner) { |
| 31 dbus::FileDescriptor dbus_fd; | |
| 32 int fd = HANDLE_EINTR(open(path.c_str(), O_RDWR)); | 33 int fd = HANDLE_EINTR(open(path.c_str(), O_RDWR)); |
| 33 if (fd < 0) { | 34 if (fd < 0) { |
| 34 PLOG(WARNING) << "Failed to open '" << path << "'"; | 35 int error_code = logging::GetLastSystemErrorCode(); |
| 36 task_runner->PostTask( | |
| 37 FROM_HERE, | |
| 38 base::Bind(error_callback, "open_failed", | |
|
stevenjb
2016/02/09 23:16:51
nit: define 'open_failed' as a const, make availab
Reilly Grant (use Gerrit)
2016/02/09 23:54:03
Which header do you recommend? permission_broker_c
stevenjb
2016/02/10 00:01:01
Oh, I didn't notice this was the fake. In that cas
Reilly Grant (use Gerrit)
2016/02/10 00:16:32
Done.
| |
| 39 base::StringPrintf( | |
| 40 "Failed to open '%s': %s", path.c_str(), | |
| 41 logging::SystemErrorCodeToString(error_code).c_str()))); | |
|
stevenjb
2016/02/09 23:16:51
nit: return here, remove else
Reilly Grant (use Gerrit)
2016/02/10 00:16:32
Done.
| |
| 35 } else { | 42 } else { |
| 43 dbus::FileDescriptor dbus_fd; | |
| 36 dbus_fd.PutValue(fd); | 44 dbus_fd.PutValue(fd); |
| 37 dbus_fd.CheckValidity(); | 45 dbus_fd.CheckValidity(); |
| 46 task_runner->PostTask(FROM_HERE, | |
| 47 base::Bind(callback, base::Passed(&dbus_fd))); | |
| 38 } | 48 } |
| 39 task_runner->PostTask(FROM_HERE, | |
| 40 base::Bind(callback, base::Passed(&dbus_fd))); | |
| 41 } | 49 } |
| 42 | 50 |
| 43 } // namespace | 51 } // namespace |
| 44 | 52 |
| 45 FakePermissionBrokerClient::FakePermissionBrokerClient() {} | 53 FakePermissionBrokerClient::FakePermissionBrokerClient() {} |
| 46 | 54 |
| 47 FakePermissionBrokerClient::~FakePermissionBrokerClient() {} | 55 FakePermissionBrokerClient::~FakePermissionBrokerClient() {} |
| 48 | 56 |
| 49 void FakePermissionBrokerClient::Init(dbus::Bus* bus) {} | 57 void FakePermissionBrokerClient::Init(dbus::Bus* bus) {} |
| 50 | 58 |
| 51 void FakePermissionBrokerClient::CheckPathAccess( | 59 void FakePermissionBrokerClient::CheckPathAccess( |
| 52 const std::string& path, | 60 const std::string& path, |
| 53 const ResultCallback& callback) { | 61 const ResultCallback& callback) { |
| 54 callback.Run(true); | 62 callback.Run(true); |
| 55 } | 63 } |
| 56 | 64 |
| 57 void FakePermissionBrokerClient::OpenPath(const std::string& path, | 65 void FakePermissionBrokerClient::OpenPath(const std::string& path, |
| 58 const OpenPathCallback& callback) { | 66 const OpenPathCallback& callback, |
| 59 base::WorkerPool::PostTask(FROM_HERE, | 67 const ErrorCallback& error_callback) { |
| 60 base::Bind(&OpenPathAndValidate, path, callback, | 68 base::WorkerPool::PostTask( |
| 61 base::ThreadTaskRunnerHandle::Get()), | 69 FROM_HERE, |
| 62 false); | 70 base::Bind(&OpenPathAndValidate, path, callback, error_callback, |
| 71 base::ThreadTaskRunnerHandle::Get()), | |
| 72 false); | |
| 63 } | 73 } |
| 64 | 74 |
| 65 void FakePermissionBrokerClient::RequestTcpPortAccess( | 75 void FakePermissionBrokerClient::RequestTcpPortAccess( |
| 66 uint16_t port, | 76 uint16_t port, |
| 67 const std::string& interface, | 77 const std::string& interface, |
| 68 const dbus::FileDescriptor& lifeline_fd, | 78 const dbus::FileDescriptor& lifeline_fd, |
| 69 const ResultCallback& callback) { | 79 const ResultCallback& callback) { |
| 70 DCHECK(lifeline_fd.is_valid()); | 80 DCHECK(lifeline_fd.is_valid()); |
| 71 callback.Run(true); | 81 callback.Run(true); |
| 72 } | 82 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 88 } | 98 } |
| 89 | 99 |
| 90 void FakePermissionBrokerClient::ReleaseUdpPort( | 100 void FakePermissionBrokerClient::ReleaseUdpPort( |
| 91 uint16_t port, | 101 uint16_t port, |
| 92 const std::string& interface, | 102 const std::string& interface, |
| 93 const ResultCallback& callback) { | 103 const ResultCallback& callback) { |
| 94 callback.Run(true); | 104 callback.Run(true); |
| 95 } | 105 } |
| 96 | 106 |
| 97 } // namespace chromeos | 107 } // namespace chromeos |
| OLD | NEW |