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
|
// Copyright 2023 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_WEB_APPLICATIONS_JOBS_INSTALL_PLACEHOLDER_JOB_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_JOBS_INSTALL_PLACEHOLDER_JOB_H_
#include <memory>
#include <optional>
#include "base/memory/raw_ptr.h"
#include "chrome/browser/web_applications/commands/web_app_command.h"
#include "chrome/browser/web_applications/external_install_options.h"
#include "chrome/browser/web_applications/externally_managed_app_manager.h"
#include "chrome/browser/web_applications/web_app_install_utils.h"
class Profile;
namespace content {
class WebContents;
}
namespace webapps {
class WebAppUrlLoader;
enum class WebAppUrlLoaderResult;
} // namespace webapps
namespace web_app {
class SharedWebContentsWithAppLock;
class WebAppDataRetriever;
// This job is used during externally managed app install flow to install a
// placeholder app instead of the target app when the app's install_url fails to
// load.
class InstallPlaceholderJob {
public:
using InstallAndReplaceCallback =
base::OnceCallback<void(webapps::InstallResultCode code,
webapps::AppId app_id)>;
InstallPlaceholderJob(Profile* profile,
base::Value::Dict& debug_value,
const ExternalInstallOptions& install_options,
InstallAndReplaceCallback callback,
SharedWebContentsWithAppLock& lock);
virtual ~InstallPlaceholderJob();
void Start();
void SetDataRetrieverForTesting(
std::unique_ptr<WebAppDataRetriever> data_retriever);
private:
void Abort(webapps::InstallResultCode code);
void FetchCustomIcon(const GURL& url, int retries_left);
void OnUrlLoaded(webapps::WebAppUrlLoaderResult load_url_result);
void OnCustomIconFetched(const GURL& image_url,
int retries_left,
IconsDownloadedResult result,
IconsMap icons_map,
DownloadedIconsHttpResults icons_http_results);
void FinalizeInstall(
std::optional<std::reference_wrapper<const std::vector<SkBitmap>>>
bitmaps);
void OnInstallFinalized(const webapps::AppId& app_id,
webapps::InstallResultCode code);
const raw_ref<Profile> profile_;
const raw_ref<base::Value::Dict> debug_value_;
const webapps::AppId app_id_;
// `this` must exist within the scope of a WebCommand's
// SharedWebContentsWithAppLock.
const raw_ref<SharedWebContentsWithAppLock> lock_;
const ExternalInstallOptions install_options_;
InstallAndReplaceCallback callback_;
raw_ptr<content::WebContents> web_contents_;
std::unique_ptr<webapps::WebAppUrlLoader> url_loader_;
std::unique_ptr<WebAppDataRetriever> data_retriever_;
base::WeakPtrFactory<InstallPlaceholderJob> weak_factory_{this};
};
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_JOBS_INSTALL_PLACEHOLDER_JOB_H_
|