Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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. | |
| 4 | |
| 5 #ifndef ASH_SYSTEM_CHROMEOS_BLUETOOTH_BLUETOOTH_NOTIFICATION_CONTROLLER_H_ | |
| 6 #define ASH_SYSTEM_CHROMEOS_BLUETOOTH_BLUETOOTH_NOTIFICATION_CONTROLLER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 | |
| 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" | |
| 18 | |
| 19 namespace ash { | |
| 20 namespace internal { | |
| 21 | |
| 22 // The BluetoothNotificationController receives incoming pairing requests from | |
| 23 // the BluetoothAdapter, and notifications of changes to the adapter state and | |
| 24 // set of paired devices. It presents incoming pairing requests in the form of | |
| 25 // rich notifications that the user can interact with to approve the request. | |
| 26 class ASH_EXPORT BluetoothNotificationController | |
| 27 : public device::BluetoothAdapter::Observer, | |
| 28 public device::BluetoothDevice::PairingDelegate { | |
| 29 public: | |
| 30 BluetoothNotificationController(); | |
| 31 virtual ~BluetoothNotificationController(); | |
| 32 | |
| 33 // device::BluetoothAdapter::Observer override. | |
| 34 virtual void DeviceAdded(device::BluetoothAdapter* adapter, | |
| 35 device::BluetoothDevice* device) OVERRIDE; | |
| 36 virtual void DeviceChanged(device::BluetoothAdapter* adapter, | |
| 37 device::BluetoothDevice* device) OVERRIDE; | |
| 38 virtual void DeviceRemoved(device::BluetoothAdapter* adapter, | |
| 39 device::BluetoothDevice* device) OVERRIDE; | |
| 40 | |
| 41 // device::BluetoothDevice::PairingDelegate override. | |
| 42 virtual void RequestPinCode(device::BluetoothDevice* device) OVERRIDE; | |
| 43 virtual void RequestPasskey(device::BluetoothDevice* device) OVERRIDE; | |
| 44 virtual void DisplayPinCode(device::BluetoothDevice* device, | |
| 45 const std::string& pincode) OVERRIDE; | |
| 46 virtual void DisplayPasskey(device::BluetoothDevice* device, | |
| 47 uint32 passkey) OVERRIDE; | |
| 48 virtual void KeysEntered(device::BluetoothDevice* device, | |
| 49 uint32 entered) OVERRIDE; | |
| 50 virtual void ConfirmPasskey(device::BluetoothDevice* device, | |
| 51 uint32 passkey) OVERRIDE; | |
| 52 virtual void AuthorizePairing(device::BluetoothDevice* device) OVERRIDE; | |
| 53 | |
| 54 private: | |
| 55 // Internal method called by BluetoothAdapterFactory to provide the adapter | |
| 56 // object. | |
| 57 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | |
| 58 | |
| 59 // Presents a notification to the user that a device |device| is making a | |
| 60 // pairing request. The exact message to display is given in |message| and | |
| 61 // should include all relevant instructions, if |with_buttons| is true then | |
| 62 // the notification will have Accept and Reject buttons, if false only the | |
| 63 // usual cancel/dismiss button will be present on the notification. | |
| 64 void NotifyPairing(device::BluetoothDevice* device, | |
| 65 const base::string16& message, | |
| 66 bool with_buttons); | |
| 67 | |
| 68 // Clears any shown pairing notification now that the device has been paired. | |
| 69 void NotifyPairedDevice(device::BluetoothDevice* device); | |
| 70 | |
| 71 // Reference to the underlying BluetoothAdapter object, holding this reference | |
| 72 // ensures we stay around as the pairing delegate for that adapter. | |
| 73 scoped_refptr<device::BluetoothAdapter> adapter_; | |
| 74 | |
| 75 // Set of currently paired devices, stored by Bluetooth address, used to | |
| 76 // filter out property changes for devices that were previously paired. | |
| 77 std::set<std::string> paired_devices_; | |
| 78 | |
| 79 // Note: This should remain the last member so it'll be destroyed and | |
|
sky
2014/03/03 22:56:22
nit: IMO comments like this are easy to miss. Bett
keybuk
2014/03/03 23:40:39
The problem this comment is referring to isn't a r
| |
| 80 // invalidate its weak pointers before any other members are destroyed. | |
| 81 base::WeakPtrFactory<BluetoothNotificationController> weak_ptr_factory_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(BluetoothNotificationController); | |
| 84 }; | |
| 85 | |
| 86 } // namespace internal | |
| 87 } // namespace ash | |
| 88 | |
| 89 #endif // ASH_SYSTEM_CHROMEOS_BLUETOOTH_BLUETOOTH_NOTIFICATION_CONTROLLER_H_ | |
| OLD | NEW |