Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: chromeos/dbus/fake_permission_broker_client.cc

Issue 1681383002: Add path open errors from the permission broker to the device log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_request_access
Patch Set: Addresses stevenjb@'s comments. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
24 const char kOpenFailedError[] = "open_failed";
25
23 // So that real devices can be accessed by tests and "Chromium OS on Linux" this 26 // 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 27 // function implements a simplified version of the method implemented by the
25 // permission broker by opening the path specified and returning the resulting 28 // permission broker by opening the path specified and returning the resulting
26 // file descriptor. 29 // file descriptor.
27 void OpenPathAndValidate( 30 void OpenPathAndValidate(
28 const std::string& path, 31 const std::string& path,
29 const PermissionBrokerClient::OpenPathCallback& callback, 32 const PermissionBrokerClient::OpenPathCallback& callback,
33 const PermissionBrokerClient::ErrorCallback& error_callback,
30 scoped_refptr<base::TaskRunner> task_runner) { 34 scoped_refptr<base::TaskRunner> task_runner) {
31 dbus::FileDescriptor dbus_fd;
32 int fd = HANDLE_EINTR(open(path.c_str(), O_RDWR)); 35 int fd = HANDLE_EINTR(open(path.c_str(), O_RDWR));
33 if (fd < 0) { 36 if (fd < 0) {
34 PLOG(WARNING) << "Failed to open '" << path << "'"; 37 int error_code = logging::GetLastSystemErrorCode();
35 } else { 38 task_runner->PostTask(
36 dbus_fd.PutValue(fd); 39 FROM_HERE,
37 dbus_fd.CheckValidity(); 40 base::Bind(error_callback, kOpenFailedError,
41 base::StringPrintf(
42 "Failed to open '%s': %s", path.c_str(),
43 logging::SystemErrorCodeToString(error_code).c_str())));
44 return;
38 } 45 }
46
47 dbus::FileDescriptor dbus_fd;
48 dbus_fd.PutValue(fd);
49 dbus_fd.CheckValidity();
39 task_runner->PostTask(FROM_HERE, 50 task_runner->PostTask(FROM_HERE,
40 base::Bind(callback, base::Passed(&dbus_fd))); 51 base::Bind(callback, base::Passed(&dbus_fd)));
41 } 52 }
42 53
43 } // namespace 54 } // namespace
44 55
45 FakePermissionBrokerClient::FakePermissionBrokerClient() {} 56 FakePermissionBrokerClient::FakePermissionBrokerClient() {}
46 57
47 FakePermissionBrokerClient::~FakePermissionBrokerClient() {} 58 FakePermissionBrokerClient::~FakePermissionBrokerClient() {}
48 59
49 void FakePermissionBrokerClient::Init(dbus::Bus* bus) {} 60 void FakePermissionBrokerClient::Init(dbus::Bus* bus) {}
50 61
51 void FakePermissionBrokerClient::CheckPathAccess( 62 void FakePermissionBrokerClient::CheckPathAccess(
52 const std::string& path, 63 const std::string& path,
53 const ResultCallback& callback) { 64 const ResultCallback& callback) {
54 callback.Run(true); 65 callback.Run(true);
55 } 66 }
56 67
57 void FakePermissionBrokerClient::OpenPath(const std::string& path, 68 void FakePermissionBrokerClient::OpenPath(const std::string& path,
58 const OpenPathCallback& callback) { 69 const OpenPathCallback& callback,
59 base::WorkerPool::PostTask(FROM_HERE, 70 const ErrorCallback& error_callback) {
60 base::Bind(&OpenPathAndValidate, path, callback, 71 base::WorkerPool::PostTask(
61 base::ThreadTaskRunnerHandle::Get()), 72 FROM_HERE,
62 false); 73 base::Bind(&OpenPathAndValidate, path, callback, error_callback,
74 base::ThreadTaskRunnerHandle::Get()),
75 false);
63 } 76 }
64 77
65 void FakePermissionBrokerClient::RequestTcpPortAccess( 78 void FakePermissionBrokerClient::RequestTcpPortAccess(
66 uint16_t port, 79 uint16_t port,
67 const std::string& interface, 80 const std::string& interface,
68 const dbus::FileDescriptor& lifeline_fd, 81 const dbus::FileDescriptor& lifeline_fd,
69 const ResultCallback& callback) { 82 const ResultCallback& callback) {
70 DCHECK(lifeline_fd.is_valid()); 83 DCHECK(lifeline_fd.is_valid());
71 callback.Run(true); 84 callback.Run(true);
72 } 85 }
(...skipping 15 matching lines...) Expand all
88 } 101 }
89 102
90 void FakePermissionBrokerClient::ReleaseUdpPort( 103 void FakePermissionBrokerClient::ReleaseUdpPort(
91 uint16_t port, 104 uint16_t port,
92 const std::string& interface, 105 const std::string& interface,
93 const ResultCallback& callback) { 106 const ResultCallback& callback) {
94 callback.Run(true); 107 callback.Run(true);
95 } 108 }
96 109
97 } // namespace chromeos 110 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_permission_broker_client.h ('k') | chromeos/dbus/mock_permission_broker_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698