chromium/components/update_client/op_install.cc

// Copyright 2024 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/op_install.h"

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/scoped_refptr.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/values.h"
#include "components/crx_file/crx_verifier.h"
#include "components/update_client/configurator.h"
#include "components/update_client/crx_cache.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 "third_party/puffin/src/include/puffin/puffpatch.h"

namespace update_client {

namespace {

// The sequence of calls is:
//
// [Original Sequence]      [Blocking Pool]
//
// CrxCache::Put (optional)
// Unpack
// Unpacker::Unpack
// Install
//                          InstallBlocking
//                          installer->Install
// CallbackChecker::Done
//                          [lambda to delete unpack path]
// InstallComplete
// [original callback]

// CallbackChecker ensures that a progress callback is not posted after a
// completion callback. It is only accessed and modified on the main sequence.
// Both callbacks maintain a reference to an instance of this class.
class CallbackChecker : public base::RefCountedThreadSafe<CallbackChecker> {};

// Runs on the original sequence.
void InstallComplete(
    base::OnceCallback<void(const CrxInstaller::Result&)> callback,
    base::RepeatingCallback<void(base::Value::Dict)> event_adder,
    const CrxInstaller::Result& result) {}

// Runs in the blocking thread pool.
void InstallBlocking(
    CrxInstaller::ProgressCallback progress_callback,
    base::OnceCallback<void(const CrxInstaller::Result&)> callback,
    const base::FilePath& unpack_path,
    const std::string& public_key,
    const std::string& next_fp,
    std::unique_ptr<CrxInstaller::InstallParams> install_params,
    scoped_refptr<CrxInstaller> installer) {}

// Runs on the original sequence.
void Install(base::OnceCallback<void(const CrxInstaller::Result&)> callback,
             const std::string& next_fp,
             std::unique_ptr<CrxInstaller::InstallParams> install_params,
             scoped_refptr<CrxInstaller> installer,
             CrxInstaller::ProgressCallback progress_callback,
             const Unpacker::Result& result) {}

// Runs on the original sequence.
void Unpack(base::OnceCallback<void(const Unpacker::Result&)> callback,
            const base::FilePath& crx_file,
            std::unique_ptr<Unzipper> unzipper,
            const std::vector<uint8_t>& pk_hash,
            crx_file::VerifierFormat crx_format,
            const CrxCache::Result& cache_result) {}

}  // namespace

void InstallOperation(
    std::optional<scoped_refptr<CrxCache>> crx_cache,
    std::unique_ptr<Unzipper> unzipper,
    crx_file::VerifierFormat crx_format,
    const std::string& id,
    const std::vector<uint8_t>& pk_hash,
    scoped_refptr<CrxInstaller> installer,
    std::unique_ptr<CrxInstaller::InstallParams> install_params,
    const std::string& next_fp,
    base::RepeatingCallback<void(base::Value::Dict)> event_adder,
    base::OnceCallback<void(const CrxInstaller::Result&)> callback,
    CrxInstaller::ProgressCallback progress_callback,
    const base::FilePath& crx_file) {}

}  // namespace update_client