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