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

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: build fix for win 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 device::mojom::blink::SensorType type() const { return m_type; }
53 device::mojom::blink::ReportingMode reportingMode() const { return m_mode; }
54
55 struct Reading {
56 double timestamp;
57 double reading[3];
58 };
59 static_assert(sizeof(Reading) == device::mojom::blink::SensorReadBuffer::kRe adBufferSize, "Check reading size");
60
61 const Reading& reading() const { return m_reading; }
62
63 // Updates internal reading from shared buffer.
64 void updateInternalReading();
65
66 DECLARE_VIRTUAL_TRACE();
67
68 private:
69 friend class SensorProviderProxy;
70 SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*);
71
72 // device::mojom::blink::SensorClient overrides.
73 void RaiseError() override;
74 void SensorReadingChanged() override;
75
76 // Generic handler for a fatal error.
77 void handleSensorError();
78
79 void onSensorCreated(device::mojom::blink::SensorReadBufferPtr, device::mojo m::blink::SensorClientRequest);
80
81 device::mojom::blink::SensorType m_type;
82 device::mojom::blink::ReportingMode m_mode;
83 Member<SensorProviderProxy> m_provider;
84 using ObserversSet = HeapHashSet<WeakMember<Observer>>;
85 ObserversSet m_observers;
86
87 device::mojom::blink::SensorPtr m_sensor;
88 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding;
89 enum State {
90 Uninitialized,
91 Initializing,
92 Initialized
93 };
94 State m_state;
95 mojo::ScopedSharedBufferHandle m_sharedBufferHandle;
96 mojo::ScopedSharedBufferMapping m_sharedBuffer;
97 Reading m_reading;
98 };
99
100 } // namespace blink
101
102 #endif // SensorProxy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698