1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_UPDATER_APP_APP_INSTALL_H_
#define CHROME_UPDATER_APP_APP_INSTALL_H_
#include <memory>
#include <string>
#include "base/functional/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "chrome/updater/app/app.h"
#include "chrome/updater/lock.h"
namespace base {
class Version;
}
namespace updater {
class ExternalConstants;
class UpdateService;
// This class defines an interface for installing an application. The interface
// is intended to be implemented for scenerios where UI and RPC calls to
// |UpdateService| are involved, hence the word `controller` in the name of
// the interface.
class AppInstallController
: public base::RefCountedThreadSafe<AppInstallController> {
public:
using Maker = base::RepeatingCallback<scoped_refptr<AppInstallController>()>;
virtual void Initialize() = 0;
virtual void InstallApp(const std::string& app_id,
const std::string& app_name,
base::OnceCallback<void(int)> callback) = 0;
virtual void InstallAppOffline(const std::string& app_id,
const std::string& app_name,
base::OnceCallback<void(int)> callback) = 0;
virtual void Exit(int exit_code) = 0;
virtual void set_update_service(
scoped_refptr<UpdateService> update_service) = 0;
protected:
virtual ~AppInstallController() = default;
private:
friend class base::RefCountedThreadSafe<AppInstallController>;
};
// Sets the updater up then installs an application while displaying the UI
// progress window.
class AppInstall : public App {
public:
explicit AppInstall(AppInstallController::Maker app_install_controller_maker);
private:
~AppInstall() override;
void SendPing(int exit_code, base::OnceClosure callback);
void PingAndShutdown(int exit_code);
void ShutdownNow(int exit_code);
// Overrides for App.
[[nodiscard]] int Initialize() override;
void FirstTaskRun() override;
// Initializes or reinitializes `update_service_`. Reinitialization can be
// used to pick up a possible change to the active updater.
void CreateUpdateServiceProxy();
// Called after the version of the active updater has been retrieved.
void GetVersionDone(const base::Version& version);
void InstallCandidateDone(bool valid_version, int result);
void WakeCandidate();
void RegisterUpdater();
// Installs an application if the `app_id_` is valid.
void MaybeInstallApp();
// Bound to the main sequence.
SEQUENCE_CHECKER(sequence_checker_);
// Inter-process lock taken by AppInstall, AppUninstall, and AppUpdate.
std::unique_ptr<ScopedLock> setup_lock_;
// The `app_id_` is parsed from the tag, if the the tag is present, or from
// the command line argument --app-id.
std::string app_id_;
std::string app_name_;
// Creates instances of |AppInstallController|.
AppInstallController::Maker app_install_controller_maker_;
scoped_refptr<AppInstallController> app_install_controller_;
scoped_refptr<ExternalConstants> external_constants_;
scoped_refptr<UpdateService> update_service_;
};
scoped_refptr<App> MakeAppInstall(bool is_silent_install);
} // namespace updater
#endif // CHROME_UPDATER_APP_APP_INSTALL_H_
|