| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/chromeos/bluetooth/bluetooth_notification_controller.h" | 5 #include "ash/system/chromeos/bluetooth/bluetooth_notification_controller.h" |
| 6 | 6 |
| 7 #include "ash/system/system_notifier.h" | 7 #include "ash/system/system_notifier.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 class BluetoothPairingNotificationDelegate | 51 class BluetoothPairingNotificationDelegate |
| 52 : public message_center::NotificationDelegate { | 52 : public message_center::NotificationDelegate { |
| 53 public: | 53 public: |
| 54 BluetoothPairingNotificationDelegate(scoped_refptr<BluetoothAdapter> adapter, | 54 BluetoothPairingNotificationDelegate(scoped_refptr<BluetoothAdapter> adapter, |
| 55 const std::string& address); | 55 const std::string& address); |
| 56 | 56 |
| 57 protected: | 57 protected: |
| 58 virtual ~BluetoothPairingNotificationDelegate(); | 58 virtual ~BluetoothPairingNotificationDelegate(); |
| 59 | 59 |
| 60 // message_center::NotificationDelegate overrides. | 60 // message_center::NotificationDelegate overrides. |
| 61 virtual void Display() override; | 61 void Close(bool by_user) override; |
| 62 virtual void Error() override; | 62 void ButtonClick(int button_index) override; |
| 63 virtual void Close(bool by_user) override; | |
| 64 virtual bool HasClickedListener() override; | |
| 65 virtual void Click() override; | |
| 66 virtual void ButtonClick(int button_index) override; | |
| 67 | 63 |
| 68 private: | 64 private: |
| 69 // Buttons that appear in notifications. | 65 // Buttons that appear in notifications. |
| 70 enum Button { | 66 enum Button { |
| 71 BUTTON_ACCEPT, | 67 BUTTON_ACCEPT, |
| 72 BUTTON_REJECT | 68 BUTTON_REJECT |
| 73 }; | 69 }; |
| 74 | 70 |
| 75 // Reference to the underlying Bluetooth Adapter, holding onto this | 71 // Reference to the underlying Bluetooth Adapter, holding onto this |
| 76 // reference ensures the adapter object doesn't go out of scope while we have | 72 // reference ensures the adapter object doesn't go out of scope while we have |
| 77 // a pending request and user interaction. | 73 // a pending request and user interaction. |
| 78 scoped_refptr<BluetoothAdapter> adapter_; | 74 scoped_refptr<BluetoothAdapter> adapter_; |
| 79 | 75 |
| 80 // Address of the device being paired. | 76 // Address of the device being paired. |
| 81 const std::string address_; | 77 const std::string address_; |
| 82 | 78 |
| 83 DISALLOW_COPY_AND_ASSIGN(BluetoothPairingNotificationDelegate); | 79 DISALLOW_COPY_AND_ASSIGN(BluetoothPairingNotificationDelegate); |
| 84 }; | 80 }; |
| 85 | 81 |
| 86 BluetoothPairingNotificationDelegate::BluetoothPairingNotificationDelegate( | 82 BluetoothPairingNotificationDelegate::BluetoothPairingNotificationDelegate( |
| 87 scoped_refptr<BluetoothAdapter> adapter, | 83 scoped_refptr<BluetoothAdapter> adapter, |
| 88 const std::string& address) | 84 const std::string& address) |
| 89 : adapter_(adapter), | 85 : adapter_(adapter), |
| 90 address_(address) { | 86 address_(address) { |
| 91 } | 87 } |
| 92 | 88 |
| 93 BluetoothPairingNotificationDelegate::~BluetoothPairingNotificationDelegate() { | 89 BluetoothPairingNotificationDelegate::~BluetoothPairingNotificationDelegate() { |
| 94 } | 90 } |
| 95 | 91 |
| 96 void BluetoothPairingNotificationDelegate::Display() { | |
| 97 } | |
| 98 | |
| 99 void BluetoothPairingNotificationDelegate::Error() { | |
| 100 } | |
| 101 | |
| 102 void BluetoothPairingNotificationDelegate::Close(bool by_user) { | 92 void BluetoothPairingNotificationDelegate::Close(bool by_user) { |
| 103 VLOG(1) << "Pairing notification closed. by_user = " << by_user; | 93 VLOG(1) << "Pairing notification closed. by_user = " << by_user; |
| 104 // Ignore notification closes generated as a result of pairing completion. | 94 // Ignore notification closes generated as a result of pairing completion. |
| 105 if (!by_user) | 95 if (!by_user) |
| 106 return; | 96 return; |
| 107 | 97 |
| 108 // Cancel the pairing of the device, if the object still exists. | 98 // Cancel the pairing of the device, if the object still exists. |
| 109 BluetoothDevice* device = adapter_->GetDevice(address_); | 99 BluetoothDevice* device = adapter_->GetDevice(address_); |
| 110 if (device) | 100 if (device) |
| 111 device->CancelPairing(); | 101 device->CancelPairing(); |
| 112 } | 102 } |
| 113 | 103 |
| 114 bool BluetoothPairingNotificationDelegate::HasClickedListener() { | |
| 115 return false; | |
| 116 } | |
| 117 | |
| 118 void BluetoothPairingNotificationDelegate::Click() { | |
| 119 } | |
| 120 | |
| 121 void BluetoothPairingNotificationDelegate::ButtonClick(int button_index) { | 104 void BluetoothPairingNotificationDelegate::ButtonClick(int button_index) { |
| 122 VLOG(1) << "Pairing notification, button click: " << button_index; | 105 VLOG(1) << "Pairing notification, button click: " << button_index; |
| 123 // If the device object still exists, send the appropriate response either | 106 // If the device object still exists, send the appropriate response either |
| 124 // confirming or rejecting the pairing. | 107 // confirming or rejecting the pairing. |
| 125 BluetoothDevice* device = adapter_->GetDevice(address_); | 108 BluetoothDevice* device = adapter_->GetDevice(address_); |
| 126 if (device) { | 109 if (device) { |
| 127 switch (button_index) { | 110 switch (button_index) { |
| 128 case BUTTON_ACCEPT: | 111 case BUTTON_ACCEPT: |
| 129 device->ConfirmPairing(); | 112 device->ConfirmPairing(); |
| 130 break; | 113 break; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 base::string16() /* display source */, | 344 base::string16() /* display source */, |
| 362 message_center::NotifierId( | 345 message_center::NotifierId( |
| 363 message_center::NotifierId::SYSTEM_COMPONENT, | 346 message_center::NotifierId::SYSTEM_COMPONENT, |
| 364 system_notifier::kNotifierBluetooth), | 347 system_notifier::kNotifierBluetooth), |
| 365 optional, | 348 optional, |
| 366 NULL)); | 349 NULL)); |
| 367 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); | 350 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); |
| 368 } | 351 } |
| 369 | 352 |
| 370 } // namespace ash | 353 } // namespace ash |
| OLD | NEW |