class ProjectContextFactory

Defined at line 41 of file ../../third_party/cobalt/src/logger/project_context_factory.h

A ProjectContextFactory is used in a Cobalt client application in order

to obtain one or more ProjectContexts based on a given a CobaltRegistry.

First construct a ProjectContextFactory by giving it the bytes of

a serialized CobaltRegistry. The bytes will be deserialized and the

factory will then have an instance of CobaltRegistry.

The factory's CobaltRegistry may be in one of the following states:

- Invalid: The bytes could not be successfully deserialized.

- single-project

- multi-project

Invoke the status methods is_valid(), is_single_project()

to determine which state the factory's CobaltRegistry is in.

Depending on which state the factory's CobaltRegistry is in, invoke one

of the New*() or Take*() methods to retrieve a new ProjectContext().

Important: Pay attention to the notes on each method regarding the

requirement that this ProjectContextFactory remain alive. In some cases,

the returned ProjectContext contains a poiner into the CobaltRegistry

owned by this ProjectContextFactory and so the factory must not

be destructed until after the ProjectContext is no longer being used.

Public Methods

std::unique_ptr<ProjectContextFactory> CreateFromCobaltRegistryBase64 (const std::string & cobalt_registry_base64)

Constructs and returns an instance of ProjectContextFactory whose

CobaltRegistry is obtained by Base64 decoding and then deserializing

|cobalt_registry_base64|, which should contain the Base64 encoding of the

bytes of a serialized CobaltRegistry.

Returns nullptr to indicate that the Base64 decoding failed.

If a non-nullptr is returned invoke is_valid() to determine if

the parsing succeeded and the resulting CobaltRegistry is valid.

void ProjectContextFactory (const std::string & cobalt_registry_bytes)

Constructs a ProjectContextFactory whose CobaltRegistry is obtained

by parsing |cobalt_registry_bytes|. Invoke is_valid() to determine

if the parsing succeeded and the resulting CobaltRegistry is valid.

void ProjectContextFactory (util::NotNullUniquePtr<CobaltRegistry> cobalt_registry)

Constructs a ProjectContextFactory containing the given CobaltRegistry.

Invoke is_valid() to determine if the CobbaltRegistry is valid

std::unique_ptr<ProjectContext> NewProjectContext (lib::ProjectIdentifier project)

Returns a ProjectContext for the project with the given

(customer_id, project_id), if the factory's CobaltRegistry is valid and

contains that project. Returns nullptr otherwise.

Important: The returned ProjectContext contains a pointer into this

factory's CobaltRegistry. This ProjectContextFactory must remain alive as

long as the returned ProjectContext is being used.

std::vector<lib::ProjectIdentifier> ListProjects ()

ListProjects returns a list of tuples of the form (customer_id, project_id) for all of the

projects in the registry.

std::unique_ptr<ProjectContext> TakeSingleProjectContext ()

If is_single_project() is true, then this returns a

ProjectContext for the unique Cobalt project contained in the factory's

CobaltRegistry and removes the corresponding data from the registry,

leaving this ProjectContextFactory invalid. Returns nullptr otherwise.

Note: The returned ProjectContext does *not* contain a pointer into

this factory's CobaltRegistry because the appropriate data is removed

from the CobaltRegistry and is now owned by the ProjectContext. If nullptr

is not returned then this ProjectContextFactory becomes invalid and

shoud be discarded.

bool is_valid ()

Returns true if the factory's CobaltRegistry exists (meaning we were

able to parse the |cobalt_regsitry_bytes| passed to the constructor)

and is non-empty.

Defined at line 66 of file ../../third_party/cobalt/src/logger/project_context_factory.h

bool is_single_project ()

Returns true if the factory's CobaltRegistry is valid and contains

a single project.

Defined at line 70 of file ../../third_party/cobalt/src/logger/project_context_factory.h