Move VariationsRegistrySyncerWin to ChromeVariationsServiceClient
[chromium-blink-merge.git] / chromeos / dbus / fake_permission_broker_client.cc
blob85ac1b8a30de2712783982c518c3fb98baa7a412
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"
7 #include <fcntl.h>
9 #include "base/bind.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"
18 namespace chromeos {
20 namespace {
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
25 // file descriptor.
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));
31 if (fd < 0) {
32 PLOG(ERROR) << "Failed to open '" << path << "'";
33 } else {
34 dbus::FileDescriptor dbus_fd;
35 dbus_fd.PutValue(fd);
36 dbus_fd.CheckValidity();
37 task_runner->PostTask(FROM_HERE,
38 base::Bind(callback, base::Passed(&dbus_fd)));
42 } // namespace
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) {
53 callback.Run(true);
56 void FakePermissionBrokerClient::RequestPathAccess(
57 const std::string& path,
58 int interface_id,
59 const ResultCallback& callback) {
60 callback.Run(true);
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()),
68 false);
71 void FakePermissionBrokerClient::RequestTcpPortAccess(
72 uint16 port,
73 const std::string& interface,
74 const dbus::FileDescriptor& lifeline_fd,
75 const ResultCallback& callback) {
76 DCHECK(lifeline_fd.is_valid());
77 callback.Run(true);
80 void FakePermissionBrokerClient::RequestUdpPortAccess(
81 uint16 port,
82 const std::string& interface,
83 const dbus::FileDescriptor& lifeline_fd,
84 const ResultCallback& callback) {
85 DCHECK(lifeline_fd.is_valid());
86 callback.Run(true);
89 void FakePermissionBrokerClient::ReleaseTcpPort(
90 uint16 port,
91 const std::string& interface,
92 const ResultCallback& callback) {
93 callback.Run(true);
96 void FakePermissionBrokerClient::ReleaseUdpPort(
97 uint16 port,
98 const std::string& interface,
99 const ResultCallback& callback) {
100 callback.Run(true);
103 } // namespace chromeos