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_bridge_service.h" | 13 #include "components/arc/arc_bridge_service.h" |
14 #include "components/arc/arc_service_manager.h" | 14 #include "components/arc/arc_service_manager.h" |
15 | 15 |
16 namespace arc { | 16 namespace arc { |
17 | 17 |
18 namespace { | |
19 | |
20 constexpr uint32_t kMinVersionForSetInteractive = 1; | |
21 | |
22 } // namespace | |
23 | |
24 ArcPowerBridge::ArcPowerBridge(ArcBridgeService* bridge_service) | 18 ArcPowerBridge::ArcPowerBridge(ArcBridgeService* bridge_service) |
25 : ArcService(bridge_service), binding_(this) { | 19 : ArcService(bridge_service), binding_(this) { |
26 arc_bridge_service()->power()->AddObserver(this); | 20 arc_bridge_service()->power()->AddObserver(this); |
27 } | 21 } |
28 | 22 |
29 ArcPowerBridge::~ArcPowerBridge() { | 23 ArcPowerBridge::~ArcPowerBridge() { |
30 arc_bridge_service()->power()->RemoveObserver(this); | 24 arc_bridge_service()->power()->RemoveObserver(this); |
31 ReleaseAllDisplayWakeLocks(); | 25 ReleaseAllDisplayWakeLocks(); |
32 } | 26 } |
33 | 27 |
34 void ArcPowerBridge::OnInstanceReady() { | 28 void ArcPowerBridge::OnInstanceReady() { |
35 mojom::PowerInstance* power_instance = | 29 mojom::PowerInstance* power_instance = |
36 arc_bridge_service()->power()->GetInstanceForMethod("Init"); | 30 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->power(), Init); |
37 DCHECK(power_instance); | 31 DCHECK(power_instance); |
38 power_instance->Init(binding_.CreateInterfacePtrAndBind()); | 32 power_instance->Init(binding_.CreateInterfacePtrAndBind()); |
39 ash::Shell::GetInstance()->display_configurator()->AddObserver(this); | 33 ash::Shell::GetInstance()->display_configurator()->AddObserver(this); |
40 } | 34 } |
41 | 35 |
42 void ArcPowerBridge::OnInstanceClosed() { | 36 void ArcPowerBridge::OnInstanceClosed() { |
43 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 37 ash::Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
44 ReleaseAllDisplayWakeLocks(); | 38 ReleaseAllDisplayWakeLocks(); |
45 } | 39 } |
46 | 40 |
47 void ArcPowerBridge::OnPowerStateChanged( | 41 void ArcPowerBridge::OnPowerStateChanged( |
48 chromeos::DisplayPowerState power_state) { | 42 chromeos::DisplayPowerState power_state) { |
49 mojom::PowerInstance* power_instance = | 43 mojom::PowerInstance* power_instance = ARC_GET_INSTANCE_FOR_METHOD( |
50 arc_bridge_service()->power()->GetInstanceForMethod( | 44 arc_bridge_service()->power(), SetInteractive); |
51 "SetInteractive", kMinVersionForSetInteractive); | |
52 if (!power_instance) | 45 if (!power_instance) |
53 return; | 46 return; |
54 | 47 |
55 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); | 48 bool enabled = (power_state != chromeos::DISPLAY_POWER_ALL_OFF); |
56 power_instance->SetInteractive(enabled); | 49 power_instance->SetInteractive(enabled); |
57 } | 50 } |
58 | 51 |
59 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { | 52 void ArcPowerBridge::OnAcquireDisplayWakeLock(mojom::DisplayWakeLockType type) { |
60 if (!chromeos::PowerPolicyController::IsInitialized()) { | 53 if (!chromeos::PowerPolicyController::IsInitialized()) { |
61 LOG(WARNING) << "PowerPolicyController is not available"; | 54 LOG(WARNING) << "PowerPolicyController is not available"; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 chromeos::PowerPolicyController* controller = | 109 chromeos::PowerPolicyController* controller = |
117 chromeos::PowerPolicyController::Get(); | 110 chromeos::PowerPolicyController::Get(); |
118 | 111 |
119 for (const auto& it : wake_locks_) { | 112 for (const auto& it : wake_locks_) { |
120 controller->RemoveWakeLock(it.second); | 113 controller->RemoveWakeLock(it.second); |
121 } | 114 } |
122 wake_locks_.clear(); | 115 wake_locks_.clear(); |
123 } | 116 } |
124 | 117 |
125 } // namespace arc | 118 } // namespace arc |
OLD | NEW |