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

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 Tim. Removed the default sensor configuration management (to be added with a separate… 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
66 // Updates internal reading from shared buffer.
67 void updateReading();
68
69 DECLARE_VIRTUAL_TRACE();
70
71 private:
72 friend class SensorProviderProxy;
73 SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*);
74
75 // device::mojom::blink::SensorClient overrides.
76 void RaiseError() override;
77 void SensorReadingChanged() override;
78
79 void handleSensorError();
80
81 void onSensorCreated(device::mojom::blink::SensorReadBufferPtr, device::mojo m::blink::SensorClientRequest);
82
83 device::mojom::blink::SensorType m_type;
84 device::mojom::blink::ReportingMode m_mode;
85 Member<SensorProviderProxy> m_provider;
86 using ObserversSet = HeapHashSet<WeakMember<Observer>>;
87 ObserversSet m_observers;
88
89 device::mojom::blink::SensorPtr m_sensor;
90 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding;
91 enum State {
92 Uninitialized,
93 Initializing,
94 Initialized
95 };
96 State m_state;
97 mojo::ScopedSharedBufferHandle m_sharedBufferHandle;
98 mojo::ScopedSharedBufferMapping m_sharedBuffer;
99 Reading m_reading;
100 };
101
102 } // namespace blink
103
104 #endif // SensorProxy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698