Chromium Code Reviews| 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/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/power_policy_controller.h" | 13 #include "chromeos/dbus/power_policy_controller.h" |
| 14 #include "components/arc/arc_bridge_service.h" | 14 #include "components/arc/arc_bridge_service.h" |
| 15 #include "components/arc/arc_service_manager.h" | 15 #include "components/arc/arc_service_manager.h" |
| 16 | 16 |
| 17 namespace arc { | 17 namespace arc { |
| 18 | 18 |
| 19 ArcPowerBridge::ArcPowerBridge(ArcBridgeService* bridge_service) | 19 ArcPowerBridge::ArcPowerBridge(ArcBridgeService* bridge_service) |
| 20 : ArcService(bridge_service), binding_(this) { | 20 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) { |
| 21 arc_bridge_service()->power()->AddObserver(this); | 21 arc_bridge_service()->power()->AddObserver(this); |
| 22 } | 22 } |
| 23 | 23 |
| 24 ArcPowerBridge::~ArcPowerBridge() { | 24 ArcPowerBridge::~ArcPowerBridge() { |
| 25 arc_bridge_service()->power()->RemoveObserver(this); | 25 arc_bridge_service()->power()->RemoveObserver(this); |
| 26 ReleaseAllDisplayWakeLocks(); | 26 ReleaseAllDisplayWakeLocks(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void ArcPowerBridge::OnInstanceReady() { | 29 void ArcPowerBridge::OnInstanceReady() { |
| 30 mojom::PowerInstance* power_instance = | 30 mojom::PowerInstance* power_instance = |
| 31 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->power(), Init); | 31 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->power(), Init); |
| 32 DCHECK(power_instance); | 32 DCHECK(power_instance); |
| 33 power_instance->Init(binding_.CreateInterfacePtrAndBind()); | 33 power_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 34 ash::Shell::GetInstance()->display_configurator()->AddObserver(this); | 34 ash::Shell::GetInstance()->display_configurator()->AddObserver(this); |
| 35 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 35 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 36 AddObserver(this); | 36 AddObserver(this); |
| 37 chromeos::DBusThreadManager::Get() | |
| 38 ->GetPowerManagerClient() | |
| 39 ->GetScreenBrightnessPercent(base::Bind(&ArcPowerBridge::UpdateBrightness, | |
| 40 weak_ptr_factory_.GetWeakPtr())); | |
| 37 } | 41 } |
| 38 | 42 |
| 39 void ArcPowerBridge::OnInstanceClosed() { | 43 void ArcPowerBridge::OnInstanceClosed() { |
| 40 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 44 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
| 41 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 45 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 42 RemoveObserver(this); | 46 RemoveObserver(this); |
| 43 ReleaseAllDisplayWakeLocks(); | 47 ReleaseAllDisplayWakeLocks(); |
| 44 } | 48 } |
| 45 | 49 |
| 46 void ArcPowerBridge::SuspendImminent() { | 50 void ArcPowerBridge::SuspendImminent() { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 67 chromeos::DisplayPowerState power_state) { | 71 chromeos::DisplayPowerState power_state) { |
| 68 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD( | 72 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD( |
| 69 arc_bridge_service()->power(), SetInteractive); | 73 arc_bridge_service()->power(), SetInteractive); |
| 70 if (!power_instance) | 74 if (!power_instance) |
| 71 return; | 75 return; |
| 72 | 76 |
| 73 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); | 77 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); |
| 74 power_instance->SetInteractive(enabled); | 78 power_instance->SetInteractive(enabled); |
| 75 } | 79 } |
| 76 | 80 |
| 81 void ArcPowerBridge::UpdateBrightness(double percent) { | |
| 82 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD( | |
| 83 arc_bridge_service()->power(), UpdateBrightness); | |
| 84 if (!power_instance) | |
| 85 return; | |
| 86 power_instance->UpdateBrightness(percent); | |
|
Daniel Erat
2017/04/05 23:43:38
nit: just do:
if (power_instance)
power_ins
| |
| 87 } | |
| 88 | |
| 89 void ArcPowerBridge::BrightnessChanged(int level, bool user_initiated) { | |
|
Daniel Erat
2017/04/05 23:43:38
please make order of methods in .cc files match or
yueli
2017/04/06 01:12:37
Done.
| |
| 90 UpdateBrightness(static_cast<double>(level)); | |
| 91 } | |
| 92 | |
| 77 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { | 93 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { |
| 78 if (!chromeos::PowerPolicyController::IsInitialized()) { | 94 if (!chromeos::PowerPolicyController::IsInitialized()) { |
| 79 LOG(WARNING) << "PowerPolicyController is not available"; | 95 LOG(WARNING) << "PowerPolicyController is not available"; |
| 80 return; | 96 return; |
| 81 } | 97 } |
| 82 chromeos::PowerPolicyController* controller = | 98 chromeos::PowerPolicyController* controller = |
| 83 chromeos::PowerPolicyController::Get(); | 99 chromeos::PowerPolicyController::Get(); |
| 84 | 100 |
| 85 int wake_lock_id = -1; | 101 int wake_lock_id = -1; |
| 86 switch (type) { | 102 switch (type) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 } | 135 } |
| 120 controller->RemoveWakeLock(it->second); | 136 controller->RemoveWakeLock(it->second); |
| 121 wake_locks_.erase(it); | 137 wake_locks_.erase(it); |
| 122 } | 138 } |
| 123 | 139 |
| 124 void ArcPowerBridge::IsDisplayOn(const IsDisplayOnCallback& callback) { | 140 void ArcPowerBridge::IsDisplayOn(const IsDisplayOnCallback& callback) { |
| 125 callback.Run( | 141 callback.Run( |
| 126 ash::Shell::GetInstance()->display_configurator()->IsDisplayOn()); | 142 ash::Shell::GetInstance()->display_configurator()->IsDisplayOn()); |
| 127 } | 143 } |
| 128 | 144 |
| 145 void ArcPowerBridge::SetBrightness(double percent) { | |
| 146 chromeos::DBusThreadManager::Get() | |
| 147 ->GetPowerManagerClient() | |
| 148 ->SetScreenBrightnessPercent(percent, true); | |
| 149 return; | |
|
Daniel Erat
2017/04/05 23:43:38
remove pointless return statement
yueli
2017/04/06 01:12:37
Done.
| |
| 150 } | |
| 151 | |
| 129 void ArcPowerBridge::ReleaseAllDisplayWakeLocks() { | 152 void ArcPowerBridge::ReleaseAllDisplayWakeLocks() { |
| 130 if (!chromeos::PowerPolicyController::IsInitialized()) { | 153 if (!chromeos::PowerPolicyController::IsInitialized()) { |
| 131 LOG(WARNING) << "PowerPolicyController is not available"; | 154 LOG(WARNING) << "PowerPolicyController is not available"; |
| 132 return; | 155 return; |
| 133 } | 156 } |
| 134 chromeos::PowerPolicyController* controller = | 157 chromeos::PowerPolicyController* controller = |
| 135 chromeos::PowerPolicyController::Get(); | 158 chromeos::PowerPolicyController::Get(); |
| 136 | 159 |
| 137 for (const auto& it : wake_locks_) { | 160 for (const auto& it : wake_locks_) { |
| 138 controller->RemoveWakeLock(it.second); | 161 controller->RemoveWakeLock(it.second); |
| 139 } | 162 } |
| 140 wake_locks_.clear(); | 163 wake_locks_.clear(); |
| 141 } | 164 } |
| 142 | 165 |
| 143 } // namespace arc | 166 } // namespace arc |
| OLD | NEW |