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 PressureSourceProviderRemarks
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
| Name | Description |
|---|---|
| PressureSourceProvider() |
PressureSourceProvider()
ComputePressure.cspublic PressureSourceProvider()No documentation is available.
Methods
| Name | Description |
|---|---|
| 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.csReturns 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)IsSupported(PressureSource)
ComputePressure.csReturns 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)OnSampleChanged(PressureSource)
ComputePressure.csReads 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
sourcePressureSource- The source type that reported a new sample.
SetSample(PressureSource, PressureSample?)
ComputePressure.csSets 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
sourcePressureSource- The source type.
samplePressureSample?- The new sample, or null.
SetSupported(PressureSource, bool)
ComputePressure.csSets 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
sourcePressureSource- The source type.
supportedbool- Whether the source can provide samples.