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
|
// Copyright 2021 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_BROWSER_CHROMEOS_APP_MODE_CHROME_KIOSK_APP_INSTALLER_H_
#define CHROME_BROWSER_CHROMEOS_APP_MODE_CHROME_KIOSK_APP_INSTALLER_H_
#include <memory>
#include <string>
#include <vector>
#include "base/containers/flat_set.h"
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/app_mode/startup_app_launcher_update_checker.h"
#include "chrome/browser/extensions/forced_extensions/install_stage_tracker.h"
#include "chrome/browser/extensions/install_observer.h"
#include "chrome/browser/extensions/install_tracker.h"
#include "chromeos/crosapi/mojom/chrome_app_kiosk_service.mojom.h"
#include "extensions/common/extension_id.h"
class Profile;
namespace chromeos {
class ChromeKioskAppInstaller
: private extensions::InstallObserver,
public extensions::InstallStageTracker::Observer {
public:
using InstallResult = crosapi::mojom::ChromeKioskInstallResult;
using AppInstallParams = crosapi::mojom::AppInstallParams;
using InstallCallback =
crosapi::mojom::ChromeKioskLaunchController::InstallKioskAppCallback;
ChromeKioskAppInstaller(Profile* profile,
const AppInstallParams& install_data);
ChromeKioskAppInstaller(const ChromeKioskAppInstaller&) = delete;
ChromeKioskAppInstaller& operator=(const ChromeKioskAppInstaller&) = delete;
~ChromeKioskAppInstaller() override;
void BeginInstall(InstallCallback callback);
private:
void MaybeInstallSecondaryApps(const extensions::Extension& primary_app);
void MaybeCheckExtensionUpdate();
void OnExtensionUpdateCheckFinished(bool update_found);
void FinalizeAppInstall();
// extensions::InstallObserver overrides.
void OnFinishCrxInstall(content::BrowserContext* context,
const base::FilePath& source_file,
const std::string& extension_id,
const extensions::Extension* extension,
bool success) override;
// extensions::InstallStageTracker::Observer overrides.
void OnExtensionInstallationFailed(
const extensions::ExtensionId& id,
extensions::InstallStageTracker::FailureReason reason) override;
void ReportInstallSuccess();
void ReportInstallFailure(InstallResult result);
// Observes `InstallTracker` until the given `ids` finish installing.
void ObserveInstallations(const std::vector<extensions::ExtensionId>& ids);
const extensions::ExtensionId& primary_app_id() const {
return primary_app_install_data_.id;
}
raw_ref<Profile> profile_;
AppInstallParams primary_app_install_data_;
// The set of extension IDs to wait for in `OnFinishCrxInstall`. This includes
// the primary Chrome app, its secondary apps, as well as any shared modules
// they import.
base::flat_set<extensions::ExtensionId> waiting_ids_;
InstallCallback on_ready_callback_;
bool install_complete_ = false;
bool secondary_apps_installing_ = false;
// Will be true if an update (not an install) of the primary app fails.
bool primary_app_update_failed_ = false;
// Will be true if an update (not an install) of a secondary app fails.
bool secondary_app_update_failed_ = false;
base::Time extension_update_start_time_;
// Used to run extension update checks for primary app's imports and
// secondary extensions.
std::unique_ptr<StartupAppLauncherUpdateChecker> update_checker_;
base::ScopedObservation<extensions::InstallTracker,
extensions::InstallObserver>
install_observation_{this};
base::ScopedObservation<extensions::InstallStageTracker,
extensions::InstallStageTracker::Observer>
install_stage_observation_{this};
base::WeakPtrFactory<ChromeKioskAppInstaller> weak_ptr_factory_{this};
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_APP_MODE_CHROME_KIOSK_APP_INSTALLER_H_
|