| 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()->AddObserver(this); |
| 20 } | 20 } |
| 21 | 21 |
| 22 ArcPowerBridge::~ArcPowerBridge() { | 22 ArcPowerBridge::~ArcPowerBridge() { |
| 23 arc_bridge_service()->RemoveObserver(this); | 23 arc_bridge_service()->RemoveObserver(this); |
| 24 ReleaseAllDisplayWakeLocks(); | 24 ReleaseAllDisplayWakeLocks(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void ArcPowerBridge::OnPowerInstanceReady() { | 27 void ArcPowerBridge::OnPowerInstanceReady() { |
| 28 PowerInstance* power_instance = arc_bridge_service()->power_instance(); | 28 mojom::PowerInstance* power_instance = arc_bridge_service()->power_instance(); |
| 29 if (!power_instance) { | 29 if (!power_instance) { |
| 30 LOG(ERROR) << "OnPowerInstanceReady called, but no power instance found"; | 30 LOG(ERROR) << "OnPowerInstanceReady called, but no power instance found"; |
| 31 return; | 31 return; |
| 32 } | 32 } |
| 33 | 33 |
| 34 power_instance->Init(binding_.CreateInterfacePtrAndBind()); | 34 power_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 35 ash::Shell::GetInstance()->display_configurator()->AddObserver(this); | 35 ash::Shell::GetInstance()->display_configurator()->AddObserver(this); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void ArcPowerBridge::OnPowerInstanceClosed() { | 38 void ArcPowerBridge::OnPowerInstanceClosed() { |
| 39 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 39 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
| 40 ReleaseAllDisplayWakeLocks(); | 40 ReleaseAllDisplayWakeLocks(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ArcPowerBridge::OnPowerStateChanged( | 43 void ArcPowerBridge::OnPowerStateChanged( |
| 44 chromeos::DisplayPowerState power_state) { | 44 chromeos::DisplayPowerState power_state) { |
| 45 PowerInstance* power_instance = arc_bridge_service()->power_instance(); | 45 mojom::PowerInstance* power_instance = arc_bridge_service()->power_instance(); |
| 46 if (!power_instance) { | 46 if (!power_instance) { |
| 47 LOG(ERROR) << "PowerInstance is not available"; | 47 LOG(ERROR) << "PowerInstance is not available"; |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); | 51 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); |
| 52 power_instance->SetInteractive(enabled); | 52 power_instance->SetInteractive(enabled); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void ArcPowerBridge::OnAcquireDisplayWakeLock( | 55 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { |
| 56 DisplayWakeLockType type) { | |
| 57 if (!chromeos::PowerPolicyController::IsInitialized()) { | 56 if (!chromeos::PowerPolicyController::IsInitialized()) { |
| 58 LOG(WARNING) << "PowerPolicyController is not available"; | 57 LOG(WARNING) << "PowerPolicyController is not available"; |
| 59 return; | 58 return; |
| 60 } | 59 } |
| 61 chromeos::PowerPolicyController* controller = | 60 chromeos::PowerPolicyController* controller = |
| 62 chromeos::PowerPolicyController::Get(); | 61 chromeos::PowerPolicyController::Get(); |
| 63 | 62 |
| 64 int wake_lock_id = -1; | 63 int wake_lock_id = -1; |
| 65 switch (type) { | 64 switch (type) { |
| 66 case DisplayWakeLockType::BRIGHT: | 65 case mojom::DisplayWakeLockType::BRIGHT: |
| 67 wake_lock_id = controller->AddScreenWakeLock( | 66 wake_lock_id = controller->AddScreenWakeLock( |
| 68 chromeos::PowerPolicyController::REASON_OTHER, "ARC"); | 67 chromeos::PowerPolicyController::REASON_OTHER, "ARC"); |
| 69 break; | 68 break; |
| 70 case DisplayWakeLockType::DIM: | 69 case mojom::DisplayWakeLockType::DIM: |
| 71 wake_lock_id = controller->AddDimWakeLock( | 70 wake_lock_id = controller->AddDimWakeLock( |
| 72 chromeos::PowerPolicyController::REASON_OTHER, "ARC"); | 71 chromeos::PowerPolicyController::REASON_OTHER, "ARC"); |
| 73 break; | 72 break; |
| 74 default: | 73 default: |
| 75 LOG(WARNING) << "Tried to take invalid wake lock type " | 74 LOG(WARNING) << "Tried to take invalid wake lock type " |
| 76 << static_cast<int>(type); | 75 << static_cast<int>(type); |
| 77 return; | 76 return; |
| 78 } | 77 } |
| 79 wake_locks_.insert(std::make_pair(type, wake_lock_id)); | 78 wake_locks_.insert(std::make_pair(type, wake_lock_id)); |
| 80 } | 79 } |
| 81 | 80 |
| 82 void ArcPowerBridge::OnReleaseDisplayWakeLock( | 81 void ArcPowerBridge::OnReleaseDisplayWakeLock(mojom::DisplayWakeLockType type) { |
| 83 DisplayWakeLockType type) { | |
| 84 if (!chromeos::PowerPolicyController::IsInitialized()) { | 82 if (!chromeos::PowerPolicyController::IsInitialized()) { |
| 85 LOG(WARNING) << "PowerPolicyController is not available"; | 83 LOG(WARNING) << "PowerPolicyController is not available"; |
| 86 return; | 84 return; |
| 87 } | 85 } |
| 88 chromeos::PowerPolicyController* controller = | 86 chromeos::PowerPolicyController* controller = |
| 89 chromeos::PowerPolicyController::Get(); | 87 chromeos::PowerPolicyController::Get(); |
| 90 | 88 |
| 91 // From the perspective of the PowerPolicyController, all wake locks | 89 // From the perspective of the PowerPolicyController, all wake locks |
| 92 // of a given type are equivalent, so it doesn't matter which one | 90 // of a given type are equivalent, so it doesn't matter which one |
| 93 // we pass to the controller here. | 91 // we pass to the controller here. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 114 chromeos::PowerPolicyController* controller = | 112 chromeos::PowerPolicyController* controller = |
| 115 chromeos::PowerPolicyController::Get(); | 113 chromeos::PowerPolicyController::Get(); |
| 116 | 114 |
| 117 for (const auto& it : wake_locks_) { | 115 for (const auto& it : wake_locks_) { |
| 118 controller->RemoveWakeLock(it.second); | 116 controller->RemoveWakeLock(it.second); |
| 119 } | 117 } |
| 120 wake_locks_.clear(); | 118 wake_locks_.clear(); |
| 121 } | 119 } |
| 122 | 120 |
| 123 } // namespace arc | 121 } // namespace arc |
| OLD | NEW |