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" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 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 ->SyncScreenBrightness(); | |
|
Luis Héctor Chávez
2017/04/05 21:28:02
You don't need SyncScreenBrightness() either :) In
yueli
2017/04/05 23:27:17
Thanks Luis!
Done.
| |
| 37 } | 40 } |
| 38 | 41 |
| 39 void ArcPowerBridge::OnInstanceClosed() { | 42 void ArcPowerBridge::OnInstanceClosed() { |
| 40 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 43 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
| 41 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 44 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 42 RemoveObserver(this); | 45 RemoveObserver(this); |
| 43 ReleaseAllDisplayWakeLocks(); | 46 ReleaseAllDisplayWakeLocks(); |
| 44 } | 47 } |
| 45 | 48 |
| 46 void ArcPowerBridge::SuspendImminent() { | 49 void ArcPowerBridge::SuspendImminent() { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 67 chromeos::DisplayPowerState power_state) { | 70 chromeos::DisplayPowerState power_state) { |
| 68 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD( | 71 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD( |
| 69 arc_bridge_service()->power(), SetInteractive); | 72 arc_bridge_service()->power(), SetInteractive); |
| 70 if (!power_instance) | 73 if (!power_instance) |
| 71 return; | 74 return; |
| 72 | 75 |
| 73 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); | 76 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); |
| 74 power_instance->SetInteractive(enabled); | 77 power_instance->SetInteractive(enabled); |
| 75 } | 78 } |
| 76 | 79 |
| 80 void ArcPowerBridge::BrightnessChanged(int level, bool user_initiated) { | |
| 81 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD( | |
| 82 arc_bridge_service()->power(), UpdateBrightness); | |
| 83 if (!power_instance) | |
| 84 return; | |
| 85 // Android side brightness is of the range [0, 255] | |
| 86 int brightness = round(level * 2.55); | |
| 87 power_instance->UpdateBrightness(brightness); | |
| 88 } | |
| 89 | |
| 77 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { | 90 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { |
| 78 if (!chromeos::PowerPolicyController::IsInitialized()) { | 91 if (!chromeos::PowerPolicyController::IsInitialized()) { |
| 79 LOG(WARNING) << "PowerPolicyController is not available"; | 92 LOG(WARNING) << "PowerPolicyController is not available"; |
| 80 return; | 93 return; |
| 81 } | 94 } |
| 82 chromeos::PowerPolicyController* controller = | 95 chromeos::PowerPolicyController* controller = |
| 83 chromeos::PowerPolicyController::Get(); | 96 chromeos::PowerPolicyController::Get(); |
| 84 | 97 |
| 85 int wake_lock_id = -1; | 98 int wake_lock_id = -1; |
| 86 switch (type) { | 99 switch (type) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 } | 132 } |
| 120 controller->RemoveWakeLock(it->second); | 133 controller->RemoveWakeLock(it->second); |
| 121 wake_locks_.erase(it); | 134 wake_locks_.erase(it); |
| 122 } | 135 } |
| 123 | 136 |
| 124 void ArcPowerBridge::IsDisplayOn(const IsDisplayOnCallback& callback) { | 137 void ArcPowerBridge::IsDisplayOn(const IsDisplayOnCallback& callback) { |
| 125 callback.Run( | 138 callback.Run( |
| 126 ash::Shell::GetInstance()->display_configurator()->IsDisplayOn()); | 139 ash::Shell::GetInstance()->display_configurator()->IsDisplayOn()); |
| 127 } | 140 } |
| 128 | 141 |
| 142 void ArcPowerBridge::SetBrightness(int32_t brightness) { | |
| 143 // Android side brightness is of the range [0, 255] | |
| 144 chromeos::DBusThreadManager::Get() | |
| 145 ->GetPowerManagerClient() | |
| 146 ->SetScreenBrightnessPercent(brightness / 2.55, true); | |
| 147 return; | |
| 148 } | |
| 149 | |
| 129 void ArcPowerBridge::ReleaseAllDisplayWakeLocks() { | 150 void ArcPowerBridge::ReleaseAllDisplayWakeLocks() { |
| 130 if (!chromeos::PowerPolicyController::IsInitialized()) { | 151 if (!chromeos::PowerPolicyController::IsInitialized()) { |
| 131 LOG(WARNING) << "PowerPolicyController is not available"; | 152 LOG(WARNING) << "PowerPolicyController is not available"; |
| 132 return; | 153 return; |
| 133 } | 154 } |
| 134 chromeos::PowerPolicyController* controller = | 155 chromeos::PowerPolicyController* controller = |
| 135 chromeos::PowerPolicyController::Get(); | 156 chromeos::PowerPolicyController::Get(); |
| 136 | 157 |
| 137 for (const auto& it : wake_locks_) { | 158 for (const auto& it : wake_locks_) { |
| 138 controller->RemoveWakeLock(it.second); | 159 controller->RemoveWakeLock(it.second); |
| 139 } | 160 } |
| 140 wake_locks_.clear(); | 161 wake_locks_.clear(); |
| 141 } | 162 } |
| 142 | 163 |
| 143 } // namespace arc | 164 } // namespace arc |
| OLD | NEW |