#ifndef ASH_WEBUI_ECHE_APP_UI_LAUNCH_APP_HELPER_H_
#define ASH_WEBUI_ECHE_APP_UI_LAUNCH_APP_HELPER_H_
#include <optional>
#include <variant>
#include "ash/webui/eche_app_ui/feature_status.h"
#include "ash/webui/eche_app_ui/mojom/eche_app.mojom.h"
#include "base/containers/flat_set.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/timer/timer.h"
namespace gfx {
class Image;
}
namespace ash {
namespace phonehub {
class PhoneHubManager;
}
namespace eche_app {
class AppsLaunchInfoProvider;
class LaunchAppHelper {
public:
class NotificationInfo {
public:
enum Category {
kNative,
kWebUI,
};
enum class NotificationType {
kScreenLock = 0,
};
NotificationInfo(
Category category,
std::variant<NotificationType, mojom::WebNotificationType> type);
~NotificationInfo();
Category category() const { return category_; }
std::variant<NotificationType, mojom::WebNotificationType> type() const {
return type_;
}
private:
Category category_;
std::variant<NotificationType, mojom::WebNotificationType> type_;
};
using LaunchNotificationFunction =
base::RepeatingCallback<void(const std::optional<std::u16string>& title,
const std::optional<std::u16string>& message,
std::unique_ptr<NotificationInfo> info)>;
using CloseNotificationFunction =
base::RepeatingCallback<void(const std::string& notification_id)>;
using LaunchEcheAppFunction = base::RepeatingCallback<void(
const std::optional<int64_t>& notification_id,
const std::string& package_name,
const std::u16string& visible_name,
const std::optional<int64_t>& user_id,
const gfx::Image& icon,
const std::u16string& phone_name,
AppsLaunchInfoProvider* apps_launch_info_provider)>;
enum class AppLaunchProhibitedReason {
kNotProhibited = 0,
kDisabledByScreenLock = 1,
};
LaunchAppHelper(phonehub::PhoneHubManager* phone_hub_manager,
LaunchEcheAppFunction launch_eche_app_function,
LaunchNotificationFunction launch_notification_function,
CloseNotificationFunction close_notification_function);
virtual ~LaunchAppHelper();
LaunchAppHelper(const LaunchAppHelper&) = delete;
LaunchAppHelper& operator=(const LaunchAppHelper&) = delete;
virtual LaunchAppHelper::AppLaunchProhibitedReason
CheckAppLaunchProhibitedReason(FeatureStatus status) const;
virtual void ShowNotification(const std::optional<std::u16string>& title,
const std::optional<std::u16string>& message,
std::unique_ptr<NotificationInfo> info) const;
virtual void CloseNotification(const std::string& notification_id) const;
virtual void ShowToast(const std::u16string& text) const;
void LaunchEcheApp(std::optional<int64_t> notification_id,
const std::string& package_name,
const std::u16string& visible_name,
const std::optional<int64_t>& user_id,
const gfx::Image& icon,
const std::u16string& phone_name,
AppsLaunchInfoProvider* apps_launch_info_provider);
const base::flat_set<std::string> GetSessionPackagesLaunchedForTest() const {
return session_packages_launched_;
}
private:
bool IsScreenLockRequired() const;
base::flat_set<std::string> session_packages_launched_;
base::TimeTicks session_packages_last_reset_ = base::TimeTicks();
raw_ptr<phonehub::PhoneHubManager> phone_hub_manager_;
LaunchEcheAppFunction launch_eche_app_function_;
LaunchNotificationFunction launch_notification_function_;
CloseNotificationFunction close_notification_function_;
};
}
}
#endif