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 |