#ifndef CHROME_BROWSER_ASH_EXTENSIONS_EXTERNAL_CACHE_IMPL_H_
#define CHROME_BROWSER_ASH_EXTENSIONS_EXTERNAL_CACHE_IMPL_H_
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/callback_list.h"
#include "base/files/file_path.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "chrome/browser/ash/extensions/external_cache.h"
#include "chrome/browser/extensions/updater/local_extension_cache.h"
#include "extensions/browser/updater/extension_downloader_delegate.h"
#include "extensions/common/extension_id.h"
#include "net/base/backoff_entry.h"
namespace content {
class BrowserContext;
}
namespace extensions {
class ExtensionDownloader;
}
namespace network {
class SharedURLLoaderFactory;
}
namespace chromeos {
class ExternalCacheDelegate;
class ExternalCacheImpl : public ExternalCache,
public extensions::ExtensionDownloaderDelegate {
public:
ExternalCacheImpl(
const base::FilePath& cache_dir,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner,
ExternalCacheDelegate* delegate,
bool always_check_updates,
bool wait_for_cache_initialization,
bool allow_scheduled_updates);
ExternalCacheImpl(const ExternalCacheImpl&) = delete;
ExternalCacheImpl& operator=(const ExternalCacheImpl&) = delete;
~ExternalCacheImpl() override;
const base::Value::Dict& GetCachedExtensions() override;
void Shutdown(base::OnceClosure callback) override;
void UpdateExtensionsList(base::Value::Dict prefs) override;
void OnDamagedFileDetected(const base::FilePath& path) override;
void RemoveExtensions(
const std::vector<extensions::ExtensionId>& ids) override;
bool GetExtension(const extensions::ExtensionId& id,
base::FilePath* file_path,
std::string* version) override;
bool ExtensionFetchPending(const extensions::ExtensionId& id) override;
void PutExternalExtension(const extensions::ExtensionId& id,
const base::FilePath& crx_file_path,
const std::string& version,
PutExternalExtensionCallback callback) override;
void SetBackoffPolicy(
std::optional<net::BackoffEntry::Policy> backoff_policy) override;
void OnExtensionDownloadFailed(const extensions::ExtensionId& id,
Error error,
const PingResult& ping_result,
const std::set<int>& request_ids,
const FailureData& data) override;
void OnExtensionDownloadFinished(const extensions::CRXFileInfo& file,
bool file_ownership_passed,
const GURL& download_url,
const PingResult& ping_result,
const std::set<int>& request_ids,
InstallCallback callback) override;
bool IsExtensionPending(const extensions::ExtensionId& id) override;
bool GetExtensionExistingVersion(const extensions::ExtensionId& id,
std::string* version) override;
RequestRollbackResult RequestRollback(
const extensions::ExtensionId& id) override;
void set_flush_on_put(bool flush_on_put) { flush_on_put_ = flush_on_put; }
private:
class AnyInstallFailureObserver;
void UpdateExtensionLoader();
void CheckCache();
void MaybeScheduleNextCacheCheck();
void OnPutExtension(const extensions::ExtensionId& id,
const base::FilePath& file_path,
bool file_ownership_passed);
void OnPutExternalExtension(const extensions::ExtensionId& id,
PutExternalExtensionCallback callback,
const base::FilePath& file_path,
bool file_ownership_passed);
void RemoveCachedExtension(const extensions::ExtensionId& id);
void OnCrxInstallFailure(content::BrowserContext* context,
const base::FilePath& source_file);
std::unique_ptr<AnyInstallFailureObserver> any_install_failure_observer_;
extensions::LocalExtensionCache local_cache_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
const scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
raw_ptr<ExternalCacheDelegate> delegate_;
bool always_check_updates_;
bool wait_for_cache_initialization_;
bool allow_scheduled_updates_;
bool flush_on_put_ = false;
base::Value::Dict extensions_;
base::Value::Dict cached_extensions_;
std::unique_ptr<extensions::ExtensionDownloader> downloader_;
std::optional<net::BackoffEntry::Policy> backoff_policy_;
base::CallbackListSubscription kiosk_crx_updates_from_policy_subscription_;
base::WeakPtrFactory<ExternalCacheImpl> scheduler_weak_ptr_factory_{this};
base::WeakPtrFactory<ExternalCacheImpl> weak_ptr_factory_{this};
};
}
#endif