| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/arc/power/arc_power_bridge.h" | 5 #include "components/arc/power/arc_power_bridge.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "chromeos/dbus/power_policy_controller.h" | 12 #include "chromeos/dbus/power_policy_controller.h" |
| 13 #include "components/arc/arc_service_manager.h" | 13 #include "components/arc/arc_service_manager.h" |
| 14 | 14 |
| 15 namespace arc { | 15 namespace arc { |
| 16 | 16 |
| 17 ArcPowerBridge::ArcPowerBridge(ArcBridgeService* bridge_service) | 17 ArcPowerBridge::ArcPowerBridge(ArcBridgeService* bridge_service) |
| 18 : ArcService(bridge_service), binding_(this) { | 18 : ArcService(bridge_service), binding_(this) { |
| 19 arc_bridge_service()->AddObserver(this); | 19 arc_bridge_service()->power()->AddObserver(this); |
| 20 } | 20 } |
| 21 | 21 |
| 22 ArcPowerBridge::~ArcPowerBridge() { | 22 ArcPowerBridge::~ArcPowerBridge() { |
| 23 arc_bridge_service()->RemoveObserver(this); | 23 arc_bridge_service()->power()->RemoveObserver(this); |
| 24 ReleaseAllDisplayWakeLocks(); | 24 ReleaseAllDisplayWakeLocks(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void ArcPowerBridge::OnPowerInstanceReady() { | 27 void ArcPowerBridge::OnInstanceReady(mojom::PowerInstance* power_instance, |
| 28 mojom::PowerInstance* power_instance = arc_bridge_service()->power_instance(); | 28 uint32_t version) { |
| 29 if (!power_instance) { | |
| 30 LOG(ERROR) << "OnPowerInstanceReady called, but no power instance found"; | |
| 31 return; | |
| 32 } | |
| 33 | |
| 34 power_instance->Init(binding_.CreateInterfacePtrAndBind()); | 29 power_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 35 ash::Shell::GetInstance()->display_configurator()->AddObserver(this); | 30 ash::Shell::GetInstance()->display_configurator()->AddObserver(this); |
| 36 } | 31 } |
| 37 | 32 |
| 38 void ArcPowerBridge::OnPowerInstanceClosed() { | 33 void ArcPowerBridge::OnInstanceClosed(mojom::PowerInstance*) { |
| 39 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 34 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
| 40 ReleaseAllDisplayWakeLocks(); | 35 ReleaseAllDisplayWakeLocks(); |
| 41 } | 36 } |
| 42 | 37 |
| 43 void ArcPowerBridge::OnPowerStateChanged( | 38 void ArcPowerBridge::OnPowerStateChanged( |
| 44 chromeos::DisplayPowerState power_state) { | 39 chromeos::DisplayPowerState power_state) { |
| 45 mojom::PowerInstance* power_instance = arc_bridge_service()->power_instance(); | 40 mojom::PowerInstance* power_instance = |
| 41 arc_bridge_service()->power()->instance(); |
| 46 if (!power_instance) { | 42 if (!power_instance) { |
| 47 LOG(ERROR) << "PowerInstance is not available"; | 43 LOG(ERROR) << "PowerInstance is not available"; |
| 48 return; | 44 return; |
| 49 } | 45 } |
| 50 | 46 |
| 51 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); | 47 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); |
| 52 power_instance->SetInteractive(enabled); | 48 power_instance->SetInteractive(enabled); |
| 53 } | 49 } |
| 54 | 50 |
| 55 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { | 51 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 chromeos::PowerPolicyController* controller = | 108 chromeos::PowerPolicyController* controller = |
| 113 chromeos::PowerPolicyController::Get(); | 109 chromeos::PowerPolicyController::Get(); |
| 114 | 110 |
| 115 for (const auto& it : wake_locks_) { | 111 for (const auto& it : wake_locks_) { |
| 116 controller->RemoveWakeLock(it.second); | 112 controller->RemoveWakeLock(it.second); |
| 117 } | 113 } |
| 118 wake_locks_.clear(); | 114 wake_locks_.clear(); |
| 119 } | 115 } |
| 120 | 116 |
| 121 } // namespace arc | 117 } // namespace arc |
| OLD | NEW |