| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bluetooth/tray_bluetooth.h" | 5 #include "ash/system/bluetooth/tray_bluetooth.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/system/tray/fixed_sized_scroll_view.h" | 8 #include "ash/system/tray/fixed_sized_scroll_view.h" |
| 9 #include "ash/system/tray/hover_highlight_view.h" | 9 #include "ash/system/tray/hover_highlight_view.h" |
| 10 #include "ash/system/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 namespace ash { | 27 namespace ash { |
| 28 namespace internal { | 28 namespace internal { |
| 29 | 29 |
| 30 namespace tray { | 30 namespace tray { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Updates bluetooth device |device| in the |list|. If it is new, append to the | 34 // Updates bluetooth device |device| in the |list|. If it is new, append to the |
| 35 // end of the |list|; otherwise, keep it at the same place, but update the data | 35 // end of the |list|; otherwise, keep it at the same place, but update the data |
| 36 // with new device info provided by |device|. | 36 // with new device info provided by |device|. |
| 37 void UpdateBluetoothDeviceList(BluetoothDeviceList* list, | 37 void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list, |
| 38 const BluetoothDeviceInfo& device) { | 38 const BluetoothDeviceInfo& device) { |
| 39 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); | 39 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); |
| 40 ++it) { | 40 ++it) { |
| 41 if ((*it).address == device.address) { | 41 if ((*it).address == device.address) { |
| 42 *it = device; | 42 *it = device; |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 list->push_back(device); | 47 list->push_back(device); |
| 48 } | 48 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 class BluetoothDetailedView : public TrayDetailsView, | 99 class BluetoothDetailedView : public TrayDetailsView, |
| 100 public ViewClickListener, | 100 public ViewClickListener, |
| 101 public views::ButtonListener { | 101 public views::ButtonListener { |
| 102 public: | 102 public: |
| 103 BluetoothDetailedView(SystemTrayItem* owner, user::LoginStatus login) | 103 BluetoothDetailedView(SystemTrayItem* owner, user::LoginStatus login) |
| 104 : TrayDetailsView(owner), | 104 : TrayDetailsView(owner), |
| 105 login_(login), | 105 login_(login), |
| 106 manage_devices_(NULL), | 106 manage_devices_(NULL), |
| 107 toggle_bluetooth_(NULL), | 107 toggle_bluetooth_(NULL), |
| 108 enable_bluetooth_(NULL), | 108 enable_bluetooth_(NULL) { |
| 109 bluetooth_discovering_(false) { | |
| 110 CreateItems(); | 109 CreateItems(); |
| 111 Update(); | |
| 112 } | 110 } |
| 113 | 111 |
| 114 virtual ~BluetoothDetailedView() { | 112 virtual ~BluetoothDetailedView() { |
| 115 // Stop discovering bluetooth devices when exiting BT detailed view. | 113 // Stop discovering bluetooth devices when exiting BT detailed view. |
| 116 BluetoothStopDiscovering(); | 114 BluetoothStopDiscovering(); |
| 117 } | 115 } |
| 118 | 116 |
| 119 void Update() { | 117 void Update() { |
| 120 BluetoothStartDiscovering(); | 118 BluetoothStartDiscovering(); |
| 121 UpdateBlueToothDeviceList(); | 119 UpdateBluetoothDeviceList(); |
| 122 | 120 |
| 123 // Update UI. | 121 // Update UI. |
| 124 UpdateDeviceScrollList(); | 122 UpdateDeviceScrollList(); |
| 125 UpdateHeaderEntry(); | 123 UpdateHeaderEntry(); |
| 126 Layout(); | 124 Layout(); |
| 127 } | 125 } |
| 128 | 126 |
| 129 private: | 127 private: |
| 130 void CreateItems() { | 128 void CreateItems() { |
| 131 CreateScrollableList(); | 129 CreateScrollableList(); |
| 132 AppendSettingsEntries(); | 130 AppendSettingsEntries(); |
| 133 AppendHeaderEntry(); | 131 AppendHeaderEntry(); |
| 134 } | 132 } |
| 135 | 133 |
| 136 void BluetoothStartDiscovering() { | 134 void BluetoothStartDiscovering() { |
| 137 ash::SystemTrayDelegate* delegate = | 135 ash::SystemTrayDelegate* delegate = |
| 138 ash::Shell::GetInstance()->system_tray_delegate(); | 136 ash::Shell::GetInstance()->system_tray_delegate(); |
| 139 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | 137 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
| 140 if (!bluetooth_discovering_ && bluetooth_enabled) { | 138 bool bluetooth_discovering = delegate->GetBluetoothDiscovering(); |
| 141 bluetooth_discovering_ = true; | 139 if (bluetooth_discovering) { |
| 140 throbber_->Start(); |
| 141 return; |
| 142 } |
| 143 throbber_->Stop(); |
| 144 if (bluetooth_enabled) { |
| 142 delegate->BluetoothStartDiscovering(); | 145 delegate->BluetoothStartDiscovering(); |
| 143 throbber_->Start(); | |
| 144 } else if(!bluetooth_enabled) { | |
| 145 bluetooth_discovering_ = false; | |
| 146 throbber_->Stop(); | |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 | 148 |
| 150 void BluetoothStopDiscovering() { | 149 void BluetoothStopDiscovering() { |
| 151 ash::SystemTrayDelegate* delegate = | 150 ash::SystemTrayDelegate* delegate = |
| 152 ash::Shell::GetInstance()->system_tray_delegate(); | 151 ash::Shell::GetInstance()->system_tray_delegate(); |
| 153 if (delegate && bluetooth_discovering_) { | 152 if (delegate && delegate->GetBluetoothDiscovering()) { |
| 154 bluetooth_discovering_ = false; | |
| 155 delegate->BluetoothStopDiscovering(); | 153 delegate->BluetoothStopDiscovering(); |
| 156 throbber_->Stop(); | 154 throbber_->Stop(); |
| 157 } | 155 } |
| 158 } | 156 } |
| 159 | 157 |
| 160 void UpdateBlueToothDeviceList() { | 158 void UpdateBluetoothDeviceList() { |
| 161 std::set<std::string> new_connecting_devices; | 159 std::set<std::string> new_connecting_devices; |
| 162 std::set<std::string> new_connected_devices; | 160 std::set<std::string> new_connected_devices; |
| 163 std::set<std::string> new_paired_not_connected_devices; | 161 std::set<std::string> new_paired_not_connected_devices; |
| 164 std::set<std::string> new_discovered_not_paired_devices; | 162 std::set<std::string> new_discovered_not_paired_devices; |
| 165 | 163 |
| 166 BluetoothDeviceList list; | 164 BluetoothDeviceList list; |
| 167 Shell::GetInstance()->system_tray_delegate()-> | 165 Shell::GetInstance()->system_tray_delegate()-> |
| 168 GetAvailableBluetoothDevices(&list); | 166 GetAvailableBluetoothDevices(&list); |
| 169 for (size_t i = 0; i < list.size(); ++i) { | 167 for (size_t i = 0; i < list.size(); ++i) { |
| 170 if (list[i].connecting) { | 168 if (list[i].connecting) { |
| 171 list[i].display_name = l10n_util::GetStringFUTF16( | 169 list[i].display_name = l10n_util::GetStringFUTF16( |
| 172 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, list[i].display_name); | 170 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, list[i].display_name); |
| 173 new_connecting_devices.insert(list[i].address); | 171 new_connecting_devices.insert(list[i].address); |
| 174 UpdateBluetoothDeviceList(&connecting_devices_, list[i]); | 172 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]); |
| 175 } else if (list[i].connected && list[i].paired) { | 173 } else if (list[i].connected && list[i].paired) { |
| 176 new_connected_devices.insert(list[i].address); | 174 new_connected_devices.insert(list[i].address); |
| 177 UpdateBluetoothDeviceList(&connected_devices_, list[i]); | 175 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]); |
| 178 } else if (list[i].paired) { | 176 } else if (list[i].paired) { |
| 179 new_paired_not_connected_devices.insert(list[i].address); | 177 new_paired_not_connected_devices.insert(list[i].address); |
| 180 UpdateBluetoothDeviceList(&paired_not_connected_devices_, list[i]); | 178 UpdateBluetoothDeviceListHelper( |
| 179 &paired_not_connected_devices_, list[i]); |
| 181 } else { | 180 } else { |
| 182 new_discovered_not_paired_devices.insert(list[i].address); | 181 new_discovered_not_paired_devices.insert(list[i].address); |
| 183 UpdateBluetoothDeviceList(&discovered_not_paired_devices_, list[i]); | 182 UpdateBluetoothDeviceListHelper( |
| 183 &discovered_not_paired_devices_, list[i]); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, | 186 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, |
| 187 new_connecting_devices); | 187 new_connecting_devices); |
| 188 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, | 188 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, |
| 189 new_connected_devices); | 189 new_connected_devices); |
| 190 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, | 190 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, |
| 191 new_paired_not_connected_devices); | 191 new_paired_not_connected_devices); |
| 192 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, | 192 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, |
| 193 new_discovered_not_paired_devices); | 193 new_discovered_not_paired_devices); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 392 |
| 393 std::map<views::View*, std::string> device_map_; | 393 std::map<views::View*, std::string> device_map_; |
| 394 views::View* manage_devices_; | 394 views::View* manage_devices_; |
| 395 ThrobberView* throbber_; | 395 ThrobberView* throbber_; |
| 396 TrayPopupHeaderButton* toggle_bluetooth_; | 396 TrayPopupHeaderButton* toggle_bluetooth_; |
| 397 HoverHighlightView* enable_bluetooth_; | 397 HoverHighlightView* enable_bluetooth_; |
| 398 BluetoothDeviceList connected_devices_; | 398 BluetoothDeviceList connected_devices_; |
| 399 BluetoothDeviceList connecting_devices_; | 399 BluetoothDeviceList connecting_devices_; |
| 400 BluetoothDeviceList paired_not_connected_devices_; | 400 BluetoothDeviceList paired_not_connected_devices_; |
| 401 BluetoothDeviceList discovered_not_paired_devices_; | 401 BluetoothDeviceList discovered_not_paired_devices_; |
| 402 bool bluetooth_discovering_; | |
| 403 | 402 |
| 404 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); | 403 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); |
| 405 }; | 404 }; |
| 406 | 405 |
| 407 } // namespace tray | 406 } // namespace tray |
| 408 | 407 |
| 409 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) | 408 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) |
| 410 : SystemTrayItem(system_tray), | 409 : SystemTrayItem(system_tray), |
| 411 default_(NULL), | 410 default_(NULL), |
| 412 detailed_(NULL) { | 411 detailed_(NULL) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 428 return default_; | 427 return default_; |
| 429 } | 428 } |
| 430 | 429 |
| 431 views::View* TrayBluetooth::CreateDetailedView(user::LoginStatus status) { | 430 views::View* TrayBluetooth::CreateDetailedView(user::LoginStatus status) { |
| 432 if (!Shell::GetInstance()->system_tray_delegate()->GetBluetoothAvailable()) | 431 if (!Shell::GetInstance()->system_tray_delegate()->GetBluetoothAvailable()) |
| 433 return NULL; | 432 return NULL; |
| 434 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 433 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 435 ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW); | 434 ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW); |
| 436 CHECK(detailed_ == NULL); | 435 CHECK(detailed_ == NULL); |
| 437 detailed_ = new tray::BluetoothDetailedView(this, status); | 436 detailed_ = new tray::BluetoothDetailedView(this, status); |
| 437 detailed_->Update(); |
| 438 return detailed_; | 438 return detailed_; |
| 439 } | 439 } |
| 440 | 440 |
| 441 void TrayBluetooth::DestroyTrayView() { | 441 void TrayBluetooth::DestroyTrayView() { |
| 442 } | 442 } |
| 443 | 443 |
| 444 void TrayBluetooth::DestroyDefaultView() { | 444 void TrayBluetooth::DestroyDefaultView() { |
| 445 default_ = NULL; | 445 default_ = NULL; |
| 446 } | 446 } |
| 447 | 447 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 460 } | 460 } |
| 461 | 461 |
| 462 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | 462 void TrayBluetooth::OnBluetoothDiscoveringChanged() { |
| 463 if (!detailed_) | 463 if (!detailed_) |
| 464 return; | 464 return; |
| 465 detailed_->Update(); | 465 detailed_->Update(); |
| 466 } | 466 } |
| 467 | 467 |
| 468 } // namespace internal | 468 } // namespace internal |
| 469 } // namespace ash | 469 } // namespace ash |
| OLD | NEW |