| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/power_monitor/power_monitor.h" | 5 #include "base/power_monitor/power_monitor.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/power_monitor/power_monitor_source.h" | 9 #include "base/power_monitor/power_monitor_source.h" |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 } | 30 } |
| 31 | 31 |
| 32 void PowerMonitor::AddObserver(PowerObserver* obs) { | 32 void PowerMonitor::AddObserver(PowerObserver* obs) { |
| 33 observers_->AddObserver(obs); | 33 observers_->AddObserver(obs); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void PowerMonitor::RemoveObserver(PowerObserver* obs) { | 36 void PowerMonitor::RemoveObserver(PowerObserver* obs) { |
| 37 observers_->RemoveObserver(obs); | 37 observers_->RemoveObserver(obs); |
| 38 } | 38 } |
| 39 | 39 |
| 40 #if defined(OS_ANDROID) |
| 41 void PowerMonitor::DeferSuspendEvents(bool defer) { |
| 42 LOG(ERROR) << __func__ << " : " << defer << " : " << std::hex << this; |
| 43 base::AutoLock al(lock_); |
| 44 should_defer_suspend_ = defer; |
| 45 if (!should_defer_suspend_ && is_suspended_) |
| 46 observers_->Notify(FROM_HERE, &PowerObserver::OnSuspend); |
| 47 } |
| 48 #endif |
| 49 |
| 40 PowerMonitorSource* PowerMonitor::Source() { | 50 PowerMonitorSource* PowerMonitor::Source() { |
| 41 return source_.get(); | 51 return source_.get(); |
| 42 } | 52 } |
| 43 | 53 |
| 44 bool PowerMonitor::IsOnBatteryPower() { | 54 bool PowerMonitor::IsOnBatteryPower() { |
| 45 return source_->IsOnBatteryPower(); | 55 return source_->IsOnBatteryPower(); |
| 46 } | 56 } |
| 47 | 57 |
| 48 void PowerMonitor::NotifyPowerStateChange(bool battery_in_use) { | 58 void PowerMonitor::NotifyPowerStateChange(bool battery_in_use) { |
| 49 DVLOG(1) << "PowerStateChange: " << (battery_in_use ? "On" : "Off") | 59 DVLOG(1) << "PowerStateChange: " << (battery_in_use ? "On" : "Off") |
| 50 << " battery"; | 60 << " battery"; |
| 51 observers_->Notify(FROM_HERE, &PowerObserver::OnPowerStateChange, | 61 observers_->Notify(FROM_HERE, &PowerObserver::OnPowerStateChange, |
| 52 battery_in_use); | 62 battery_in_use); |
| 53 } | 63 } |
| 54 | 64 |
| 55 void PowerMonitor::NotifySuspend() { | 65 void PowerMonitor::NotifySuspend() { |
| 56 DVLOG(1) << "Power Suspending"; | 66 LOG(ERROR) << __func__ << " : " << std::hex << this; |
| 67 #if defined(OS_ANDROID) |
| 68 { |
| 69 base::AutoLock al(lock_); |
| 70 if (should_defer_suspend_) { |
| 71 is_suspended_ = true; |
| 72 return; |
| 73 } |
| 74 } |
| 75 #endif |
| 76 |
| 77 LOG(ERROR) << "Power Suspending : " << should_defer_suspend_; |
| 57 observers_->Notify(FROM_HERE, &PowerObserver::OnSuspend); | 78 observers_->Notify(FROM_HERE, &PowerObserver::OnSuspend); |
| 58 } | 79 } |
| 59 | 80 |
| 60 void PowerMonitor::NotifyResume() { | 81 void PowerMonitor::NotifyResume() { |
| 82 #if defined(OS_ANDROID) |
| 83 { |
| 84 base::AutoLock al(lock_); |
| 85 is_suspended_ = false; |
| 86 } |
| 87 #endif |
| 88 |
| 61 DVLOG(1) << "Power Resuming"; | 89 DVLOG(1) << "Power Resuming"; |
| 62 observers_->Notify(FROM_HERE, &PowerObserver::OnResume); | 90 observers_->Notify(FROM_HERE, &PowerObserver::OnResume); |
| 63 } | 91 } |
| 64 | 92 |
| 65 } // namespace base | 93 } // namespace base |
| OLD | NEW |