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.
4
5#ifndef CHROMEOS_DBUS_PERMISSION_BROKER_CLIENT_H_
6#define CHROMEOS_DBUS_PERMISSION_BROKER_CLIENT_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/callback.h"
12#include "chromeos/chromeos_export.h"
13#include "chromeos/dbus/dbus_client.h"
14
15namespace chromeos {
16
17// PermissionBrokerClient is used to communicate with the permission broker, a
18// process that allows requesting permission to access specific device nodes.
19// For example, one place that this client is used is within the USB extension
20// API code, where it is used to request explicit access to USB peripherals
21// which the user the browser runs under normally wouldn't have access to. For
22// more details on the permission broker see:
23// http://git.chromium.org/gitweb/?p=chromiumos/platform/permission_broker.git
24class CHROMEOS_EXPORT PermissionBrokerClient : public DBusClient {
25 public:
26  // The ResultCallback is used for both the RequestPathAccess and
27  // RequestUsbAcess methods. Its boolean parameter represents the result of the
28  // operation that it was submitted alongside.
29  typedef base::Callback<void(bool)> ResultCallback;
30
31  virtual ~PermissionBrokerClient();
32
33  static PermissionBrokerClient* Create();
34
35  // RequestPathAccess requests access to a single device node identified by
36  // |path|. If |interface_id| value is passed (different than
37  // UsbDevicePermissionData::ANY_INTERFACE), the request will check if a
38  // specific interface is claimed while requesting access.
39  // This allows devices with multiple interfaces to be accessed even if
40  // some of them are already claimed by kernel.
41  virtual void RequestPathAccess(const std::string& path,
42                                 int interface_id,
43                                 const ResultCallback& callback) = 0;
44
45  // RequestUsbAccess attempts to request access to _all_ USB devices attached
46  // to the system that match |vendor_id| and |product_id|. If |interface_id| is
47  // passed (not -1), the request will check if a specific interface is claimed
48  // while requesting access. This allows devices with multiple interfaces to be
49  // accessed even if some of them are already claimed by kernel.
50  // This call makes no attempt to guarantee atomicity, and partial failure is
51  // indistinguishable from complete failure.
52  virtual void RequestUsbAccess(uint16_t vendor_id,
53                                uint16_t product_id,
54                                int interface_id,
55                                const ResultCallback& callback) = 0;
56
57 protected:
58  PermissionBrokerClient();
59
60 private:
61  DISALLOW_COPY_AND_ASSIGN(PermissionBrokerClient);
62};
63
64}  // namespace chromeos
65
66#endif  // CHROMEOS_DBUS_PERMISSION_BROKER_CLIENT_H_
67