Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: components/arc/power/arc_power_bridge.cc

Issue 2805433002: Adding ArcBridge interface for synchronizing brightness settings (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 chromeos::DisplayPowerState power_state) { 67 chromeos::DisplayPowerState power_state) {
68 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD( 68 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD(
69 arc_bridge_service()->power(), SetInteractive); 69 arc_bridge_service()->power(), SetInteractive);
70 if (!power_instance) 70 if (!power_instance)
71 return; 71 return;
72 72
73 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); 73 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF);
74 power_instance->SetInteractive(enabled); 74 power_instance->SetInteractive(enabled);
75 } 75 }
76 76
77 void ArcPowerBridge::NotifyBrightnessChange(double percent) {
78 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD(
79 arc_bridge_service()->power(), UpdateBrightness);
80 if (!power_instance)
81 return;
82
83 int brightness = round(percent * 2.55);
Muyuan 2017/04/05 18:41:10 Document why multiply this by 2.55
yueli 2017/04/05 19:59:47 Done.
84 power_instance->UpdateBrightness(brightness);
85 }
86
77 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { 87 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) {
78 if (!chromeos::PowerPolicyController::IsInitialized()) { 88 if (!chromeos::PowerPolicyController::IsInitialized()) {
79 LOG(WARNING) << "PowerPolicyController is not available"; 89 LOG(WARNING) << "PowerPolicyController is not available";
80 return; 90 return;
81 } 91 }
82 chromeos::PowerPolicyController* controller = 92 chromeos::PowerPolicyController* controller =
83 chromeos::PowerPolicyController::Get(); 93 chromeos::PowerPolicyController::Get();
84 94
85 int wake_lock_id = -1; 95 int wake_lock_id = -1;
86 switch (type) { 96 switch (type) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 129 }
120 controller->RemoveWakeLock(it->second); 130 controller->RemoveWakeLock(it->second);
121 wake_locks_.erase(it); 131 wake_locks_.erase(it);
122 } 132 }
123 133
124 void ArcPowerBridge::IsDisplayOn(const IsDisplayOnCallback& callback) { 134 void ArcPowerBridge::IsDisplayOn(const IsDisplayOnCallback& callback) {
125 callback.Run( 135 callback.Run(
126 ash::Shell::GetInstance()->display_configurator()->IsDisplayOn()); 136 ash::Shell::GetInstance()->display_configurator()->IsDisplayOn());
127 } 137 }
128 138
139 void ArcPowerBridge::SetBrightness(int32_t brightness) {
140 if (!chromeos::DBusThreadManager::IsInitialized()) {
141 LOG(WARNING) << "DBusThreadManager is not available";
142 return;
143 }
144 chromeos::DBusThreadManager::Get()
145 ->GetPowerManagerClient()
146 ->SetScreenBrightnessPercent(brightness / 2.55, true);
147 return;
148 }
149
150 void ArcPowerBridge::SyncBrightness() {
151 if (!chromeos::DBusThreadManager::IsInitialized()) {
152 LOG(WARNING) << "DBusThreadManager is not available";
153 return;
154 }
155 chromeos::DBusThreadManager::Get()
156 ->GetPowerManagerClient()
157 ->SyncScreenBrightness();
158 return;
159 }
160
129 void ArcPowerBridge::ReleaseAllDisplayWakeLocks() { 161 void ArcPowerBridge::ReleaseAllDisplayWakeLocks() {
130 if (!chromeos::PowerPolicyController::IsInitialized()) { 162 if (!chromeos::PowerPolicyController::IsInitialized()) {
131 LOG(WARNING) << "PowerPolicyController is not available"; 163 LOG(WARNING) << "PowerPolicyController is not available";
132 return; 164 return;
133 } 165 }
134 chromeos::PowerPolicyController* controller = 166 chromeos::PowerPolicyController* controller =
135 chromeos::PowerPolicyController::Get(); 167 chromeos::PowerPolicyController::Get();
136 168
137 for (const auto& it : wake_locks_) { 169 for (const auto& it : wake_locks_) {
138 controller->RemoveWakeLock(it.second); 170 controller->RemoveWakeLock(it.second);
139 } 171 }
140 wake_locks_.clear(); 172 wake_locks_.clear();
141 } 173 }
142 174
143 } // namespace arc 175 } // namespace arc
OLDNEW
« components/arc/power/arc_power_bridge.h ('K') | « components/arc/power/arc_power_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698