class ShippingManager

Defined at line 51 of file ../../third_party/cobalt/src/uploader/shipping_manager.h

ShippingManager is the client-side component of Cobalt responsible for

periodically sending Envelopes, encrypted to the Shuffler, from the device

to the server. In Cobalt, Observations are accumulated in the Observation

Store. The ShippingManager maintains a background thread that periodically

reads Envelopes from the Observation Store, encrypts the Envelopes, and

sends them to Cobalt's backend server. ShippingManager also performs

expedited off-schedule sends when too much unsent Observation data has

accumulated. A client may also explicitly request an expedited send.

ShippingManager is an abstract class. Most of the logic is contained in

ShippingManager itself but a subclass must be defined for each type of

backend server to which we need to ship. This allows us to switch to

a different type of backend server without changing this class.

Usage: Construct an instance of a concrete subclass of ShippingManager,

invoke Start() once. Whenever an observation is added to the

ObservationStore, call NotifyObservationsAdded() which allows ShippingManager

to check if it needs to send early. Optionally invoke RequestSendSoon() to

expedite a send operation.

Usually a single ShippingManager will be constructed for a device.

Public Methods

void ShippingManager (const UploadScheduler & upload_scheduler, observation_store::ObservationStore & observation_store, util::EncryptedMessageMaker * encrypt_to_analyzer)

Constructor

upload_scheduler: This controls the ShippingManager's behavior with

respect to scheduling sends.

observation_store: The ObservationStore from which Envelopes will be

retrieved.

encrypt_to_analyzer: An EncryptedMessageMaker that will be used to encrypt the observations in

an envelope before sending. TODO(https://fxbug.dev/278924679): add nullptr check once storing

unencrypted observations is enabled.

void ~ShippingManager ()

The destructor will stop the worker thread and wait for it to stop

before exiting.

void Start ()

Starts the worker thread. Destruct this instance to stop the worker thread.

This method must be invoked exactly once.

void NotifyObservationsAdded ()

Invoke this each time an Observation is added to the ObservationStore.

void RequestSendSoon ()

Register a request with the ShippingManager for an expedited send. The

ShippingManager's worker thread will try to send all of the accumulated,

unsent Observations as soon as possible but not sooner than |min_interval|

seconds after the previous send operation has completed.

void RequestSendSoon (const SendCallback & send_callback)

A version of RequestSendSoon() that provides feedback about the send.

|send_callback| will be invoked with the result of the requested send

attempt. More precisely, send_callback will be invoked after the

ShippingManager has attempted to send all of the Observations that were

added to the ObservationStore. It will be invoked with true if all such

Observations were succesfully sent. It will be invoked with false if some

Observations were not able to be sent, but the status of any particular

Observation may not be determined. This is useful mainly in tests.

void WaitUntilIdle (std::chrono::seconds max_wait)

Blocks for |max_wait| seconds or until the worker thread has successfully

sent all previously added Observations and is idle, waiting for more

Observations to be added. This method is most useful if it can be arranged

that there are no concurrent invocations of NotifyObservationsAdded() (for

example in a test) because such concurrent invocations may cause the idle

state to never be entered.

void WaitUntilWorkerWaiting (std::chrono::seconds max_wait)

Blocks for |max_wait| seconds or until the worker thread is in the state

where there are Observations to be sent but it is waiting for the

next scheduled send time. This method is most useful if it can be

arranged that there are no concurrent invocations of RequestSendSoon()

(for example in a test) because such concurrent invocations might cause

that state to never be entered.

size_t num_send_attempts ()

These diagnostic stats are mostly useful in a testing environment but

may possibly prove useful in production also.

size_t num_failed_attempts ()
cobalt::Status last_send_status ()
void Disable (bool is_disabled)

Disable allows enabling/disabling the ShippingManager. When the ShippingManager is disabled,

all calls to SendAllEnvelopes will return immediately without uploading any data.

void ResetInternalMetrics (logger::InternalMetrics * internal_metrics)

Resets the internal metrics for the ShippingManager and the ClearcutUploader to use the

provided logger.

Impl impl ()

Returns some information about which implementation of ShippingManager

this is an instance of.

Defined at line 136 of file ../../third_party/cobalt/src/uploader/shipping_manager.h

Enumerations

enum Impl
Name Value
OTHER 0
CLEARCUTV1 1

Defined at line 127 of file ../../third_party/cobalt/src/uploader/shipping_manager.h

Friends

class LocalShippingManager
class ClearcutV1ShippingManager