Home | History | Annotate | Download | only in dbus
      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_implementation_type.h"
     14 
     15 namespace dbus {
     16 class Bus;
     17 }  // namespace dbus
     18 
     19 namespace chromeos {
     20 
     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 {
     29  public:
     30   // The ResultCallback is used for both the RequestPathAccess and
     31   // RequestUsbAcess methods. Its boolean parameter represents the result of the
     32   // operation that it was submitted alongside.
     33   typedef base::Callback<void(bool)> ResultCallback;
     34 
     35   virtual ~PermissionBrokerClient();
     36 
     37   static PermissionBrokerClient* Create(DBusClientImplementationType type,
     38                                         dbus::Bus* bus);
     39 
     40   // RequestPathAccess requests access to a single device node identified by
     41   // |path|. If |interface_id| value is passed (different than
     42   // UsbDevicePermissionData::ANY_INTERFACE), the request will check if a
     43   // specific interface is claimed while requesting access.
     44   // This allows devices with multiple interfaces to be accessed even if
     45   // some of them are already claimed by kernel.
     46   virtual void RequestPathAccess(const std::string& path,
     47                                  int interface_id,
     48                                  const ResultCallback& callback) = 0;
     49 
     50   // RequestUsbAccess attempts to request access to _all_ USB devices attached
     51   // to the system that match |vendor_id| and |product_id|. If |interface_id| is
     52   // passed (not -1), the request will check if a specific interface is claimed
     53   // while requesting access. This allows devices with multiple interfaces to be
     54   // accessed even if some of them are already claimed by kernel.
     55   // This call makes no attempt to guarantee atomicity, and partial failure is
     56   // indistinguishable from complete failure.
     57   virtual void RequestUsbAccess(uint16_t vendor_id,
     58                                 uint16_t product_id,
     59                                 int interface_id,
     60                                 const ResultCallback& callback) = 0;
     61 
     62  protected:
     63   PermissionBrokerClient();
     64 
     65  private:
     66   DISALLOW_COPY_AND_ASSIGN(PermissionBrokerClient);
     67 };
     68 
     69 }  // namespace chromeos
     70 
     71 #endif  // CHROMEOS_DBUS_PERMISSION_BROKER_CLIENT_H_
     72