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

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

Powered by Google App Engine
This is Rietveld 408576698