OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "modules/sensor/SensorProxy.h" | 5 #include "modules/sensor/SensorProxy.h" |
6 | 6 |
7 #include "core/frame/LocalFrame.h" | 7 #include "core/frame/LocalFrame.h" |
8 #include "modules/sensor/SensorProviderProxy.h" | 8 #include "modules/sensor/SensorProviderProxy.h" |
9 #include "platform/mojo/MojoHelper.h" | 9 #include "platform/mojo/MojoHelper.h" |
10 | 10 |
11 using namespace device::mojom::blink; | 11 using namespace device::mojom::blink; |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 SensorProxy::SensorProxy(SensorType sensorType, SensorProviderProxy* provider) | 15 SensorProxy::SensorProxy(SensorType sensorType, Page* page, SensorProviderProxy*
provider) |
16 : m_type(sensorType) | 16 : PageVisibilityObserver(page) |
| 17 , m_type(sensorType) |
17 , m_mode(ReportingMode::CONTINUOUS) | 18 , m_mode(ReportingMode::CONTINUOUS) |
18 , m_provider(provider) | 19 , m_provider(provider) |
19 , m_clientBinding(this) | 20 , m_clientBinding(this) |
20 , m_state(SensorProxy::Uninitialized) | 21 , m_state(SensorProxy::Uninitialized) |
21 , m_reading() | 22 , m_reading() |
22 { | 23 { |
23 } | 24 } |
24 | 25 |
25 SensorProxy::~SensorProxy() | 26 SensorProxy::~SensorProxy() |
26 { | 27 { |
27 } | 28 } |
28 | 29 |
29 void SensorProxy::dispose() | 30 void SensorProxy::dispose() |
30 { | 31 { |
31 m_clientBinding.Close(); | 32 m_clientBinding.Close(); |
32 } | 33 } |
33 | 34 |
34 DEFINE_TRACE(SensorProxy) | 35 DEFINE_TRACE(SensorProxy) |
35 { | 36 { |
36 visitor->trace(m_observers); | 37 visitor->trace(m_observers); |
37 visitor->trace(m_provider); | 38 visitor->trace(m_provider); |
| 39 PageVisibilityObserver::trace(visitor); |
38 } | 40 } |
39 | 41 |
40 void SensorProxy::addObserver(Observer* observer) | 42 void SensorProxy::addObserver(Observer* observer) |
41 { | 43 { |
42 if (!m_observers.contains(observer)) | 44 if (!m_observers.contains(observer)) |
43 m_observers.add(observer); | 45 m_observers.add(observer); |
44 } | 46 } |
45 | 47 |
46 void SensorProxy::removeObserver(Observer* observer) | 48 void SensorProxy::removeObserver(Observer* observer) |
47 { | 49 { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 { | 89 { |
88 handleSensorError(); | 90 handleSensorError(); |
89 } | 91 } |
90 | 92 |
91 void SensorProxy::SensorReadingChanged() | 93 void SensorProxy::SensorReadingChanged() |
92 { | 94 { |
93 for (Observer* observer : m_observers) | 95 for (Observer* observer : m_observers) |
94 observer->onSensorReadingChanged(); | 96 observer->onSensorReadingChanged(); |
95 } | 97 } |
96 | 98 |
| 99 void SensorProxy::pageVisibilityChanged() |
| 100 { |
| 101 if (!isInitialized()) |
| 102 return; |
| 103 |
| 104 if (page()->visibilityState() != PageVisibilityStateVisible) { |
| 105 m_sensor->Suspend(); |
| 106 } else { |
| 107 m_sensor->Resume(); |
| 108 } |
| 109 } |
| 110 |
97 void SensorProxy::handleSensorError() | 111 void SensorProxy::handleSensorError() |
98 { | 112 { |
99 m_state = Uninitialized; | 113 m_state = Uninitialized; |
100 m_sensor.reset(); | 114 m_sensor.reset(); |
101 for (Observer* observer : m_observers) | 115 for (Observer* observer : m_observers) |
102 observer->onSensorError(); | 116 observer->onSensorError(); |
103 } | 117 } |
104 | 118 |
105 void SensorProxy::onSensorCreated(SensorReadBufferPtr buffer, SensorClientReques
t clientRequest) | 119 void SensorProxy::onSensorCreated(SensorReadBufferPtr buffer, SensorClientReques
t clientRequest) |
106 { | 120 { |
(...skipping 18 matching lines...) Expand all Loading... |
125 handleSensorError(); | 139 handleSensorError(); |
126 return; | 140 return; |
127 } | 141 } |
128 | 142 |
129 m_state = Initialized; | 143 m_state = Initialized; |
130 for (Observer* observer : m_observers) | 144 for (Observer* observer : m_observers) |
131 observer->onSensorInitialized(); | 145 observer->onSensorInitialized(); |
132 } | 146 } |
133 | 147 |
134 } // namespace blink | 148 } // namespace blink |
OLD | NEW |