blob: 853b934adff7bc63d04914f632040b3c9d1c702d [file] [log] [blame]
// 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.
#ifndef SensorProviderProxy_h
#define SensorProviderProxy_h
#include "core/frame/LocalFrame.h"
#include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
#include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
namespace blink {
class SensorProxy;
// This class wraps 'SensorProvider' mojo interface and it manages
// 'SensorProxy' instances.
class SensorProviderProxy final
: public GarbageCollectedFinalized<SensorProviderProxy>,
public Supplement<LocalFrame> {
USING_GARBAGE_COLLECTED_MIXIN(SensorProviderProxy);
WTF_MAKE_NONCOPYABLE(SensorProviderProxy);
public:
static SensorProviderProxy* From(LocalFrame*);
~SensorProviderProxy();
SensorProxy* CreateSensorProxy(device::mojom::blink::SensorType, Page*);
SensorProxy* GetSensorProxy(device::mojom::blink::SensorType);
DECLARE_VIRTUAL_TRACE();
private:
friend class SensorProxy; // To call getSensorProvider().
explicit SensorProviderProxy(LocalFrame&);
static const char* SupplementName();
void InitializeIfNeeded();
bool IsInitialized() const { return sensor_provider_; }
device::mojom::blink::SensorProvider* GetSensorProvider() const {
return sensor_provider_.get();
}
void OnSensorProviderConnectionError();
using SensorsSet = HeapHashSet<WeakMember<SensorProxy>>;
SensorsSet sensor_proxies_;
device::mojom::blink::SensorProviderPtr sensor_provider_;
};
} // namespace blink
#endif // SensorProviderProxy_h