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

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: code rebase 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
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/SensorProviderProxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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->GetInterfaceProvider()->GetInterface( 23 Platform::Current()->GetConnector()->BindInterface(
23 mojo::MakeRequest(&sensor_provider_)); 24 device::mojom::blink::kServiceName, mojo::MakeRequest(&sensor_provider_));
24 sensor_provider_.set_connection_error_handler(ConvertToBaseCallback( 25 sensor_provider_.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* provider_proxy = static_cast<SensorProviderProxy*>( 37 SensorProviderProxy* provider_proxy = static_cast<SensorProviderProxy*>(
37 Supplement<LocalFrame>::From(*frame, SupplementName())); 38 Supplement<LocalFrame>::From(*frame, SupplementName()));
38 if (!provider_proxy) { 39 if (!provider_proxy) {
39 provider_proxy = new SensorProviderProxy(*frame); 40 provider_proxy = new SensorProviderProxy(*frame);
40 Supplement<LocalFrame>::ProvideTo(*frame, SupplementName(), provider_proxy); 41 Supplement<LocalFrame>::ProvideTo(*frame, SupplementName(), provider_proxy);
41 } 42 }
42 provider_proxy->InitializeIfNeeded(frame); 43 provider_proxy->InitializeIfNeeded();
43 return provider_proxy; 44 return provider_proxy;
44 } 45 }
45 46
46 SensorProviderProxy::~SensorProviderProxy() {} 47 SensorProviderProxy::~SensorProviderProxy() {}
47 48
48 DEFINE_TRACE(SensorProviderProxy) { 49 DEFINE_TRACE(SensorProviderProxy) {
49 visitor->Trace(sensor_proxies_); 50 visitor->Trace(sensor_proxies_);
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 sensor_provider_.reset(); 77 sensor_provider_.reset();
77 for (SensorProxy* sensor : sensor_proxies_) 78 for (SensorProxy* sensor : sensor_proxies_)
78 sensor->HandleSensorError(); 79 sensor->HandleSensorError();
79 } 80 }
80 81
81 } // namespace blink 82 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/SensorProviderProxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698