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

Side by Side Diff: third_party/WebKit/Source/modules/sensor/SensorProviderProxy.cpp

Issue 2121313002: [sensors] Generic Sensors Framework blink side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sensors_mojo_interfaces
Patch Set: Rebased 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 #include "modules/sensor/SensorProviderProxy.h"
6
7 #include "core/frame/LocalFrame.h"
8 #include "modules/sensor/SensorProxy.h"
9 #include "platform/mojo/MojoHelper.h"
10 #include "public/platform/InterfaceProvider.h"
11
12 using namespace device::mojom::blink;
13
14 namespace blink {
15
16 const char SensorProviderProxy::s_supplementKey[] = "SensorProvider";
17
18 // SensorProviderProxy
19 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame)
20 : PageVisibilityObserver(frame->document() ? frame->document()->page() : nul lptr)
21 , m_frame(frame)
22 {
23 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider));
24 m_sensorProvider.set_connection_error_handler(convertToBaseCallback(WTF::bin d(&SensorProviderProxy::handleSensorError, wrapWeakPersistent(this))));
25 }
26
27 SensorProviderProxy* SensorProviderProxy::getOrCreateForFrame(LocalFrame* frame)
28 {
29 DCHECK(frame);
30 SensorProviderProxy* result = static_cast<SensorProviderProxy*>(Supplement<L ocalFrame>::from(*frame, s_supplementKey));
31 if (!result) {
32 result = new SensorProviderProxy(frame);
33 Supplement<LocalFrame>::provideTo(*frame, s_supplementKey, result);
34 }
35 return result;
36 }
37
38 SensorProviderProxy::~SensorProviderProxy()
39 {
40 }
41
42 DEFINE_TRACE(SensorProviderProxy)
43 {
44 visitor->trace(m_sensors);
45 visitor->trace(m_frame);
46 PageVisibilityObserver::trace(visitor);
47 Supplement<LocalFrame>::trace(visitor);
48 }
49
50 void SensorProviderProxy::removeSensor(SensorProxy* sensor)
51 {
52 if (m_sensors.contains(sensor))
timvolodine 2016/08/25 17:52:32 if think you could just .remove() without contains
Mikhail 2016/08/26 16:42:42 Indeed, thanks for pointing out!
53 m_sensors.remove(sensor);
54 }
55
56 SensorProxy* SensorProviderProxy::getOrCreateSensor(device::mojom::blink::Sensor Type type)
57 {
58 for (SensorProxy* sensor : m_sensors) {
59 if (sensor->type() == type)
60 return sensor;
61 }
62 SensorProxy* sensor = new SensorProxy(type, this);
63 m_sensors.add(sensor);
64
65 return sensor;
66 }
67
68 void SensorProviderProxy::handleSensorError()
timvolodine 2016/08/25 17:52:32 when does this happen? slightly confused with Sens
Mikhail 2016/08/26 16:42:41 on IPC connection problems or if the browser-side
69 {
70 SensorsSet copy(m_sensors);
71 for (SensorProxy* sensor : copy) {
72 // All sensors are invalidated.
73 sensor->handleSensorError();
74 }
75 DCHECK(m_sensors.isEmpty());
76 if (m_frame)
77 m_frame->removeSupplement(s_supplementKey);
78 }
79
80 void SensorProviderProxy::pageVisibilityChanged()
81 {
82 if (!m_frame)
83 return;
84
85 Page* page = m_frame->document()->page();
86 DCHECK(page);
87
88 if (page->visibilityState() != PageVisibilityStateVisible) {
89 for (SensorProxy* sensor : m_sensors)
timvolodine 2016/08/25 17:52:32 but Sensor is also listening to page visibility..
Mikhail 2016/08/26 16:42:42 We could propagate this call from here to sensors
timvolodine 2016/09/01 19:02:05 what I meant is to just suspend() in the Sensor cl
Mikhail 2016/09/02 08:23:43 That would work, but since there can be multiple S
timvolodine 2016/09/02 19:41:28 not sure why this would result in more IPCs? would
Mikhail 2016/09/05 10:26:27 All the JS Sensor instances of the same type withi
90 sensor->suspend();
91 } else {
92 for (SensorProxy* sensor : m_sensors)
93 sensor->resume();
94 }
95 }
96
97 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698