Revert 217860 "Implement per-browser crash throttling for NaCl p..." which broke...
[chromium-blink-merge.git] / chromeos / dbus / bluetooth_profile_service_provider.h
blobee942cf4550d62cbe1a823a07a9f6668ae78a3fe
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 #ifndef CHROMEOS_DBUS_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_
6 #define CHROMEOS_DBUS_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chromeos/chromeos_export.h"
14 #include "dbus/bus.h"
15 #include "dbus/file_descriptor.h"
16 #include "dbus/object_path.h"
18 namespace chromeos {
20 // BluetoothProfileServiceProvider is used to provide a D-Bus object that the
21 // Bluetooth daemon can communicate with to connect application profiles.
23 // Instantiate with a chosen D-Bus object path and delegate object, and pass
24 // the D-Bus object path as the |agent_path| argument to the
25 // chromeos::BluetoothProfileManagerClient::RegisterProfile() method.
27 // When an incoming profile connection occurs, or after initiating a connection
28 // using the chromeos::BluetoothDeviceClient::ConnectProfile() method, the
29 // Bluetooth daemon will make calls to this profile object and they will be
30 // passed on to your Delegate object for handling. Responses should be returned
31 // using the callbacks supplied to those methods.
32 class CHROMEOS_EXPORT BluetoothProfileServiceProvider {
33 public:
34 // Interface for reacting to profile requests.
35 class Delegate {
36 public:
37 virtual ~Delegate() {}
39 // Possible status values that may be returned to callbacks on a new
40 // connection or a requested disconnection. Success indicates acceptance,
41 // reject indicates the user rejected or denied the request; cancelled
42 // means the user cancelled the request without confirming either way.
43 enum Status {
44 SUCCESS,
45 REJECTED,
46 CANCELLED
49 // Connection-specific options.
50 struct CHROMEOS_EXPORT Options {
51 Options() {}
52 ~Options() {}
54 // Profile version.
55 uint16 version;
57 // Profile features.
58 uint16 features;
61 // The ConfirmationCallback is used for methods which require confirmation;
62 // it should be called with one argument, the |status| of the request
63 // (success, rejected or cancelled).
64 typedef base::Callback<void(Status)> ConfirmationCallback;
66 // This method will be called when the profile is unregistered from the
67 // Bluetooth daemon, generally at shutdown or at the applications' request.
68 // It may be used to perform cleanup tasks.
69 virtual void Release() = 0;
71 // This method will be called when a profile connection to the device
72 // with object path |device_path| is established. |callback| must be called
73 // to confirm the connection, or indicate rejection or cancellation.
75 // A file descriptor for the connection socket is provided in |fd|, and
76 // details about the specific implementation of the profile in |options|.
78 // IMPORTANT: Ownership of the file descriptor object |fd| is passed to
79 // the delegate by this call. The delegate is responsible for checking the
80 // validity of |fd| on a thread where I/O is permitted before taking the
81 // value. If the value is not taken, the file descriptor is closed.
83 // Ownership of |options| is NOT passed so information out of it must be
84 // copied if required.
85 virtual void NewConnection(const dbus::ObjectPath& device_path,
86 scoped_ptr<dbus::FileDescriptor> fd,
87 const Options& options,
88 const ConfirmationCallback& callback) = 0;
90 // This method will be called when a profile connection to the device
91 // with object path |device_path| is disconnected. Any file descriptors
92 // owned by the service should be cleaned up and |callback| called to
93 // confirm, or indicate rejection or cancellation of the disconnection.
94 virtual void RequestDisconnection(const dbus::ObjectPath& device_path,
95 const ConfirmationCallback& callback) = 0;
97 // This method will be called by the Bluetooth daemon to indicate that
98 // a profile request failed before a reply was returned from the device.
99 virtual void Cancel() = 0;
102 virtual ~BluetoothProfileServiceProvider();
104 // Creates the instance where |bus| is the D-Bus bus connection to export
105 // the object onto, |object_path| is the object path that it should have
106 // and |delegate| is the object to which all method calls will be passed
107 // and responses generated from.
108 static BluetoothProfileServiceProvider* Create(
109 dbus::Bus* bus,
110 const dbus::ObjectPath& object_path,
111 Delegate* delegate);
113 protected:
114 BluetoothProfileServiceProvider();
116 private:
117 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileServiceProvider);
120 } // namespace chromeos
122 #endif // CHROMEOS_DBUS_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_