| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/battery_status/battery_status_manager_linux.h" | 5 #include "content/browser/battery_status/battery_status_manager_linux.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "content/browser/battery_status/battery_status_manager.h" | 10 #include "content/browser/battery_status/battery_status_manager.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 base::Bind(&BatteryStatusNotificationThread::ShutdownDBusConnection, | 116 base::Bind(&BatteryStatusNotificationThread::ShutdownDBusConnection, |
| 117 base::Unretained(this))); | 117 base::Unretained(this))); |
| 118 | 118 |
| 119 // Drain the message queue of the BatteryStatusNotificationThread and stop. | 119 // Drain the message queue of the BatteryStatusNotificationThread and stop. |
| 120 Stop(); | 120 Stop(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void StartListening() { | 123 void StartListening() { |
| 124 DCHECK(OnWatcherThread()); | 124 DCHECK(OnWatcherThread()); |
| 125 | 125 |
| 126 if (system_bus_) | 126 if (system_bus_.get()) |
| 127 return; | 127 return; |
| 128 | 128 |
| 129 InitDBus(); | 129 InitDBus(); |
| 130 dbus::ObjectProxy* power_proxy = | 130 dbus::ObjectProxy* power_proxy = |
| 131 system_bus_->GetObjectProxy(kUPowerServiceName, | 131 system_bus_->GetObjectProxy(kUPowerServiceName, |
| 132 dbus::ObjectPath(kUPowerPath)); | 132 dbus::ObjectPath(kUPowerPath)); |
| 133 scoped_ptr<PathsVector> device_paths = GetPowerSourcesPaths(power_proxy); | 133 scoped_ptr<PathsVector> device_paths = GetPowerSourcesPaths(power_proxy); |
| 134 | 134 |
| 135 for (size_t i = 0; i < device_paths->size(); ++i) { | 135 for (size_t i = 0; i < device_paths->size(); ++i) { |
| 136 const dbus::ObjectPath& device_path = device_paths->at(i); | 136 const dbus::ObjectPath& device_path = device_paths->at(i); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 194 |
| 195 dbus::Bus::Options options; | 195 dbus::Bus::Options options; |
| 196 options.bus_type = dbus::Bus::SYSTEM; | 196 options.bus_type = dbus::Bus::SYSTEM; |
| 197 options.connection_type = dbus::Bus::PRIVATE; | 197 options.connection_type = dbus::Bus::PRIVATE; |
| 198 system_bus_ = new dbus::Bus(options); | 198 system_bus_ = new dbus::Bus(options); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void ShutdownDBusConnection() { | 201 void ShutdownDBusConnection() { |
| 202 DCHECK(OnWatcherThread()); | 202 DCHECK(OnWatcherThread()); |
| 203 | 203 |
| 204 if (!system_bus_) | 204 if (!system_bus_.get()) |
| 205 return; | 205 return; |
| 206 | 206 |
| 207 // Shutdown DBus connection later because there may be pending tasks on | 207 // Shutdown DBus connection later because there may be pending tasks on |
| 208 // this thread. | 208 // this thread. |
| 209 message_loop()->PostTask(FROM_HERE, | 209 message_loop()->PostTask(FROM_HERE, |
| 210 base::Bind(&dbus::Bus::ShutdownAndBlock, | 210 base::Bind(&dbus::Bus::ShutdownAndBlock, |
| 211 system_bus_)); | 211 system_bus_)); |
| 212 system_bus_ = NULL; | 212 system_bus_ = NULL; |
| 213 battery_proxy_ = NULL; | 213 battery_proxy_ = NULL; |
| 214 } | 214 } |
| 215 | 215 |
| 216 void OnSignalConnected(const std::string& interface_name, | 216 void OnSignalConnected(const std::string& interface_name, |
| 217 const std::string& signal_name, | 217 const std::string& signal_name, |
| 218 bool success) { | 218 bool success) { |
| 219 DCHECK(OnWatcherThread()); | 219 DCHECK(OnWatcherThread()); |
| 220 | 220 |
| 221 if (interface_name != kUPowerDeviceName || | 221 if (interface_name != kUPowerDeviceName || |
| 222 signal_name != kUPowerDeviceSignalChanged) { | 222 signal_name != kUPowerDeviceSignalChanged) { |
| 223 return; | 223 return; |
| 224 } | 224 } |
| 225 | 225 |
| 226 if (!system_bus_) | 226 if (!system_bus_.get()) |
| 227 return; | 227 return; |
| 228 | 228 |
| 229 if (success) { | 229 if (success) { |
| 230 BatteryChanged(NULL); | 230 BatteryChanged(NULL); |
| 231 } else { | 231 } else { |
| 232 // Failed to register for "Changed" signal, execute callback with the | 232 // Failed to register for "Changed" signal, execute callback with the |
| 233 // default values. | 233 // default values. |
| 234 callback_.Run(blink::WebBatteryStatus()); | 234 callback_.Run(blink::WebBatteryStatus()); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 void BatteryChanged(dbus::Signal* signal /* unsused */) { | 238 void BatteryChanged(dbus::Signal* signal /* unsused */) { |
| 239 DCHECK(OnWatcherThread()); | 239 DCHECK(OnWatcherThread()); |
| 240 | 240 |
| 241 if (!system_bus_) | 241 if (!system_bus_.get()) |
| 242 return; | 242 return; |
| 243 | 243 |
| 244 scoped_ptr<base::DictionaryValue> dictionary = | 244 scoped_ptr<base::DictionaryValue> dictionary = |
| 245 GetPropertiesAsDictionary(battery_proxy_); | 245 GetPropertiesAsDictionary(battery_proxy_); |
| 246 if (dictionary) | 246 if (dictionary) |
| 247 callback_.Run(ComputeWebBatteryStatus(*dictionary)); | 247 callback_.Run(ComputeWebBatteryStatus(*dictionary)); |
| 248 else | 248 else |
| 249 callback_.Run(blink::WebBatteryStatus()); | 249 callback_.Run(blink::WebBatteryStatus()); |
| 250 } | 250 } |
| 251 | 251 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 } | 365 } |
| 366 | 366 |
| 367 // static | 367 // static |
| 368 scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create( | 368 scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create( |
| 369 const BatteryStatusService::BatteryUpdateCallback& callback) { | 369 const BatteryStatusService::BatteryUpdateCallback& callback) { |
| 370 return scoped_ptr<BatteryStatusManager>( | 370 return scoped_ptr<BatteryStatusManager>( |
| 371 new BatteryStatusManagerLinux(callback)); | 371 new BatteryStatusManagerLinux(callback)); |
| 372 } | 372 } |
| 373 | 373 |
| 374 } // namespace content | 374 } // namespace content |
| OLD | NEW |