#ifndef CHROME_BROWSER_ACCESSIBILITY_EMBEDDED_A11Y_EXTENSION_LOADER_H_
#define CHROME_BROWSER_ACCESSIBILITY_EMBEDDED_A11Y_EXTENSION_LOADER_H_
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_multi_source_observation.h"
#include "base/scoped_observation.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "chrome/browser/profiles/profile_observer.h"
namespace extensions {
class ComponentLoader;
}
class Profile;
class EmbeddedA11yExtensionLoader : public ProfileObserver,
public ProfileManagerObserver {
public:
struct ExtensionInfo {
ExtensionInfo(const std::string& extension_id,
const base::FilePath& extension_path,
const base::FilePath::CharType* extension_manifest_file,
bool should_localize);
ExtensionInfo(const ExtensionInfo& other);
ExtensionInfo(ExtensionInfo&&);
ExtensionInfo& operator=(const ExtensionInfo&);
ExtensionInfo& operator=(ExtensionInfo&&);
~ExtensionInfo();
const std::string extension_id;
const base::FilePath extension_path;
const base::FilePath::CharType* extension_manifest_file;
bool should_localize;
};
static EmbeddedA11yExtensionLoader* GetInstance();
EmbeddedA11yExtensionLoader();
~EmbeddedA11yExtensionLoader() override;
EmbeddedA11yExtensionLoader(EmbeddedA11yExtensionLoader&) = delete;
EmbeddedA11yExtensionLoader& operator=(EmbeddedA11yExtensionLoader&) = delete;
void Init();
void InstallExtensionWithId(const std::string& extension_id,
const std::string& extension_resource_directory,
const base::FilePath::CharType* manifest_name,
bool should_localize);
void InstallExtensionWithIdAndPath(
const std::string& extension_id,
const base::FilePath& extension_path,
const base::FilePath::CharType* manifest_name,
bool should_localize);
void RemoveExtensionWithId(const std::string& extension_id);
void AddExtensionChangedCallbackForTest(base::RepeatingClosure callback);
bool IsExtensionInstalled(const std::string& extension_id);
private:
void OnProfileWillBeDestroyed(Profile* profile) override;
void OnOffTheRecordProfileCreated(Profile* off_the_record) override;
void OnProfileAdded(Profile* profile) override;
void OnProfileManagerDestroying() override;
void UpdateAllProfiles(const std::string& extension_id);
void UpdateProfile(Profile* profile, const std::string& extension_id);
void MaybeRemoveExtension(Profile* profile, const std::string& extension_id);
void MaybeInstallExtension(Profile* profile,
const std::string& extension_id,
const base::FilePath& extension_path,
const base::FilePath::CharType* manifest_name,
bool should_localize);
void InstallExtension(extensions::ComponentLoader* component_loader,
const base::FilePath& path,
const std::string& extension_id,
std::optional<base::Value::Dict> manifest);
bool initialized_ = false;
std::map<std::string, ExtensionInfo> extension_map_;
base::RepeatingClosure extension_installation_changed_callback_for_test_;
base::ScopedMultiSourceObservation<Profile, ProfileObserver>
observed_profiles_{this};
base::ScopedObservation<ProfileManager, ProfileManagerObserver>
profile_manager_observation_{this};
base::WeakPtrFactory<EmbeddedA11yExtensionLoader> weak_ptr_factory_{this};
friend struct base::DefaultSingletonTraits<EmbeddedA11yExtensionLoader>;
};
#endif