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

Side by Side Diff: third_party/WebKit/Source/modules/sensor/SensorProxy.h

Issue 2472403002: [Sensors] Align sensor reading attribute implementation with the specification (Closed)
Patch Set: Created 4 years, 1 month 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 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 #ifndef SensorProxy_h 5 #ifndef SensorProxy_h
6 #define SensorProxy_h 6 #define SensorProxy_h
7 7
8 #include "core/dom/ExceptionCode.h" 8 #include "core/dom/ExceptionCode.h"
9 #include "device/generic_sensor/public/cpp/sensor_reading.h" 9 #include "device/generic_sensor/public/cpp/sensor_reading.h"
10 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" 10 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
11 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" 11 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h"
12 #include "mojo/public/cpp/bindings/binding.h" 12 #include "mojo/public/cpp/bindings/binding.h"
13 #include "platform/Supplementable.h" 13 #include "platform/Supplementable.h"
14 #include "platform/heap/Handle.h" 14 #include "platform/heap/Handle.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 class SensorProviderProxy; 18 class SensorProviderProxy;
19 class SensorReading;
20 class SensorReadingFactory;
19 21
20 // This class wraps 'Sensor' mojo interface and used by multiple 22 // This class wraps 'Sensor' mojo interface and used by multiple
21 // JS sensor instances of the same type (within a single frame). 23 // JS sensor instances of the same type (within a single frame).
22 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, 24 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>,
23 public device::mojom::blink::SensorClient { 25 public device::mojom::blink::SensorClient {
24 USING_PRE_FINALIZER(SensorProxy, dispose); 26 USING_PRE_FINALIZER(SensorProxy, dispose);
25 WTF_MAKE_NONCOPYABLE(SensorProxy); 27 WTF_MAKE_NONCOPYABLE(SensorProxy);
26 28
27 public: 29 public:
28 class Observer : public GarbageCollectedMixin { 30 class Observer : public GarbageCollectedMixin {
(...skipping 25 matching lines...) Expand all
54 std::unique_ptr<Function<void(bool)>>); 56 std::unique_ptr<Function<void(bool)>>);
55 void removeConfiguration(device::mojom::blink::SensorConfigurationPtr, 57 void removeConfiguration(device::mojom::blink::SensorConfigurationPtr,
56 std::unique_ptr<Function<void(bool)>>); 58 std::unique_ptr<Function<void(bool)>>);
57 59
58 void suspend(); 60 void suspend();
59 void resume(); 61 void resume();
60 62
61 device::mojom::blink::SensorType type() const { return m_type; } 63 device::mojom::blink::SensorType type() const { return m_type; }
62 device::mojom::blink::ReportingMode reportingMode() const { return m_mode; } 64 device::mojom::blink::ReportingMode reportingMode() const { return m_mode; }
63 65
64 using Reading = device::SensorReading; 66 // The |SensorReading| instance which is shared between sensor instances
65 67 // of the same type.
66 const Reading& reading() const { return m_reading; } 68 // Note: the returned value is reset after updateSensorReading() call.
69 SensorReading* sensorReading() const { return m_reading; }
67 70
68 const device::mojom::blink::SensorConfiguration* defaultConfig() const; 71 const device::mojom::blink::SensorConfiguration* defaultConfig() const;
69 72
70 // Updates internal reading from shared buffer. 73 // Updates sensor reading from shared buffer.
71 void updateInternalReading(); 74 void updateSensorReading();
72 75
73 DECLARE_VIRTUAL_TRACE(); 76 DECLARE_VIRTUAL_TRACE();
74 77
75 private: 78 private:
76 friend class SensorProviderProxy; 79 friend class SensorProviderProxy;
77 SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*); 80 SensorProxy(device::mojom::blink::SensorType,
81 SensorProviderProxy*,
82 std::unique_ptr<SensorReadingFactory>);
78 83
79 // device::mojom::blink::SensorClient overrides. 84 // device::mojom::blink::SensorClient overrides.
80 void RaiseError() override; 85 void RaiseError() override;
81 void SensorReadingChanged() override; 86 void SensorReadingChanged() override;
82 87
83 // Generic handler for a fatal error. 88 // Generic handler for a fatal error.
84 void handleSensorError(ExceptionCode = UnknownError, 89 void handleSensorError(ExceptionCode = UnknownError,
85 const String& sanitizedMessage = String(), 90 const String& sanitizedMessage = String(),
86 const String& unsanitizedMessage = String()); 91 const String& unsanitizedMessage = String());
87 92
88 void onSensorCreated(device::mojom::blink::SensorInitParamsPtr, 93 void onSensorCreated(device::mojom::blink::SensorInitParamsPtr,
89 device::mojom::blink::SensorClientRequest); 94 device::mojom::blink::SensorClientRequest);
90 95
91 bool tryReadFromBuffer(); 96 bool tryReadFromBuffer(device::SensorReading& result);
92 97
93 device::mojom::blink::SensorType m_type; 98 device::mojom::blink::SensorType m_type;
94 device::mojom::blink::ReportingMode m_mode; 99 device::mojom::blink::ReportingMode m_mode;
95 Member<SensorProviderProxy> m_provider; 100 Member<SensorProviderProxy> m_provider;
96 using ObserversSet = HeapHashSet<WeakMember<Observer>>; 101 using ObserversSet = HeapHashSet<WeakMember<Observer>>;
97 ObserversSet m_observers; 102 ObserversSet m_observers;
98 103
99 device::mojom::blink::SensorPtr m_sensor; 104 device::mojom::blink::SensorPtr m_sensor;
100 device::mojom::blink::SensorConfigurationPtr m_defaultConfig; 105 device::mojom::blink::SensorConfigurationPtr m_defaultConfig;
101 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding; 106 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding;
102 107
103 enum State { Uninitialized, Initializing, Initialized }; 108 enum State { Uninitialized, Initializing, Initialized };
104 State m_state; 109 State m_state;
105 mojo::ScopedSharedBufferHandle m_sharedBufferHandle; 110 mojo::ScopedSharedBufferHandle m_sharedBufferHandle;
106 mojo::ScopedSharedBufferMapping m_sharedBuffer; 111 mojo::ScopedSharedBufferMapping m_sharedBuffer;
107 Reading m_reading;
108 bool m_suspended; 112 bool m_suspended;
113 Member<SensorReading> m_reading;
114 std::unique_ptr<SensorReadingFactory> m_readingFactory;
115
109 using ReadingBuffer = device::SensorReadingSharedBuffer; 116 using ReadingBuffer = device::SensorReadingSharedBuffer;
110 static_assert( 117 static_assert(
111 sizeof(ReadingBuffer) == 118 sizeof(ReadingBuffer) ==
112 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, 119 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests,
113 "Check reading buffer size for tests"); 120 "Check reading buffer size for tests");
114 }; 121 };
115 122
116 } // namespace blink 123 } // namespace blink
117 124
118 #endif // SensorProxy_h 125 #endif // SensorProxy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698