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
3 // found in the LICENSE file.
5 #include "chromeos/dbus/fake_permission_broker_client.h"
10 #include "base/callback.h"
11 #include "base/location.h"
12 #include "base/logging.h"
13 #include "base/posix/eintr_wrapper.h"
14 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/worker_pool.h"
16 #include "dbus/file_descriptor.h"
22 // So that real devices can be accessed by tests and "Chromium OS on Linux" this
23 // function implements a simplified version of the method implemented by the
24 // permission broker by opening the path specified and returning the resulting
26 void OpenPathAndValidate(
27 const std::string
& path
,
28 const PermissionBrokerClient::OpenPathCallback
& callback
,
29 scoped_refptr
<base::TaskRunner
> task_runner
) {
30 int fd
= HANDLE_EINTR(open(path
.c_str(), O_RDWR
));
32 PLOG(ERROR
) << "Failed to open '" << path
<< "'";
34 dbus::FileDescriptor dbus_fd
;
36 dbus_fd
.CheckValidity();
37 task_runner
->PostTask(FROM_HERE
,
38 base::Bind(callback
, base::Passed(&dbus_fd
)));
44 FakePermissionBrokerClient::FakePermissionBrokerClient() {}
46 FakePermissionBrokerClient::~FakePermissionBrokerClient() {}
48 void FakePermissionBrokerClient::Init(dbus::Bus
* bus
) {}
50 void FakePermissionBrokerClient::CheckPathAccess(
51 const std::string
& path
,
52 const ResultCallback
& callback
) {
56 void FakePermissionBrokerClient::RequestPathAccess(
57 const std::string
& path
,
59 const ResultCallback
& callback
) {
63 void FakePermissionBrokerClient::OpenPath(const std::string
& path
,
64 const OpenPathCallback
& callback
) {
65 base::WorkerPool::PostTask(FROM_HERE
,
66 base::Bind(&OpenPathAndValidate
, path
, callback
,
67 base::ThreadTaskRunnerHandle::Get()),
71 void FakePermissionBrokerClient::RequestTcpPortAccess(
73 const std::string
& interface
,
74 const dbus::FileDescriptor
& lifeline_fd
,
75 const ResultCallback
& callback
) {
76 DCHECK(lifeline_fd
.is_valid());
80 void FakePermissionBrokerClient::RequestUdpPortAccess(
82 const std::string
& interface
,
83 const dbus::FileDescriptor
& lifeline_fd
,
84 const ResultCallback
& callback
) {
85 DCHECK(lifeline_fd
.is_valid());
89 void FakePermissionBrokerClient::ReleaseTcpPort(
91 const std::string
& interface
,
92 const ResultCallback
& callback
) {
96 void FakePermissionBrokerClient::ReleaseUdpPort(
98 const std::string
& interface
,
99 const ResultCallback
& callback
) {
103 } // namespace chromeos