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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_DBUS_PERMISSION_BROKER_CLIENT_H_
6 #define CHROMEOS_DBUS_PERMISSION_BROKER_CLIENT_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_client.h"
21 // PermissionBrokerClient is used to communicate with the permission broker, a
22 // process that allows requesting permission to access specific device nodes.
23 // For example, one place that this client is used is within the USB extension
24 // API code, where it is used to request explicit access to USB peripherals
25 // which the user the browser runs under normally wouldn't have access to. For
26 // more details on the permission broker see:
27 // http://git.chromium.org/gitweb/?p=chromiumos/platform/permission_broker.git
28 class CHROMEOS_EXPORT PermissionBrokerClient
: public DBusClient
{
30 // The ResultCallback is used for both the RequestPathAccess and
31 // RequestUsbAccess methods. Its boolean parameter represents the result of
32 // the operation that it was submitted alongside.
33 typedef base::Callback
<void(bool)> ResultCallback
;
35 ~PermissionBrokerClient() override
;
37 static PermissionBrokerClient
* Create();
39 // CheckPathAccess requests a hint from the permission broker about whether
40 // a later call to RequestPathAccess will be successful. It presumes that
41 // the |interface_id| value passed to RequestPathAccess will be
42 // UsbDevicePermissionsData::ANY_INTERFACE).
43 virtual void CheckPathAccess(const std::string
& path
,
44 const ResultCallback
& callback
) = 0;
46 // RequestPathAccess requests access to a single device node identified by
47 // |path|. If |interface_id| value is passed (different than
48 // UsbDevicePermissionData::ANY_INTERFACE), the request will check if a
49 // specific interface is claimed while requesting access.
50 // This allows devices with multiple interfaces to be accessed even if
51 // some of them are already claimed by kernel.
52 virtual void RequestPathAccess(const std::string
& path
,
54 const ResultCallback
& callback
) = 0;
56 // Requests the |port| be opened on the firewall for incoming TCP/IP
57 // connections received on |interface| (an empty string indicates all
58 // interfaces). An open pipe must be passed as |lifeline_fd| so that the
59 // permission broker can monitor the lifetime of the calling process.
60 virtual void RequestTcpPortAccess(uint16 port
,
61 const std::string
& interface
,
62 const dbus::FileDescriptor
& lifeline_fd
,
63 const ResultCallback
& callback
) = 0;
65 // Requests the |port| be opened on the firewall for incoming UDP packets
66 // received on |interface| (an empty string indicates all interfaces). An open
67 // pipe must be passed as |lifeline_fd| so that the permission broker can
68 // monitor the lifetime of the calling process.
69 virtual void RequestUdpPortAccess(uint16 port
,
70 const std::string
& interface
,
71 const dbus::FileDescriptor
& lifeline_fd
,
72 const ResultCallback
& callback
) = 0;
74 // Releases a request for an open firewall port for TCP/IP connections. The
75 // |port| and |interface| parameters must be the same as a previous call to
76 // RequestTcpPortAccess.
77 virtual void ReleaseTcpPort(uint16 port
,
78 const std::string
& interface
,
79 const ResultCallback
& callback
) = 0;
81 // Releases a request for an open firewall port for UDP packets. The |port|
82 // and |interface| parameters must be the same as a previous call to
83 // RequestUdpPortAccess.
84 virtual void ReleaseUdpPort(uint16 port
,
85 const std::string
& interface
,
86 const ResultCallback
& callback
) = 0;
89 PermissionBrokerClient();
92 DISALLOW_COPY_AND_ASSIGN(PermissionBrokerClient
);
95 } // namespace chromeos
97 #endif // CHROMEOS_DBUS_PERMISSION_BROKER_CLIENT_H_