| Index: device/battery/battery_status_manager_win.cc
|
| diff --git a/content/browser/battery_status/battery_status_manager_win.cc b/device/battery/battery_status_manager_win.cc
|
| similarity index 76%
|
| rename from content/browser/battery_status/battery_status_manager_win.cc
|
| rename to device/battery/battery_status_manager_win.cc
|
| index d998d5aca0e2ab6405e323d659aa894cf179ef34..1bc69fd15d994e6ef330446c5c3a033efcac6867 100644
|
| --- a/content/browser/battery_status/battery_status_manager_win.cc
|
| +++ b/device/battery/battery_status_manager_win.cc
|
| @@ -2,16 +2,16 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/browser/battery_status/battery_status_manager_win.h"
|
| +#include "device/battery/battery_status_manager_win.h"
|
|
|
| +#include "base/bind.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/strings/string16.h"
|
| #include "base/win/message_window.h"
|
| #include "base/win/windows_version.h"
|
| -#include "content/browser/battery_status/battery_status_manager.h"
|
| -#include "content/public/browser/browser_thread.h"
|
| +#include "device/battery/battery_status_manager.h"
|
|
|
| -namespace content {
|
| +namespace device {
|
|
|
| namespace {
|
|
|
| @@ -32,26 +32,6 @@ class BatteryStatusObserver
|
| virtual ~BatteryStatusObserver() { DCHECK(!window_); }
|
|
|
| void Start() {
|
| - // Need to start on the UI thread to receive battery status notifications.
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI,
|
| - FROM_HERE,
|
| - base::Bind(&BatteryStatusObserver::StartOnUI, this));
|
| - }
|
| -
|
| - void Stop() {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI,
|
| - FROM_HERE,
|
| - base::Bind(&BatteryStatusObserver::StopOnUI, this));
|
| - }
|
| -
|
| - private:
|
| - void StartOnUI() {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - if (window_)
|
| - return;
|
| -
|
| if (CreateMessageWindow()) {
|
| BatteryChanged();
|
| // RegisterPowerSettingNotification function work from Windows Vista
|
| @@ -66,15 +46,11 @@ class BatteryStatusObserver
|
| } else {
|
| // Could not create a message window, execute callback with the default
|
| // values.
|
| - callback_.Run(blink::WebBatteryStatus());
|
| + callback_.Run(BatteryStatus());
|
| }
|
| }
|
|
|
| - void StopOnUI() {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - if (!window_)
|
| - return;
|
| -
|
| + void Stop() {
|
| if (power_handle_)
|
| UnregisterNotification(power_handle_);
|
| if (battery_change_handle_)
|
| @@ -82,12 +58,13 @@ class BatteryStatusObserver
|
| window_.reset();
|
| }
|
|
|
| + private:
|
| void BatteryChanged() {
|
| SYSTEM_POWER_STATUS win_status;
|
| if (GetSystemPowerStatus(&win_status))
|
| callback_.Run(ComputeWebBatteryStatus(win_status));
|
| else
|
| - callback_.Run(blink::WebBatteryStatus());
|
| + callback_.Run(BatteryStatus());
|
| }
|
|
|
| bool HandleMessage(UINT message,
|
| @@ -152,13 +129,11 @@ class BatteryStatusManagerWin : public BatteryStatusManager {
|
| public:
|
| // BatteryStatusManager:
|
| virtual bool StartListeningBatteryChange() OVERRIDE {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| battery_observer_->Start();
|
| return true;
|
| }
|
|
|
| virtual void StopListeningBatteryChange() OVERRIDE {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| battery_observer_->Stop();
|
| }
|
|
|
| @@ -170,9 +145,8 @@ class BatteryStatusManagerWin : public BatteryStatusManager {
|
|
|
| } // namespace
|
|
|
| -blink::WebBatteryStatus ComputeWebBatteryStatus(
|
| - const SYSTEM_POWER_STATUS& win_status) {
|
| - blink::WebBatteryStatus status;
|
| +BatteryStatus ComputeWebBatteryStatus(const SYSTEM_POWER_STATUS& win_status) {
|
| + BatteryStatus status;
|
| status.charging = win_status.ACLineStatus != WIN_AC_LINE_STATUS_OFFLINE;
|
|
|
| // Set level if available. Otherwise keep the default value which is 1.
|
| @@ -182,16 +156,16 @@ blink::WebBatteryStatus ComputeWebBatteryStatus(
|
| }
|
|
|
| if (!status.charging) {
|
| - // Set dischargingTime if available otherwise keep the default value,
|
| + // Set discharging_time if available otherwise keep the default value,
|
| // which is +Infinity.
|
| if (win_status.BatteryLifeTime != (DWORD)-1)
|
| - status.dischargingTime = win_status.BatteryLifeTime;
|
| - status.chargingTime = std::numeric_limits<double>::infinity();
|
| + status.discharging_time = win_status.BatteryLifeTime;
|
| + status.charging_time = std::numeric_limits<double>::infinity();
|
| } else {
|
| - // Set chargingTime to +Infinity if not fully charged, otherwise leave the
|
| + // Set charging_time to +Infinity if not fully charged, otherwise leave the
|
| // default value, which is 0.
|
| if (status.level < 1)
|
| - status.chargingTime = std::numeric_limits<double>::infinity();
|
| + status.charging_time = std::numeric_limits<double>::infinity();
|
| }
|
| return status;
|
| }
|
| @@ -203,4 +177,4 @@ scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create(
|
| new BatteryStatusManagerWin(callback));
|
| }
|
|
|
| -} // namespace content
|
| +} // namespace device
|
|
|