chromium/components/update_client/component.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/update_client/component.h"

#include <memory>
#include <tuple>
#include <utility>
#include <vector>

#include "base/check.h"
#include "base/check_op.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "components/update_client/action_runner.h"
#include "components/update_client/configurator.h"
#include "components/update_client/network.h"
#include "components/update_client/op_download.h"
#include "components/update_client/op_install.h"
#include "components/update_client/op_puffin.h"
#include "components/update_client/patcher.h"
#include "components/update_client/persisted_data.h"
#include "components/update_client/protocol_definition.h"
#include "components/update_client/protocol_serializer.h"
#include "components/update_client/task_traits.h"
#include "components/update_client/unpacker.h"
#include "components/update_client/unzipper.h"
#include "components/update_client/update_client.h"
#include "components/update_client/update_client_errors.h"
#include "components/update_client/update_client_metrics.h"
#include "components/update_client/update_engine.h"
#include "components/update_client/utils.h"

// The state machine representing how a CRX component changes during an update.
//
//     +------------------------- kNew
//     |                            |
//     |                            V
//     |                        kChecking
//     |                            |
//     V                error       V     no           no
//  kUpdateError <------------- [update?] -> [action?] -> kUpToDate
//     ^                            |           |            ^
//     |                        yes |           | yes        |
//     |     update disabled        V           |            |
//     +-<--------------------- kCanUpdate      +--------> kRun
//     |                            |
//     |                            V           yes
//     |                    [download cached?] --------------+
//     |                               |                     |
//     |                            no |                     |
//     |                no             |                     |
//     |               +-<- [differential update?]           |
//     |               |               |                     |
//     |               |           yes |                     |
//     |               |               |                     |
//     |    error, no  |               |                     |
//     +-<----------[disk space available?]                  |
//     |               |               |                     |
//     |           yes |           yes |                     |
//     |               |               |                     |
//     |               |               |                     |
//     |               | error         V                     |
//     |               +-<----- kDownloadingDiff             |
//     |               |               |                     |
//     |               |               |                     |
//     |               | error         V                     |
//     |               +-<----- kUpdatingDiff                |
//     |               |               |                     |
//     |    error      V               |                     |
//     +-<-------- kDownloading        |                     |
//     |               |               |                     |
//     |               |               |                     |
//     |    error      V               V      no             |
//     +-<-------- kUpdating -----> [action?] -> kUpdated    |
//                     ^               |            ^        |
//                     |               | yes        |        |
//                     |               |            |        |
//                     |               +--------> kRun       |
//                     |                                     |
//                     +-------------------------------------+

// The state machine for a check for update only.
//
//                                kNew
//                                  |
//                                  V
//                             kChecking
//                                  |
//                         yes      V     no
//                         +----[update?] ------> kUpToDate
//                         |
//             yes         v           no
//          +---<-- update disabled? -->---+
//          |                              |
//     kUpdateError                    kCanUpdate

namespace update_client {
namespace {

base::Value::Dict MakeEvent(
    UpdateClient::PingParams ping_params,
    const std::optional<base::Version>& previous_version,
    const std::optional<base::Version>& next_version) {}

}  // namespace

Component::Component(const UpdateContext& update_context, const std::string& id)
    :{}

Component::~Component() = default;

scoped_refptr<Configurator> Component::config() const {}

std::string Component::session_id() const {}

bool Component::is_foreground() const {}

void Component::Handle(CallbackHandleComplete callback_handle_complete) {}

void Component::ChangeState(std::unique_ptr<State> next_state) {}

CrxUpdateItem Component::GetCrxUpdateItem() const {}

void Component::SetParseResult(const ProtocolParser::Result& result) {}

void Component::PingOnly(const CrxComponent& crx_component,
                         UpdateClient::PingParams ping_params) {}

void Component::SetUpdateCheckResult(
    const std::optional<ProtocolParser::Result>& result,
    ErrorCategory error_category,
    int error) {}

void Component::NotifyWait() {}

void Component::AppendEvent(base::Value::Dict event) {}

void Component::NotifyObservers(UpdateClient::Observer::Events event) const {}

base::TimeDelta Component::GetUpdateDuration() const {}

base::Value::Dict Component::MakeEventUpdateComplete() const {}

base::Value::Dict Component::MakeEventActionRun(bool succeeded,
                                                int error_code,
                                                int extra_code1) const {}

std::vector<base::Value::Dict> Component::GetEvents() const {}

std::unique_ptr<CrxInstaller::InstallParams> Component::install_params() const {}

Component::State::State(Component* component, ComponentState state)
    :{}

Component::State::~State() = default;

void Component::State::Handle(CallbackNextState callback_next_state) {}

void Component::State::TransitionState(std::unique_ptr<State> next_state) {}

void Component::State::EndState() {}

Component::StateNew::StateNew(Component* component)
    :{}

Component::StateNew::~StateNew() {}

void Component::StateNew::DoHandle() {}

Component::StateChecking::StateChecking(Component* component)
    :{}

Component::StateChecking::~StateChecking() {}

void Component::StateChecking::DoHandle() {}

Component::StateUpdateError::StateUpdateError(Component* component)
    :{}

Component::StateUpdateError::~StateUpdateError() {}

void Component::StateUpdateError::DoHandle() {}

Component::StateCanUpdate::StateCanUpdate(Component* component)
    :{}

Component::StateCanUpdate::~StateCanUpdate() {}

void Component::StateCanUpdate::DoHandle() {}

// Returns true if a differential update is available, it has not failed yet,
// and the configuration allows this update.
bool Component::StateCanUpdate::CanTryDiffUpdate() const {}

void Component::StateCanUpdate::GetNextCrxFromCacheComplete(
    const CrxCache::Result& result) {}

void Component::StateCanUpdate::CheckIfCacheContainsPreviousCrxComplete(
    bool crx_is_in_cache) {}

Component::StateUpToDate::StateUpToDate(Component* component)
    :{}

Component::StateUpToDate::~StateUpToDate() {}

void Component::StateUpToDate::DoHandle() {}

Component::StateDownloading::StateDownloading(Component* component, bool diff)
    :{}

Component::StateDownloading::~StateDownloading() {}

void Component::StateDownloading::DoHandle() {}

void Component::StateDownloading::DownloadComplete(
    const base::expected<base::FilePath, CategorizedError>& file) {}

Component::StateUpdatingDiff::StateUpdatingDiff(Component* component)
    :{}

Component::StateUpdatingDiff::~StateUpdatingDiff() {}

void Component::StateUpdatingDiff::DoHandle() {}

void Component::StateUpdatingDiff::PatchingComplete(
    const base::expected<base::FilePath, CategorizedError>& result) {}

void Component::StateUpdatingDiff::InstallProgress(int install_progress) {}

void Component::StateUpdatingDiff::InstallComplete(
    const CrxInstaller::Result& result) {}

Component::StateUpdating::StateUpdating(Component* component)
    :{}

Component::StateUpdating::~StateUpdating() {}

void Component::StateUpdating::DoHandle() {}

void Component::StateUpdating::InstallProgress(int install_progress) {}

void Component::StateUpdating::InstallComplete(
    const CrxInstaller::Result& result) {}

Component::StateUpdated::StateUpdated(Component* component)
    :{}

Component::StateUpdated::~StateUpdated() {}

void Component::StateUpdated::DoHandle() {}

Component::StatePingOnly::StatePingOnly(Component* component)
    :{}

Component::StatePingOnly::~StatePingOnly() {}

void Component::StatePingOnly::DoHandle() {}

Component::StateRun::StateRun(Component* component)
    :{}

Component::StateRun::~StateRun() {}

void Component::StateRun::DoHandle() {}

void Component::StateRun::ActionRunComplete(bool succeeded,
                                            int error_code,
                                            int extra_code1) {}

}  // namespace update_client