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

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: Keeping mojo wrappers only + comments from haraken 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 namespace blink {
13
14 // SensorProviderProxy
15 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame)
16 {
17 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider));
18 m_sensorProvider.set_connection_error_handler(convertToBaseCallback(WTF::bin d(&SensorProviderProxy::onSensorProviderConnectionError, wrapWeakPersistent(this ))));
19 }
20
21 const char* SensorProviderProxy::supplementName()
22 {
23 return "SensorProvider";
24 }
25
26 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame)
27 {
28 DCHECK(frame);
29 SensorProviderProxy* result = static_cast<SensorProviderProxy*>(Supplement<L ocalFrame>::from(*frame, supplementName()));
30 if (!result) {
31 result = new SensorProviderProxy(frame);
32 Supplement<LocalFrame>::provideTo(*frame, supplementName(), result);
33 }
34 return result;
35 }
36
37 SensorProviderProxy::~SensorProviderProxy()
38 {
39 }
40
41 DEFINE_TRACE(SensorProviderProxy)
42 {
43 visitor->trace(m_sensors);
44 Supplement<LocalFrame>::trace(visitor);
45 }
46
47 SensorProxy* SensorProviderProxy::getOrCreateSensor(device::mojom::blink::Sensor Type type)
48 {
49 for (SensorProxy* sensor : m_sensors) {
50 // TODO(Mikhail) : Hash sensors by type for efficiency.
51 if (sensor->type() == type)
52 return sensor;
53 }
54
55 SensorProxy* sensor = new SensorProxy(type, this);
56 m_sensors.add(sensor);
57
58 return sensor;
59 }
60
61 void SensorProviderProxy::onSensorProviderConnectionError()
62 {
63 m_sensorProvider.reset();
64 for (SensorProxy* sensor : m_sensors)
65 sensor->handleSensorError();
66 }
67
68 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698