Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ash / system / chromeos / bluetooth / bluetooth_notification_controller.h
blob22b990d3f39c3cbd17a5c2db308918c39466faad
1 // Copyright 2014 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 ASH_SYSTEM_CHROMEOS_BLUETOOTH_BLUETOOTH_NOTIFICATION_CONTROLLER_H_
6 #define ASH_SYSTEM_CHROMEOS_BLUETOOTH_BLUETOOTH_NOTIFICATION_CONTROLLER_H_
8 #include <set>
10 #include "ash/ash_export.h"
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h"
16 #include "device/bluetooth/bluetooth_adapter.h"
17 #include "device/bluetooth/bluetooth_device.h"
19 namespace ash {
21 // The BluetoothNotificationController receives incoming pairing requests from
22 // the BluetoothAdapter, and notifications of changes to the adapter state and
23 // set of paired devices. It presents incoming pairing requests in the form of
24 // rich notifications that the user can interact with to approve the request.
25 class ASH_EXPORT BluetoothNotificationController
26 : public device::BluetoothAdapter::Observer,
27 public device::BluetoothDevice::PairingDelegate {
28 public:
29 BluetoothNotificationController();
30 ~BluetoothNotificationController() override;
32 // device::BluetoothAdapter::Observer override.
33 void AdapterDiscoverableChanged(device::BluetoothAdapter* adapter,
34 bool discoverable) override;
35 void DeviceAdded(device::BluetoothAdapter* adapter,
36 device::BluetoothDevice* device) override;
37 void DeviceChanged(device::BluetoothAdapter* adapter,
38 device::BluetoothDevice* device) override;
39 void DeviceRemoved(device::BluetoothAdapter* adapter,
40 device::BluetoothDevice* device) override;
42 // device::BluetoothDevice::PairingDelegate override.
43 void RequestPinCode(device::BluetoothDevice* device) override;
44 void RequestPasskey(device::BluetoothDevice* device) override;
45 void DisplayPinCode(device::BluetoothDevice* device,
46 const std::string& pincode) override;
47 void DisplayPasskey(device::BluetoothDevice* device, uint32 passkey) override;
48 void KeysEntered(device::BluetoothDevice* device, uint32 entered) override;
49 void ConfirmPasskey(device::BluetoothDevice* device, uint32 passkey) override;
50 void AuthorizePairing(device::BluetoothDevice* device) override;
52 private:
53 // Internal method called by BluetoothAdapterFactory to provide the adapter
54 // object.
55 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
57 // Presents a notification to the user when the adapter becomes discoverable
58 // to other nearby devices.
59 void NotifyAdapterDiscoverable();
61 // Presents a notification to the user that a device |device| is making a
62 // pairing request. The exact message to display is given in |message| and
63 // should include all relevant instructions, if |with_buttons| is true then
64 // the notification will have Accept and Reject buttons, if false only the
65 // usual cancel/dismiss button will be present on the notification.
66 void NotifyPairing(device::BluetoothDevice* device,
67 const base::string16& message,
68 bool with_buttons);
70 // Clears any shown pairing notification now that the device has been paired.
71 void NotifyPairedDevice(device::BluetoothDevice* device);
73 // Reference to the underlying BluetoothAdapter object, holding this reference
74 // ensures we stay around as the pairing delegate for that adapter.
75 scoped_refptr<device::BluetoothAdapter> adapter_;
77 // Set of currently paired devices, stored by Bluetooth address, used to
78 // filter out property changes for devices that were previously paired.
79 std::set<std::string> paired_devices_;
81 // Note: This should remain the last member so it'll be destroyed and
82 // invalidate its weak pointers before any other members are destroyed.
83 base::WeakPtrFactory<BluetoothNotificationController> weak_ptr_factory_;
85 DISALLOW_COPY_AND_ASSIGN(BluetoothNotificationController);
88 } // namespace ash
90 #endif // ASH_SYSTEM_CHROMEOS_BLUETOOTH_BLUETOOTH_NOTIFICATION_CONTROLLER_H_