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, SensorProviderProxy* provider) |
16 : m_type(sensorType) | 16 : m_type(sensorType) |
17 , m_mode(ReportingMode::CONTINUOUS) | 17 , m_mode(ReportingMode::CONTINUOUS) |
18 , m_provider(provider) | 18 , m_provider(provider) |
19 , m_clientBinding(this) | 19 , m_clientBinding(this) |
20 , m_state(SensorProxy::Uninitialized) | 20 , m_state(SensorProxy::Uninitialized) |
21 , m_reading() | 21 , m_reading() |
| 22 , m_suspended(false) |
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(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 DCHECK(isInitialized()); | 70 DCHECK(isInitialized()); |
70 m_sensor->AddConfiguration(std::move(configuration), convertToBaseCallback(s
td::move(callback))); | 71 m_sensor->AddConfiguration(std::move(configuration), convertToBaseCallback(s
td::move(callback))); |
71 } | 72 } |
72 | 73 |
73 void SensorProxy::removeConfiguration(SensorConfigurationPtr configuration, std:
:unique_ptr<Function<void(bool)>> callback) | 74 void SensorProxy::removeConfiguration(SensorConfigurationPtr configuration, std:
:unique_ptr<Function<void(bool)>> callback) |
74 { | 75 { |
75 DCHECK(isInitialized()); | 76 DCHECK(isInitialized()); |
76 m_sensor->RemoveConfiguration(std::move(configuration), convertToBaseCallbac
k(std::move(callback))); | 77 m_sensor->RemoveConfiguration(std::move(configuration), convertToBaseCallbac
k(std::move(callback))); |
77 } | 78 } |
78 | 79 |
| 80 void SensorProxy::suspend() |
| 81 { |
| 82 DCHECK(isInitialized()); |
| 83 if (m_suspended) |
| 84 return; |
| 85 |
| 86 m_sensor->Suspend(); |
| 87 m_suspended = true; |
| 88 } |
| 89 |
| 90 void SensorProxy::resume() |
| 91 { |
| 92 DCHECK(isInitialized()); |
| 93 if (!m_suspended) |
| 94 return; |
| 95 |
| 96 m_sensor->Resume(); |
| 97 m_suspended = false; |
| 98 } |
| 99 |
79 void SensorProxy::updateInternalReading() | 100 void SensorProxy::updateInternalReading() |
80 { | 101 { |
81 DCHECK(isInitialized()); | 102 DCHECK(isInitialized()); |
82 Reading* reading = static_cast<Reading*>(m_sharedBuffer.get()); | 103 Reading* reading = static_cast<Reading*>(m_sharedBuffer.get()); |
83 m_reading = *reading; | 104 m_reading = *reading; |
84 } | 105 } |
85 | 106 |
86 void SensorProxy::RaiseError() | 107 void SensorProxy::RaiseError() |
87 { | 108 { |
88 handleSensorError(); | 109 handleSensorError(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 handleSensorError(); | 146 handleSensorError(); |
126 return; | 147 return; |
127 } | 148 } |
128 | 149 |
129 m_state = Initialized; | 150 m_state = Initialized; |
130 for (Observer* observer : m_observers) | 151 for (Observer* observer : m_observers) |
131 observer->onSensorInitialized(); | 152 observer->onSensorInitialized(); |
132 } | 153 } |
133 | 154 |
134 } // namespace blink | 155 } // namespace blink |
OLD | NEW |