PressureSourceProvider Class

The pressure sources of the device (https://w3c.github.io/compute-pressure/#dfn-pressure-source), read by the PressureObserver objects of the browsing contexts that share a BrowsingContextOptions (ComputePressureOptions.Provider). The default implementation returns the samples set by the application (PressureSourceProvider.SetSample), as the virtual pressure sources of WebDriver (https://w3c.github.io/compute-pressure/#virtual-pressure-source). Override PressureSourceProvider.IsSupported and PressureSourceProvider.GetSample to read another source, and call PressureSourceProvider.OnSampleChanged when a source reports a new sample.

public class PressureSourceProvider

Remarks

A provider can be shared by several browsing contexts, and used from any thread. While an observer requests a sample interval (sampleInterval), the latest sample is read again at that interval, as a platform collector samples the source at its sampling rate.

Constructors

NameDescription
PressureSourceProvider()

PressureSourceProvider()

ComputePressure.cs
public PressureSourceProvider()

No documentation is available.

Methods

NameDescription
GetSample(PressureSource)Returns the latest sample of the source (https://w3c.github.io/compute-pressure/#dfn-latest-sample), or null when it has no sample. The default implementation returns the sample set by PressureSourceProvider.SetSample. It is called on the thread of an event loop, and must not block it.
IsSupported(PressureSource)Returns whether the source can provide samples. The default implementation returns true, unless the source was made unsupported by PressureSourceProvider.SetSupported. The observers of an unsupported source are rejected with a NotSupportedError. It is called on the thread of an event loop, and must not block it.
OnSampleChanged(PressureSource)Reads the sample of the source again for the observers of the documents and the workers, which are called from a task when the state changed. It can be called from any thread.
SetSample(PressureSource, PressureSample?)Sets the latest sample of a source (null to remove it), returned by the default implementation of PressureSourceProvider.GetSample, then delivers it to the observers of the documents (PressureSourceProvider.OnSampleChanged).
SetSupported(PressureSource, bool)Sets whether the source can provide samples (see PressureSourceProvider.IsSupported). It applies to the next calls of observe().

GetSample(PressureSource)

ComputePressure.cs

Returns the latest sample of the source (https://w3c.github.io/compute-pressure/#dfn-latest-sample), or null when it has no sample. The default implementation returns the sample set by PressureSourceProvider.SetSample. It is called on the thread of an event loop, and must not block it.

public virtual PressureSample? GetSample(PressureSource source)

Parameters

source PressureSource
The source type.

Returns

PressureSample?

IsSupported(PressureSource)

ComputePressure.cs

Returns whether the source can provide samples. The default implementation returns true, unless the source was made unsupported by PressureSourceProvider.SetSupported. The observers of an unsupported source are rejected with a NotSupportedError. It is called on the thread of an event loop, and must not block it.

public virtual bool IsSupported(PressureSource source)

Parameters

source PressureSource
The source type.

Returns

bool

OnSampleChanged(PressureSource)

ComputePressure.cs

Reads the sample of the source again for the observers of the documents and the workers, which are called from a task when the state changed. It can be called from any thread.

protected void OnSampleChanged(PressureSource source)

Parameters

source PressureSource
The source type that reported a new sample.

SetSample(PressureSource, PressureSample?)

ComputePressure.cs

Sets the latest sample of a source (null to remove it), returned by the default implementation of PressureSourceProvider.GetSample, then delivers it to the observers of the documents (PressureSourceProvider.OnSampleChanged).

public void SetSample(PressureSource source, PressureSample? sample)

Parameters

source PressureSource
The source type.
sample PressureSample?
The new sample, or null.

SetSupported(PressureSource, bool)

ComputePressure.cs

Sets whether the source can provide samples (see PressureSourceProvider.IsSupported). It applies to the next calls of observe().

public void SetSupported(PressureSource source, bool supported)

Parameters

source PressureSource
The source type.
supported bool
Whether the source can provide samples.