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

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

Issue 2121313002: [sensors] Generic Sensors Framework blink side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sensors_mojo_interfaces
Patch Set: Comments from Riju Created 4 years, 3 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SensorProxy_h
6 #define SensorProxy_h
7
8 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
9 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h"
10 #include "mojo/public/cpp/bindings/binding.h"
11 #include "platform/Supplementable.h"
12 #include "platform/heap/Handle.h"
13
14 namespace blink {
15
16 class SensorProviderProxy;
17
18 // This class wraps 'Sensor' mojo interface and used by multiple
19 // JS sensor instances of the same type (within a single frame).
20 class SensorProxy final
21 : public GarbageCollectedFinalized<SensorProxy>
22 , public device::mojom::blink::SensorClient {
23 USING_PRE_FINALIZER(SensorProxy, dispose);
24 WTF_MAKE_NONCOPYABLE(SensorProxy);
25 public:
26 class Observer : public GarbageCollectedMixin {
27 public:
28 // Has valid 'Sensor' binding, {add, remove}Configuration()
29 // methods can be called.
30 virtual void onSensorInitialized() {}
31 // Platfrom sensort reading has changed (for 'ONCHANGE' reporting mode).
32 virtual void onSensorReadingChanged() {}
33 // An error has occurred.
34 virtual void onSensorError() {}
35 };
36
37 ~SensorProxy();
38
39 void dispose();
40
41 void addObserver(Observer*);
42 void removeObserver(Observer*);
43
44 void initialize();
45
46 bool isInitializing() const { return m_state == Initializing; }
47 bool isInitialized() const { return m_state == Initialized; }
48
49 void addConfiguration(device::mojom::blink::SensorConfigurationPtr, std::uni que_ptr<Function<void(bool)>>);
50 void removeConfiguration(device::mojom::blink::SensorConfigurationPtr, std:: unique_ptr<Function<void(bool)>>);
51
52 void suspend();
53 void resume();
54
55 device::mojom::blink::SensorType type() const { return m_type; }
56 device::mojom::blink::ReportingMode reportingMode() const { return m_mode; }
57
58 struct Reading {
59 double timestamp;
60 double reading[3];
61 };
62 static_assert(sizeof(Reading) == device::mojom::blink::SensorReadBuffer::kRe adBufferSize, "Check reading size");
63
64 const Reading& reading() const { return m_reading; }
65 device::mojom::blink::SensorConfiguration* defaultConfiguration() const { re turn m_defaultConfiguration.get(); }
66
67 // Updates internal reading from shared buffer.
68 void updateReading();
69
70 DECLARE_VIRTUAL_TRACE();
71
72 private:
73 friend class SensorProviderProxy;
74 SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*);
75
76 // device::mojom::blink::SensorClient overrides.
77 void RaiseError() override;
78 void SensorReadingChanged() override;
79
80 void handleSensorError();
81
82 void onSensorCreated(device::mojom::blink::SensorReadBufferPtr, device::mojo m::blink::SensorClientRequest);
83 void onDefaultConfiguration(device::mojom::blink::SensorConfigurationPtr);
84
85 device::mojom::blink::SensorType m_type;
86 device::mojom::blink::ReportingMode m_mode;
87 Member<SensorProviderProxy> m_provider;
88 using ObserversSet = HeapHashSet<WeakMember<Observer>>;
89 ObserversSet m_observers;
90
91 device::mojom::blink::SensorPtr m_sensor;
92 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding;
93 enum State {
94 Uninitialized,
95 Initializing,
96 Initialized
97 };
98 State m_state;
99 mojo::ScopedSharedBufferHandle m_sharedBufferHandle;
100 mojo::ScopedSharedBufferMapping m_sharedBuffer;
101 device::mojom::blink::SensorConfigurationPtr m_defaultConfiguration;
102 Reading m_reading;
103 };
104
105 } // namespace blink
106
107 #endif // SensorProxy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698