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

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

Issue 2698083007: Port device_generic_sensor to be hosted in Device Service. (Closed)
Patch Set: Port device_generic_sensor to be hosted in Device Service. Created 3 years, 8 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/sensor/SensorProviderProxy.h" 5 #include "modules/sensor/SensorProviderProxy.h"
6 6
7 #include "modules/sensor/SensorProxy.h" 7 #include "modules/sensor/SensorProxy.h"
8 #include "platform/mojo/MojoHelper.h" 8 #include "platform/mojo/MojoHelper.h"
9 #include "public/platform/InterfaceProvider.h"
10 #include "public/platform/Platform.h" 9 #include "public/platform/Platform.h"
10 #include "services/device/public/interfaces/constants.mojom-blink.h"
11 #include "services/service_manager/public/cpp/connector.h"
11 12
12 namespace blink { 13 namespace blink {
13 14
14 // SensorProviderProxy 15 // SensorProviderProxy
15 SensorProviderProxy::SensorProviderProxy(LocalFrame& frame) 16 SensorProviderProxy::SensorProviderProxy(LocalFrame& frame)
16 : Supplement<LocalFrame>(frame) {} 17 : Supplement<LocalFrame>(frame) {}
17 18
18 void SensorProviderProxy::initializeIfNeeded(LocalFrame* frame) { 19 void SensorProviderProxy::initializeIfNeeded() {
19 if (isInitialized()) 20 if (isInitialized())
20 return; 21 return;
21 22
22 frame->interfaceProvider()->getInterface( 23 Platform::current()->connector()->BindInterface(
blundell 2017/03/29 09:41:59 Just to sanity-check: This feature doesn't have la
ke.he 2017/03/29 10:05:11 It has, in LayoutTests/sensor/resources/. That's
23 mojo::MakeRequest(&m_sensorProvider)); 24 device::mojom::blink::kServiceName, mojo::MakeRequest(&m_sensorProvider));
24 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( 25 m_sensorProvider.set_connection_error_handler(convertToBaseCallback(
25 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, 26 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError,
26 wrapWeakPersistent(this)))); 27 wrapWeakPersistent(this))));
27 } 28 }
28 29
29 const char* SensorProviderProxy::supplementName() { 30 const char* SensorProviderProxy::supplementName() {
30 return "SensorProvider"; 31 return "SensorProvider";
31 } 32 }
32 33
33 // static 34 // static
34 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { 35 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) {
35 DCHECK(frame); 36 DCHECK(frame);
36 SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>( 37 SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>(
37 Supplement<LocalFrame>::from(*frame, supplementName())); 38 Supplement<LocalFrame>::from(*frame, supplementName()));
38 if (!providerProxy) { 39 if (!providerProxy) {
39 providerProxy = new SensorProviderProxy(*frame); 40 providerProxy = new SensorProviderProxy(*frame);
40 Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy); 41 Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy);
41 } 42 }
42 providerProxy->initializeIfNeeded(frame); 43 providerProxy->initializeIfNeeded();
43 return providerProxy; 44 return providerProxy;
44 } 45 }
45 46
46 SensorProviderProxy::~SensorProviderProxy() {} 47 SensorProviderProxy::~SensorProviderProxy() {}
47 48
48 DEFINE_TRACE(SensorProviderProxy) { 49 DEFINE_TRACE(SensorProviderProxy) {
49 visitor->trace(m_sensorProxies); 50 visitor->trace(m_sensorProxies);
50 Supplement<LocalFrame>::trace(visitor); 51 Supplement<LocalFrame>::trace(visitor);
51 } 52 }
52 53
(...skipping 19 matching lines...) Expand all
72 return nullptr; 73 return nullptr;
73 } 74 }
74 75
75 void SensorProviderProxy::onSensorProviderConnectionError() { 76 void SensorProviderProxy::onSensorProviderConnectionError() {
76 m_sensorProvider.reset(); 77 m_sensorProvider.reset();
77 for (SensorProxy* sensor : m_sensorProxies) 78 for (SensorProxy* sensor : m_sensorProxies)
78 sensor->handleSensorError(); 79 sensor->handleSensorError();
79 } 80 }
80 81
81 } // namespace blink 82 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698