| 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 "content/child/power_monitor_broadcast_source.h" | 5 #include "device/power_monitor/public/cpp/power_monitor_broadcast_source.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "content/child/child_thread_impl.h" | |
| 10 #include "mojo/public/cpp/bindings/binding.h" | 9 #include "mojo/public/cpp/bindings/binding.h" |
| 11 #include "services/service_manager/public/cpp/interface_provider.h" | |
| 12 | 10 |
| 13 namespace content { | 11 namespace device { |
| 14 | 12 |
| 15 PowerMonitorBroadcastSource::PowerMonitorBroadcastSource() | 13 PowerMonitorBroadcastSource::PowerMonitorBroadcastSource( |
| 14 device::mojom::PowerMonitor* power_monitor) |
| 16 : last_reported_battery_power_state_(false), binding_(this) { | 15 : last_reported_battery_power_state_(false), binding_(this) { |
| 17 // May be null during test execution. | 16 if (power_monitor) { |
| 18 if (ChildThreadImpl::current()) { | |
| 19 device::mojom::PowerMonitorPtr power_monitor; | |
| 20 ChildThreadImpl::current()->GetRemoteInterfaces()->GetInterface( | |
| 21 mojo::GetProxy(&power_monitor)); | |
| 22 power_monitor->SetClient(binding_.CreateInterfacePtrAndBind()); | 17 power_monitor->SetClient(binding_.CreateInterfacePtrAndBind()); |
| 23 } | 18 } |
| 24 } | 19 } |
| 25 | 20 |
| 26 PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() { | 21 PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() {} |
| 27 } | |
| 28 | 22 |
| 29 bool PowerMonitorBroadcastSource::IsOnBatteryPowerImpl() { | 23 bool PowerMonitorBroadcastSource::IsOnBatteryPowerImpl() { |
| 30 return last_reported_battery_power_state_; | 24 return last_reported_battery_power_state_; |
| 31 } | 25 } |
| 32 | 26 |
| 33 void PowerMonitorBroadcastSource::PowerStateChange(bool on_battery_power) { | 27 void PowerMonitorBroadcastSource::PowerStateChange(bool on_battery_power) { |
| 34 last_reported_battery_power_state_ = on_battery_power; | 28 last_reported_battery_power_state_ = on_battery_power; |
| 35 ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT); | 29 ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT); |
| 36 } | 30 } |
| 37 | 31 |
| 38 void PowerMonitorBroadcastSource::Suspend() { | 32 void PowerMonitorBroadcastSource::Suspend() { |
| 39 ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT); | 33 ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT); |
| 40 } | 34 } |
| 41 | 35 |
| 42 void PowerMonitorBroadcastSource::Resume() { | 36 void PowerMonitorBroadcastSource::Resume() { |
| 43 ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT); | 37 ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT); |
| 44 } | 38 } |
| 45 | 39 |
| 46 } // namespace content | 40 } // namespace device |
| OLD | NEW |