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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/sensor/SensorProviderProxy.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/SensorProviderProxy.cpp b/third_party/WebKit/Source/modules/sensor/SensorProviderProxy.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..023fa933661f83caea7045ecf9a3fa13c641cb6e
--- /dev/null
+++ b/third_party/WebKit/Source/modules/sensor/SensorProviderProxy.cpp
@@ -0,0 +1,67 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/sensor/SensorProviderProxy.h"
+
+#include "modules/sensor/SensorProxy.h"
+#include "platform/mojo/MojoHelper.h"
+#include "public/platform/InterfaceProvider.h"
+
+namespace blink {
+
+// SensorProviderProxy
+SensorProviderProxy::SensorProviderProxy(LocalFrame* frame)
+{
+ frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider));
+ m_sensorProvider.set_connection_error_handler(convertToBaseCallback(WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, wrapWeakPersistent(this))));
+}
+
+const char* SensorProviderProxy::supplementName()
+{
+ return "SensorProvider";
+}
+
+SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame)
+{
+ DCHECK(frame);
+ SensorProviderProxy* result = static_cast<SensorProviderProxy*>(Supplement<LocalFrame>::from(*frame, supplementName()));
+ if (!result) {
+ result = new SensorProviderProxy(frame);
+ Supplement<LocalFrame>::provideTo(*frame, supplementName(), result);
+ }
+ return result;
+}
+
+SensorProviderProxy::~SensorProviderProxy()
+{
+}
+
+DEFINE_TRACE(SensorProviderProxy)
+{
+ visitor->trace(m_sensors);
+ Supplement<LocalFrame>::trace(visitor);
+}
+
+SensorProxy* SensorProviderProxy::getOrCreateSensor(device::mojom::blink::SensorType type)
+{
+ for (SensorProxy* sensor : m_sensors) {
+ // TODO(Mikhail) : Hash sensors by type for efficiency.
+ if (sensor->type() == type)
+ return sensor;
+ }
+
+ SensorProxy* sensor = new SensorProxy(type, this);
+ m_sensors.add(sensor);
+
+ return sensor;
+}
+
+void SensorProviderProxy::onSensorProviderConnectionError()
+{
+ m_sensorProvider.reset();
+ for (SensorProxy* sensor : m_sensors)
+ sensor->handleSensorError();
+}
+
+} // namespace blink
« 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