| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" | 5 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } // namespace | 243 } // namespace |
| 244 | 244 |
| 245 SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() | 245 SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() |
| 246 : weak_ptr_factory_(this), | 246 : weak_ptr_factory_(this), |
| 247 user_profile_(NULL), | 247 user_profile_(NULL), |
| 248 clock_type_(base::GetHourClockType()), | 248 clock_type_(base::GetHourClockType()), |
| 249 search_key_mapped_to_(input_method::kSearchKey), | 249 search_key_mapped_to_(input_method::kSearchKey), |
| 250 screen_locked_(false), | 250 screen_locked_(false), |
| 251 have_session_start_time_(false), | 251 have_session_start_time_(false), |
| 252 have_session_length_limit_(false), | 252 have_session_length_limit_(false), |
| 253 bluetooth_should_discover_(false), |
| 253 volume_control_delegate_(new VolumeController()), | 254 volume_control_delegate_(new VolumeController()), |
| 254 device_settings_observer_(CrosSettings::Get()->AddSettingsObserver( | 255 device_settings_observer_(CrosSettings::Get()->AddSettingsObserver( |
| 255 kSystemUse24HourClock, | 256 kSystemUse24HourClock, |
| 256 base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType, | 257 base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType, |
| 257 base::Unretained(this)))) { | 258 base::Unretained(this)))) { |
| 258 // Register notifications on construction so that events such as | 259 // Register notifications on construction so that events such as |
| 259 // PROFILE_CREATED do not get missed if they happen before Initialize(). | 260 // PROFILE_CREATED do not get missed if they happen before Initialize(). |
| 260 registrar_.reset(new content::NotificationRegistrar); | 261 registrar_.reset(new content::NotificationRegistrar); |
| 261 registrar_->Add(this, | 262 registrar_->Add(this, |
| 262 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 263 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 info.address = device->GetAddress(); | 696 info.address = device->GetAddress(); |
| 696 info.display_name = device->GetName(); | 697 info.display_name = device->GetName(); |
| 697 info.connected = device->IsConnected(); | 698 info.connected = device->IsConnected(); |
| 698 info.connecting = device->IsConnecting(); | 699 info.connecting = device->IsConnecting(); |
| 699 info.paired = device->IsPaired(); | 700 info.paired = device->IsPaired(); |
| 700 list->push_back(info); | 701 list->push_back(info); |
| 701 } | 702 } |
| 702 } | 703 } |
| 703 | 704 |
| 704 void SystemTrayDelegateChromeOS::BluetoothStartDiscovering() { | 705 void SystemTrayDelegateChromeOS::BluetoothStartDiscovering() { |
| 705 bluetooth_adapter_->StartDiscovering( | 706 if (bluetooth_discovery_session_.get() && |
| 707 bluetooth_discovery_session_->IsActive()) { |
| 708 LOG(WARNING) << "Already have active Bluetooth device discovery session."; |
| 709 return; |
| 710 } |
| 711 VLOG(1) << "Requesting new Bluetooth device discovery session."; |
| 712 bluetooth_should_discover_ = true; |
| 713 bluetooth_adapter_->StartDiscoverySession( |
| 714 base::Bind(&SystemTrayDelegateChromeOS::OnStartDiscoverySession, |
| 715 weak_ptr_factory_.GetWeakPtr()), |
| 716 base::Bind(&BluetoothSetDiscoveringError)); |
| 717 } |
| 718 |
| 719 void SystemTrayDelegateChromeOS::BluetoothStopDiscovering() { |
| 720 bluetooth_should_discover_ = false; |
| 721 if (!bluetooth_discovery_session_.get() || |
| 722 !bluetooth_discovery_session_->IsActive()) { |
| 723 LOG(WARNING) << "No active Bluetooth device discovery session."; |
| 724 return; |
| 725 } |
| 726 VLOG(1) << "Stopping Bluetooth device discovery session."; |
| 727 bluetooth_discovery_session_->Stop( |
| 706 base::Bind(&base::DoNothing), base::Bind(&BluetoothSetDiscoveringError)); | 728 base::Bind(&base::DoNothing), base::Bind(&BluetoothSetDiscoveringError)); |
| 707 } | 729 } |
| 708 | 730 |
| 709 void SystemTrayDelegateChromeOS::BluetoothStopDiscovering() { | |
| 710 bluetooth_adapter_->StopDiscovering( | |
| 711 base::Bind(&base::DoNothing), base::Bind(&BluetoothSetDiscoveringError)); | |
| 712 } | |
| 713 | |
| 714 void SystemTrayDelegateChromeOS::ConnectToBluetoothDevice( | 731 void SystemTrayDelegateChromeOS::ConnectToBluetoothDevice( |
| 715 const std::string& address) { | 732 const std::string& address) { |
| 716 device::BluetoothDevice* device = bluetooth_adapter_->GetDevice(address); | 733 device::BluetoothDevice* device = bluetooth_adapter_->GetDevice(address); |
| 717 if (!device || device->IsConnecting() || | 734 if (!device || device->IsConnecting() || |
| 718 (device->IsConnected() && device->IsPaired())) { | 735 (device->IsConnected() && device->IsPaired())) { |
| 719 return; | 736 return; |
| 720 } | 737 } |
| 721 if (device->IsPaired() && !device->IsConnectable()) | 738 if (device->IsPaired() && !device->IsConnectable()) |
| 722 return; | 739 return; |
| 723 if (device->IsPaired() || !device->IsPairable()) { | 740 if (device->IsPaired() || !device->IsPairable()) { |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 device::BluetoothDevice* device) { | 1289 device::BluetoothDevice* device) { |
| 1273 GetSystemTrayNotifier()->NotifyRefreshBluetooth(); | 1290 GetSystemTrayNotifier()->NotifyRefreshBluetooth(); |
| 1274 } | 1291 } |
| 1275 | 1292 |
| 1276 void SystemTrayDelegateChromeOS::DeviceRemoved( | 1293 void SystemTrayDelegateChromeOS::DeviceRemoved( |
| 1277 device::BluetoothAdapter* adapter, | 1294 device::BluetoothAdapter* adapter, |
| 1278 device::BluetoothDevice* device) { | 1295 device::BluetoothDevice* device) { |
| 1279 GetSystemTrayNotifier()->NotifyRefreshBluetooth(); | 1296 GetSystemTrayNotifier()->NotifyRefreshBluetooth(); |
| 1280 } | 1297 } |
| 1281 | 1298 |
| 1299 void SystemTrayDelegateChromeOS::OnStartDiscoverySession( |
| 1300 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| 1301 // If the discovery session was returned after a request to stop discovery |
| 1302 // (e.g. the user dismissed the Bluetooth detailed view before the call |
| 1303 // returned), don't claim the discovery session and let it clean up. |
| 1304 if (!bluetooth_should_discover_) |
| 1305 return; |
| 1306 VLOG(1) << "Claiming new Bluetooth device discovery session."; |
| 1307 bluetooth_discovery_session_ = discovery_session.Pass(); |
| 1308 } |
| 1309 |
| 1282 // Overridden from SystemKeyEventListener::CapsLockObserver. | 1310 // Overridden from SystemKeyEventListener::CapsLockObserver. |
| 1283 void SystemTrayDelegateChromeOS::OnCapsLockChange(bool enabled) { | 1311 void SystemTrayDelegateChromeOS::OnCapsLockChange(bool enabled) { |
| 1284 bool search_mapped_to_caps_lock = false; | 1312 bool search_mapped_to_caps_lock = false; |
| 1285 if (!base::SysInfo::IsRunningOnChromeOS() || | 1313 if (!base::SysInfo::IsRunningOnChromeOS() || |
| 1286 search_key_mapped_to_ == input_method::kCapsLockKey) | 1314 search_key_mapped_to_ == input_method::kCapsLockKey) |
| 1287 search_mapped_to_caps_lock = true; | 1315 search_mapped_to_caps_lock = true; |
| 1288 GetSystemTrayNotifier()->NotifyCapsLockChanged(enabled, | 1316 GetSystemTrayNotifier()->NotifyCapsLockChanged(enabled, |
| 1289 search_mapped_to_caps_lock); | 1317 search_mapped_to_caps_lock); |
| 1290 } | 1318 } |
| 1291 | 1319 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1321 accessibility_subscription_.reset(); | 1349 accessibility_subscription_.reset(); |
| 1322 else | 1350 else |
| 1323 OnAccessibilityModeChanged(details.notify); | 1351 OnAccessibilityModeChanged(details.notify); |
| 1324 } | 1352 } |
| 1325 | 1353 |
| 1326 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { | 1354 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { |
| 1327 return new SystemTrayDelegateChromeOS(); | 1355 return new SystemTrayDelegateChromeOS(); |
| 1328 } | 1356 } |
| 1329 | 1357 |
| 1330 } // namespace chromeos | 1358 } // namespace chromeos |
| OLD | NEW |