| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/chromeos/power/peripheral_battery_observer.h" | 5 #include "chrome/browser/chromeos/power/peripheral_battery_observer.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/strings/grit/ash_strings.h" | 10 #include "ash/strings/grit/ash_strings.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 PeripheralBatteryObserver::~PeripheralBatteryObserver() { | 100 PeripheralBatteryObserver::~PeripheralBatteryObserver() { |
| 101 if (bluetooth_adapter_.get()) | 101 if (bluetooth_adapter_.get()) |
| 102 bluetooth_adapter_->RemoveObserver(this); | 102 bluetooth_adapter_->RemoveObserver(this); |
| 103 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 103 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void PeripheralBatteryObserver::PeripheralBatteryStatusReceived( | 106 void PeripheralBatteryObserver::PeripheralBatteryStatusReceived( |
| 107 const std::string& path, | 107 const std::string& path, |
| 108 const std::string& name, | 108 const std::string& name, |
| 109 int level) { | 109 int level) { |
| 110 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 111 std::string address; | 111 std::string address; |
| 112 if (IsBluetoothHIDBattery(path)) { | 112 if (IsBluetoothHIDBattery(path)) { |
| 113 // For HID bluetooth device, device address is used as key to index | 113 // For HID bluetooth device, device address is used as key to index |
| 114 // BatteryInfo. | 114 // BatteryInfo. |
| 115 address = ExtractBluetoothAddress(path); | 115 address = ExtractBluetoothAddress(path); |
| 116 } else { | 116 } else { |
| 117 LOG(ERROR) << "Unsupported battery path " << path; | 117 LOG(ERROR) << "Unsupported battery path " << path; |
| 118 return; | 118 return; |
| 119 } | 119 } |
| 120 | 120 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 171 } |
| 172 | 172 |
| 173 void PeripheralBatteryObserver::InitializeOnBluetoothReady( | 173 void PeripheralBatteryObserver::InitializeOnBluetoothReady( |
| 174 scoped_refptr<device::BluetoothAdapter> adapter) { | 174 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 175 bluetooth_adapter_ = adapter; | 175 bluetooth_adapter_ = adapter; |
| 176 CHECK(bluetooth_adapter_.get()); | 176 CHECK(bluetooth_adapter_.get()); |
| 177 bluetooth_adapter_->AddObserver(this); | 177 bluetooth_adapter_->AddObserver(this); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void PeripheralBatteryObserver::RemoveBattery(const std::string& address) { | 180 void PeripheralBatteryObserver::RemoveBattery(const std::string& address) { |
| 181 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 181 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 182 std::string address_lowercase = address; | 182 std::string address_lowercase = address; |
| 183 base::StringToLowerASCII(&address_lowercase); | 183 base::StringToLowerASCII(&address_lowercase); |
| 184 std::map<std::string, BatteryInfo>::iterator it = | 184 std::map<std::string, BatteryInfo>::iterator it = |
| 185 batteries_.find(address_lowercase); | 185 batteries_.find(address_lowercase); |
| 186 if (it != batteries_.end()) { | 186 if (it != batteries_.end()) { |
| 187 batteries_.erase(it); | 187 batteries_.erase(it); |
| 188 CancelNotification(address_lowercase); | 188 CancelNotification(address_lowercase); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 226 |
| 227 void PeripheralBatteryObserver::CancelNotification(const std::string& address) { | 227 void PeripheralBatteryObserver::CancelNotification(const std::string& address) { |
| 228 // If last_used_profile_ is NULL then no notification has been posted yet. | 228 // If last_used_profile_ is NULL then no notification has been posted yet. |
| 229 if (notification_profile_) { | 229 if (notification_profile_) { |
| 230 g_browser_process->notification_ui_manager()->CancelById( | 230 g_browser_process->notification_ui_manager()->CancelById( |
| 231 address, NotificationUIManager::GetProfileID(notification_profile_)); | 231 address, NotificationUIManager::GetProfileID(notification_profile_)); |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 } // namespace chromeos | 235 } // namespace chromeos |
| OLD | NEW |