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" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_piece.h" |
14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/notifications/notification.h" | 19 #include "chrome/browser/notifications/notification.h" |
19 #include "chrome/browser/notifications/notification_ui_manager.h" | 20 #include "chrome/browser/notifications/notification_ui_manager.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
21 #include "chrome/grit/theme_resources.h" | 22 #include "chrome/grit/theme_resources.h" |
22 #include "chromeos/dbus/dbus_thread_manager.h" | 23 #include "chromeos/dbus/dbus_thread_manager.h" |
23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 58 } |
58 | 59 |
59 std::string ExtractBluetoothAddress(const std::string& path) { | 60 std::string ExtractBluetoothAddress(const std::string& path) { |
60 int header_size = strlen(kHIDBatteryPathPrefix); | 61 int header_size = strlen(kHIDBatteryPathPrefix); |
61 int end_size = strlen(kHIDBatteryPathSuffix); | 62 int end_size = strlen(kHIDBatteryPathSuffix); |
62 int key_len = path.size() - header_size - end_size; | 63 int key_len = path.size() - header_size - end_size; |
63 if (key_len <= 0) | 64 if (key_len <= 0) |
64 return std::string(); | 65 return std::string(); |
65 std::string reverse_address = | 66 std::string reverse_address = |
66 base::ToLowerASCII(path.substr(header_size, key_len)); | 67 base::ToLowerASCII(path.substr(header_size, key_len)); |
67 std::vector<std::string> result = base::SplitString( | 68 std::vector<base::StringPiece> result = base::SplitStringPiece( |
68 reverse_address, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 69 reverse_address, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
69 std::reverse(result.begin(), result.end()); | 70 std::reverse(result.begin(), result.end()); |
70 std::string address = base::JoinString(result, ":"); | 71 std::string address = base::JoinString(result, ":"); |
71 return address; | 72 return address; |
72 } | 73 } |
73 | 74 |
74 class PeripheralBatteryNotificationDelegate : public NotificationDelegate { | 75 class PeripheralBatteryNotificationDelegate : public NotificationDelegate { |
75 public: | 76 public: |
76 explicit PeripheralBatteryNotificationDelegate(const std::string& id) | 77 explicit PeripheralBatteryNotificationDelegate(const std::string& id) |
77 : id_(id) {} | 78 : id_(id) {} |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 230 |
230 void PeripheralBatteryObserver::CancelNotification(const std::string& address) { | 231 void PeripheralBatteryObserver::CancelNotification(const std::string& address) { |
231 // If last_used_profile_ is NULL then no notification has been posted yet. | 232 // If last_used_profile_ is NULL then no notification has been posted yet. |
232 if (notification_profile_) { | 233 if (notification_profile_) { |
233 g_browser_process->notification_ui_manager()->CancelById( | 234 g_browser_process->notification_ui_manager()->CancelById( |
234 address, NotificationUIManager::GetProfileID(notification_profile_)); | 235 address, NotificationUIManager::GetProfileID(notification_profile_)); |
235 } | 236 } |
236 } | 237 } |
237 | 238 |
238 } // namespace chromeos | 239 } // namespace chromeos |
OLD | NEW |