Don't preload rarely seen large images
[chromium-blink-merge.git] / chromeos / dbus / bluetooth_profile_service_provider.h
blobde77b5ddeef985b78689aaa900b4d103eeff2a3a
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. This corresponds to the
69 // org.bluez.Profile1.Release method and is renamed to avoid a conflict
70 // with base::Refcounted<T>.
71 virtual void Released() = 0;
73 // This method will be called when a profile connection to the device
74 // with object path |device_path| is established. |callback| must be called
75 // to confirm the connection, or indicate rejection or cancellation.
77 // A file descriptor for the connection socket is provided in |fd|, and
78 // details about the specific implementation of the profile in |options|.
80 // IMPORTANT: Ownership of the file descriptor object |fd| is passed to
81 // the delegate by this call. The delegate is responsible for checking the
82 // validity of |fd| on a thread where I/O is permitted before taking the
83 // value. If the value is not taken, the file descriptor is closed.
85 // Ownership of |options| is NOT passed so information out of it must be
86 // copied if required.
87 virtual void NewConnection(const dbus::ObjectPath& device_path,
88 scoped_ptr<dbus::FileDescriptor> fd,
89 const Options& options,
90 const ConfirmationCallback& callback) = 0;
92 // This method will be called when a profile connection to the device
93 // with object path |device_path| is disconnected. Any file descriptors
94 // owned by the service should be cleaned up and |callback| called to
95 // confirm, or indicate rejection or cancellation of the disconnection.
96 virtual void RequestDisconnection(const dbus::ObjectPath& device_path,
97 const ConfirmationCallback& callback) = 0;
99 // This method will be called by the Bluetooth daemon to indicate that
100 // a profile request failed before a reply was returned from the device.
101 virtual void Cancel() = 0;
104 virtual ~BluetoothProfileServiceProvider();
106 // Creates the instance where |bus| is the D-Bus bus connection to export
107 // the object onto, |object_path| is the object path that it should have
108 // and |delegate| is the object to which all method calls will be passed
109 // and responses generated from.
110 static BluetoothProfileServiceProvider* Create(
111 dbus::Bus* bus,
112 const dbus::ObjectPath& object_path,
113 Delegate* delegate);
115 protected:
116 BluetoothProfileServiceProvider();
118 private:
119 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileServiceProvider);
122 } // namespace chromeos
124 #endif // CHROMEOS_DBUS_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_