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

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

Issue 2805433002: Adding ArcBridge interface for synchronizing brightness settings (Closed)
Patch Set: Renaming 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"
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(
40 base::Bind(&ArcPowerBridge::UpdateAndroidScreenBrightness,
41 weak_ptr_factory_.GetWeakPtr()));
37 } 42 }
38 43
39 void ArcPowerBridge::OnInstanceClosed() { 44 void ArcPowerBridge::OnInstanceClosed() {
40 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); 45 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this);
41 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> 46 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
42 RemoveObserver(this); 47 RemoveObserver(this);
43 ReleaseAllDisplayWakeLocks(); 48 ReleaseAllDisplayWakeLocks();
44 } 49 }
45 50
46 void ArcPowerBridge::SuspendImminent() { 51 void ArcPowerBridge::SuspendImminent() {
(...skipping 20 matching lines...) Expand all
67 chromeos::DisplayPowerState power_state) { 72 chromeos::DisplayPowerState power_state) {
68 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD( 73 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD(
69 arc_bridge_service()->power(), SetInteractive); 74 arc_bridge_service()->power(), SetInteractive);
70 if (!power_instance) 75 if (!power_instance)
71 return; 76 return;
72 77
73 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); 78 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF);
74 power_instance->SetInteractive(enabled); 79 power_instance->SetInteractive(enabled);
75 } 80 }
76 81
82 void ArcPowerBridge::BrightnessChanged(int level, bool user_initiated) {
Luis Héctor Chávez 2017/04/06 01:36:20 This should also be moved to L70.
yueli 2017/04/06 16:43:00 Done.
83 UpdateAndroidScreenBrightness(static_cast<double>(level));
84 }
85
77 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { 86 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) {
78 if (!chromeos::PowerPolicyController::IsInitialized()) { 87 if (!chromeos::PowerPolicyController::IsInitialized()) {
79 LOG(WARNING) << "PowerPolicyController is not available"; 88 LOG(WARNING) << "PowerPolicyController is not available";
80 return; 89 return;
81 } 90 }
82 chromeos::PowerPolicyController* controller = 91 chromeos::PowerPolicyController* controller =
83 chromeos::PowerPolicyController::Get(); 92 chromeos::PowerPolicyController::Get();
84 93
85 int wake_lock_id = -1; 94 int wake_lock_id = -1;
86 switch (type) { 95 switch (type) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 128 }
120 controller->RemoveWakeLock(it->second); 129 controller->RemoveWakeLock(it->second);
121 wake_locks_.erase(it); 130 wake_locks_.erase(it);
122 } 131 }
123 132
124 void ArcPowerBridge::IsDisplayOn(const IsDisplayOnCallback& callback) { 133 void ArcPowerBridge::IsDisplayOn(const IsDisplayOnCallback& callback) {
125 callback.Run( 134 callback.Run(
126 ash::Shell::GetInstance()->display_configurator()->IsDisplayOn()); 135 ash::Shell::GetInstance()->display_configurator()->IsDisplayOn());
127 } 136 }
128 137
138 void ArcPowerBridge::OnScreenBrightnessUpdateRequest(double percent) {
139 chromeos::DBusThreadManager::Get()
140 ->GetPowerManagerClient()
141 ->SetScreenBrightnessPercent(percent, true);
142 }
143
129 void ArcPowerBridge::ReleaseAllDisplayWakeLocks() { 144 void ArcPowerBridge::ReleaseAllDisplayWakeLocks() {
130 if (!chromeos::PowerPolicyController::IsInitialized()) { 145 if (!chromeos::PowerPolicyController::IsInitialized()) {
131 LOG(WARNING) << "PowerPolicyController is not available"; 146 LOG(WARNING) << "PowerPolicyController is not available";
132 return; 147 return;
133 } 148 }
134 chromeos::PowerPolicyController* controller = 149 chromeos::PowerPolicyController* controller =
135 chromeos::PowerPolicyController::Get(); 150 chromeos::PowerPolicyController::Get();
136 151
137 for (const auto& it : wake_locks_) { 152 for (const auto& it : wake_locks_) {
138 controller->RemoveWakeLock(it.second); 153 controller->RemoveWakeLock(it.second);
139 } 154 }
140 wake_locks_.clear(); 155 wake_locks_.clear();
141 } 156 }
142 157
158 void ArcPowerBridge::UpdateAndroidScreenBrightness(double percent) {
159 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD(
160 arc_bridge_service()->power(), UpdateScreenBrightnessSettings);
161 if (!power_instance)
162 return;
163 power_instance->UpdateScreenBrightnessSettings(percent);
164 }
165
143 } // namespace arc 166 } // 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