#ifndef CHROME_BROWSER_ASH_PLUGIN_VM_PLUGIN_VM_UTIL_H_
#define CHROME_BROWSER_ASH_PLUGIN_VM_PLUGIN_VM_UTIL_H_
#include <memory>
#include <optional>
#include <string>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list_types.h"
#include "chromeos/ash/components/settings/cros_settings.h"
#include "components/prefs/pref_change_registrar.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
namespace aura {
class Window;
}
class Profile;
class GURL;
namespace plugin_vm {
class PluginVmAvailabilitySubscription;
extern const char kPitaDlc[];
extern const char kPluginVmShelfAppId[];
extern const char kPluginVmName[];
extern const char kChromeOSBaseDirectoryDisplayText[];
inline constexpr net::NetworkTrafficAnnotationTag
kPluginVmNetworkTrafficAnnotation =
net::DefineNetworkTrafficAnnotation("plugin_vm_image_download", R"(
semantics {
sender: "Plugin VM image manager"
description: "Request to download Plugin VM image is sent in order "
"to allow user to run Plugin VM."
trigger: "User clicking on Plugin VM icon when Plugin VM is not yet "
"installed."
data: "Request to download Plugin VM image. Sends cookies to "
"authenticate the user."
destination: WEBSITE
}
policy {
cookies_allowed: YES
cookies_store: "user"
chrome_policy {
PluginVmImage {
PluginVmImage: "{'url': 'example.com', 'hash': 'sha256hash'}"
}
}
}
)");
bool IsPluginVmRunning(Profile* profile);
void ShowPluginVmInstallerView(Profile* profile);
bool IsPluginVmAppWindow(const aura::Window* window);
std::string GetPluginVmUserIdForProfile(const Profile* profile);
void SetFakePluginVmPolicy(Profile* profile,
const std::string& image_path,
const std::string& image_hash,
const std::string& license_key);
bool FakeLicenseKeyIsSet();
std::string GetFakeLicenseKey();
void RemoveDriveDownloadDirectoryIfExists();
std::optional<std::string> GetIdFromDriveUrl(const GURL& url);
bool IsPluginvmWindowId(const std::string& window_id);
class PluginVmAvailabilitySubscription {
public:
using AvailabilityChangeCallback =
base::RepeatingCallback<void(bool is_allowed, bool is_configured)>;
PluginVmAvailabilitySubscription(Profile* profile,
AvailabilityChangeCallback callback);
~PluginVmAvailabilitySubscription();
PluginVmAvailabilitySubscription(const PluginVmAvailabilitySubscription&) =
delete;
PluginVmAvailabilitySubscription& operator=(
const PluginVmAvailabilitySubscription&) = delete;
private:
void OnPolicyChanged();
void OnImageExistsChanged();
raw_ptr<Profile> profile_;
bool is_allowed_;
bool is_configured_;
AvailabilityChangeCallback callback_;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
base::CallbackListSubscription device_allowed_subscription_;
base::CallbackListSubscription fake_license_subscription_;
};
}
#endif