| 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 "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 EndsWith(path, kHIDBatteryPathSuffix, false); | 52 EndsWith(path, kHIDBatteryPathSuffix, false); |
| 53 } | 53 } |
| 54 | 54 |
| 55 std::string ExtractBluetoothAddress(const std::string& path) { | 55 std::string ExtractBluetoothAddress(const std::string& path) { |
| 56 int header_size = strlen(kHIDBatteryPathPrefix); | 56 int header_size = strlen(kHIDBatteryPathPrefix); |
| 57 int end_size = strlen(kHIDBatteryPathSuffix); | 57 int end_size = strlen(kHIDBatteryPathSuffix); |
| 58 int key_len = path.size() - header_size - end_size; | 58 int key_len = path.size() - header_size - end_size; |
| 59 if (key_len <= 0) | 59 if (key_len <= 0) |
| 60 return std::string(); | 60 return std::string(); |
| 61 std::string reverse_address = path.substr(header_size, key_len); | 61 std::string reverse_address = path.substr(header_size, key_len); |
| 62 StringToLowerASCII(&reverse_address); | 62 base::StringToLowerASCII(&reverse_address); |
| 63 std::vector<std::string> result; | 63 std::vector<std::string> result; |
| 64 base::SplitString(reverse_address, ':', &result); | 64 base::SplitString(reverse_address, ':', &result); |
| 65 std::reverse(result.begin(), result.end()); | 65 std::reverse(result.begin(), result.end()); |
| 66 std::string address = JoinString(result, ':'); | 66 std::string address = JoinString(result, ':'); |
| 67 return address; | 67 return address; |
| 68 } | 68 } |
| 69 | 69 |
| 70 class PeripheralBatteryNotificationDelegate : public NotificationDelegate { | 70 class PeripheralBatteryNotificationDelegate : public NotificationDelegate { |
| 71 public: | 71 public: |
| 72 explicit PeripheralBatteryNotificationDelegate(const std::string& id) | 72 explicit PeripheralBatteryNotificationDelegate(const std::string& id) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 void PeripheralBatteryObserver::InitializeOnBluetoothReady( | 180 void PeripheralBatteryObserver::InitializeOnBluetoothReady( |
| 181 scoped_refptr<device::BluetoothAdapter> adapter) { | 181 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 182 bluetooth_adapter_ = adapter; | 182 bluetooth_adapter_ = adapter; |
| 183 CHECK(bluetooth_adapter_.get()); | 183 CHECK(bluetooth_adapter_.get()); |
| 184 bluetooth_adapter_->AddObserver(this); | 184 bluetooth_adapter_->AddObserver(this); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void PeripheralBatteryObserver::RemoveBattery(const std::string& address) { | 187 void PeripheralBatteryObserver::RemoveBattery(const std::string& address) { |
| 188 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 188 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 189 std::string address_lowercase = address; | 189 std::string address_lowercase = address; |
| 190 StringToLowerASCII(&address_lowercase); | 190 base::StringToLowerASCII(&address_lowercase); |
| 191 std::map<std::string, BatteryInfo>::iterator it = | 191 std::map<std::string, BatteryInfo>::iterator it = |
| 192 batteries_.find(address_lowercase); | 192 batteries_.find(address_lowercase); |
| 193 if (it != batteries_.end()) { | 193 if (it != batteries_.end()) { |
| 194 batteries_.erase(it); | 194 batteries_.erase(it); |
| 195 CancelNotification(address_lowercase); | 195 CancelNotification(address_lowercase); |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool PeripheralBatteryObserver::PostNotification(const std::string& address, | 199 bool PeripheralBatteryObserver::PostNotification(const std::string& address, |
| 200 const BatteryInfo& battery) { | 200 const BatteryInfo& battery) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 231 ProfileManager::GetPrimaryUserProfile()); | 231 ProfileManager::GetPrimaryUserProfile()); |
| 232 | 232 |
| 233 return true; | 233 return true; |
| 234 } | 234 } |
| 235 | 235 |
| 236 void PeripheralBatteryObserver::CancelNotification(const std::string& address) { | 236 void PeripheralBatteryObserver::CancelNotification(const std::string& address) { |
| 237 g_browser_process->notification_ui_manager()->CancelById(address); | 237 g_browser_process->notification_ui_manager()->CancelById(address); |
| 238 } | 238 } |
| 239 | 239 |
| 240 } // namespace chromeos | 240 } // namespace chromeos |
| OLD | NEW |