class ObservationStore

Defined at line 88 of file ../../third_party/cobalt/src/observation_store/observation_store.h

ObservationStore is an abstract interface to an underlying store of encrypted observations and

their metadata. These are organized within the store into Envelopes. Individual (encrypted

observation, metadata) pairs are added one-at-a-time via the method StoreObservation(). These

pairs are pooled together and will eventually be combined into an Envelope. These Envelopes are

then collected into a list, and will be returned one-at-a-time from calls to

TakeNextEnvelopeHolder(). If there are no envelopes available to return, TakeNextEnvelopeHolder()

will return nullptr.

The EnvelopeHolders that are returned from this method should be treated as "owned" by the

caller. When the EnvelopeHolder is destroyed, its underlying data is also deleted. If the

underlying data should not be deleted (e.g. if the upload failed), the EnvelopeHolder should be

placed back into the ObservationStore using the ReturnEnvelopeHolder() method.

Protected Members

const size_t max_bytes_per_observation_
const size_t max_bytes_per_envelope_
const size_t max_bytes_total_
const size_t almost_full_threshold_
map num_obs_per_report_

Public Methods

void ObservationStore (size_t max_bytes_per_observation, size_t max_bytes_per_envelope, size_t max_bytes_total)

max_bytes_per_observation. StoreObservation() will return kObservationTooBig if the given

encrypted Observation's serialized size is bigger than this.

max_bytes_per_envelope. When pooling together observations into an Envelope, the

ObservationStore will try not to form envelopes larger than this size. This should be used to

avoid sending messages over HTTP that are too large.

max_bytes_total. This is the maximum size of the Observations in the store. If the size of the

accumulated Observation data reaches this value then ObservationStore will not accept any more

Observations: StoreObservation() will return kStoreFull, until enough observations are removed

from the store.

REQUIRED:

0

<

= max_bytes_per_observation

<

= max_bytes_per_envelope

<

= max_bytes_total

0

<

= max_bytes_per_envelope

void ~ObservationStore ()

Defined at line 156 of file ../../third_party/cobalt/src/observation_store/observation_store.h

void ObservationStore (const ObservationStore & )

Make ObservationStoreWriterInterface move-only

Defined at line 159 of file ../../third_party/cobalt/src/observation_store/observation_store.h

Status StoreObservation (std::unique_ptr<StoredObservation> observation, std::unique_ptr<ObservationMetadata> metadata)

Adds the given (StoredObservation, ObservationMetadata) pair into the store. If this causes the

pool of observations to exceed max_bytes_per_envelope, then the ObservationStore will construct

an EnvelopeHolder to be returned from TakeNextEnvelopeHolder().

N.B. If the store has been disabled (IsDisabled() returns true) this method will always return

kOk, even though the observation has not been stored.

std::unique_ptr<EnvelopeHolder> TakeNextEnvelopeHolder ()

Returns the next EnvelopeHolder from the list of EnvelopeHolders in the

store. If there are no more EnvelopeHolders available, this will return

nullptr. A given EnvelopeHolder will only be returned from this function

*once* unless it is subsequently returned using ReturnEnvelopeHolder.

void ReturnEnvelopeHolder (std::unique_ptr<EnvelopeHolder> envelope)

ReturnEnvelopeHolder takes an EnvelopeHolder and adds it back to the store

so that it may be returned by a later call to TakeNextEnvelopeHolder(). Use

this when an envelope failed to upload, so the underlying data should not

be deleted.

void ResetInternalMetrics (logger::InternalMetrics * internal_metrics)

Resets the internal metrics to use the provided logger.

const logger::InternalMetrics * internal_metrics ()
bool IsAlmostFull ()

Returns true when the size of the data in the ObservationStore exceeds 60%

of max_bytes_total.

size_t Size ()

Returns an approximation of the size of all the data in the store.

bool Empty ()

Returns whether or not the store is entirely empty.

uint64_t num_observations_added ()

Returns the number of Observations that have been added to the

ObservationStore.

std::vector<uint64_t> num_observations_added_for_reports (const std::vector<lib::ReportIdentifier> & report_specs)

Returns a vector containing the number of Observations that have been added

to the ObservationStore for each specified report.

void ResetObservationCounter ()

Resets the count of Observations that have been added to the

ObservationStore.

void Disable (bool is_disabled)

Disable allows enabling/disabling the ObservationStore. When the store is disabled,

StoreObservation() will return kOk but the observation will not be stored.

void DeleteData ()

DeleteData removes all stored Observations from the device. After this method is called, a call

to Size() or TakeNextEnvelopeHolder() will return 0 and nullptr respectively.

ObservationStore & operator= (const ObservationStore & )

Defined at line 160 of file ../../third_party/cobalt/src/observation_store/observation_store.h

bool IsDisabled ()

IsDisabled returns true if the ObservationStore is disabled and should ignore incoming

observations, by returning kOk and not storing the data.

Defined at line 219 of file ../../third_party/cobalt/src/observation_store/observation_store.h

Records