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

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

Issue 2529343002: [sensors] Fix flakiness in generic sensors tests (Closed)
Patch Set: Created 4 years 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 "modules/sensor/SensorReading.h" 8 #include "modules/sensor/SensorReading.h"
9 #include "platform/mojo/MojoHelper.h" 9 #include "platform/mojo/MojoHelper.h"
10 #include "public/platform/InterfaceProvider.h" 10 #include "public/platform/InterfaceProvider.h"
11 #include "public/platform/Platform.h" 11 #include "public/platform/Platform.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 // SensorProviderProxy 15 // SensorProviderProxy
16 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { 16 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) {
17 initializeSensorProviderIfNeeded(frame);
18 }
19
20 void SensorProviderProxy::initializeSensorProviderIfNeeded(LocalFrame* frame) {
21 if (m_sensorProvider)
22 return;
23
17 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider)); 24 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider));
18 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( 25 m_sensorProvider.set_connection_error_handler(convertToBaseCallback(
19 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, 26 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError,
20 wrapWeakPersistent(this)))); 27 wrapWeakPersistent(this))));
21 } 28 }
22 29
23 const char* SensorProviderProxy::supplementName() { 30 const char* SensorProviderProxy::supplementName() {
24 return "SensorProvider"; 31 return "SensorProvider";
25 } 32 }
26 33
27 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { 34 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) {
28 DCHECK(frame); 35 DCHECK(frame);
29 SensorProviderProxy* result = static_cast<SensorProviderProxy*>( 36 SensorProviderProxy* result = static_cast<SensorProviderProxy*>(
30 Supplement<LocalFrame>::from(*frame, supplementName())); 37 Supplement<LocalFrame>::from(*frame, supplementName()));
31 if (!result) { 38 if (!result) {
32 result = new SensorProviderProxy(frame); 39 result = new SensorProviderProxy(frame);
33 Supplement<LocalFrame>::provideTo(*frame, supplementName(), result); 40 Supplement<LocalFrame>::provideTo(*frame, supplementName(), result);
41 } else {
42 result->initializeSensorProviderIfNeeded(frame);
Mikhail 2016/11/28 10:42:51 maybe split methods, like "isInitialized() const"
shalamov 2016/11/28 12:50:54 Done.
34 } 43 }
35 return result; 44 return result;
36 } 45 }
37 46
38 SensorProviderProxy::~SensorProviderProxy() {} 47 SensorProviderProxy::~SensorProviderProxy() {}
39 48
40 DEFINE_TRACE(SensorProviderProxy) { 49 DEFINE_TRACE(SensorProviderProxy) {
41 visitor->trace(m_sensorProxies); 50 visitor->trace(m_sensorProxies);
42 Supplement<LocalFrame>::trace(visitor); 51 Supplement<LocalFrame>::trace(visitor);
43 } 52 }
(...skipping 15 matching lines...) Expand all
59 device::mojom::blink::SensorType type) { 68 device::mojom::blink::SensorType type) {
60 for (SensorProxy* sensor : m_sensorProxies) { 69 for (SensorProxy* sensor : m_sensorProxies) {
61 // TODO(Mikhail) : Hash sensors by type for efficiency. 70 // TODO(Mikhail) : Hash sensors by type for efficiency.
62 if (sensor->type() == type) 71 if (sensor->type() == type)
63 return sensor; 72 return sensor;
64 } 73 }
65 74
66 return nullptr; 75 return nullptr;
67 } 76 }
68 77
78 device::mojom::blink::SensorProvider* SensorProviderProxy::getSensorProvider()
Mikhail 2016/11/28 10:42:51 why move it here (and rename)? IMO it's fine to ke
shalamov 2016/11/28 12:50:54 Wanted to make lazy getter, but then noticed that
79 const {
80 return m_sensorProvider.get();
81 }
82
69 void SensorProviderProxy::onSensorProviderConnectionError() { 83 void SensorProviderProxy::onSensorProviderConnectionError() {
70 if (!Platform::current()) { 84 if (!Platform::current()) {
71 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. 85 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed.
72 return; 86 return;
73 } 87 }
74 88
75 m_sensorProvider.reset(); 89 m_sensorProvider.reset();
76 for (SensorProxy* sensor : m_sensorProxies) 90 for (SensorProxy* sensor : m_sensorProxies)
77 sensor->handleSensorError(); 91 sensor->handleSensorError();
78 } 92 }
79 93
80 } // namespace blink 94 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698