#ifndef CHROME_BROWSER_APPS_PLATFORM_APPS_APP_LOAD_SERVICE_H_
#define CHROME_BROWSER_APPS_PLATFORM_APPS_APP_LOAD_SERVICE_H_
#include <map>
#include <string>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "components/keyed_service/core/keyed_service.h"
#include "extensions/browser/extension_host_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension_id.h"
namespace content {
class BrowserContext;
}
namespace apps {
class AppLoadService : public KeyedService,
public extensions::ExtensionRegistryObserver,
public extensions::ExtensionHostRegistry::Observer {
public:
enum PostReloadActionType {
LAUNCH_FOR_RELOAD,
RESTART,
LAUNCH_FOR_LOAD_AND_LAUNCH,
};
struct PostReloadAction {
PostReloadAction();
PostReloadActionType action_type;
base::CommandLine command_line;
base::FilePath current_dir;
};
explicit AppLoadService(content::BrowserContext* context);
AppLoadService(const AppLoadService&) = delete;
AppLoadService& operator=(const AppLoadService&) = delete;
~AppLoadService() override;
void Shutdown() override;
void RestartApplication(const std::string& extension_id);
void RestartApplicationIfRunning(const std::string& extension_id);
bool LoadAndLaunch(const base::FilePath& extension_path,
const base::CommandLine& command_line,
const base::FilePath& current_dir);
bool Load(const base::FilePath& extension_path);
static AppLoadService* Get(content::BrowserContext* context);
private:
void OnExtensionHostCompletedFirstLoad(
content::BrowserContext* browser_context,
extensions::ExtensionHost* host) override;
void OnExtensionUnloaded(content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) override;
bool WasUnloadedForReload(const extensions::ExtensionId& extension_id,
const extensions::UnloadedExtensionReason reason);
bool HasPostReloadAction(const std::string& extension_id);
std::map<std::string, PostReloadAction> post_reload_actions_;
raw_ptr<content::BrowserContext> context_;
base::ScopedObservation<extensions::ExtensionHostRegistry,
extensions::ExtensionHostRegistry::Observer>
host_registry_observation_{this};
};
}
#endif