#ifndef ASH_SYSTEM_PHONEHUB_ONBOARDING_NUDGE_CONTROLLER_H_
#define ASH_SYSTEM_PHONEHUB_ONBOARDING_NUDGE_CONTROLLER_H_
#include "ash/ash_export.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chromeos/ash/components/phonehub/feature_status_provider.h"
class PrefRegistrySimple;
namespace base {
class Clock;
}
namespace multidevice {
class RemoteDeviceRef;
}
namespace views {
class View;
}
namespace ash {
class ASH_EXPORT OnboardingNudgeController
: public phonehub::FeatureStatusProvider::Observer {
public:
OnboardingNudgeController(views::View* anchored_view,
base::RepeatingClosure stop_animation_callback,
base::RepeatingClosure start_animation_callback,
base::Clock* clock);
OnboardingNudgeController(const OnboardingNudgeController&) = delete;
OnboardingNudgeController& operator=(const OnboardingNudgeController&) =
delete;
~OnboardingNudgeController() override;
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
static constexpr char kPhoneHubNudgeId[] = "PhoneHubNudge";
static constexpr char kPhoneHubNudgeLastShownTime[] =
"ash.phone_hub_nudge_last_shown";
static constexpr char kPhoneHubNudgeTotalAppearances[] =
"ash.phone_hub_nudge_total_appearances";
static constexpr char kPhoneHubNudgeLastActionTime[] =
"ash.phone_hub_nudge_last_action_time";
static constexpr char kPhoneHubNudgeLastClickTime[] =
"ash.phone_hub_nudge_last_click_time";
static constexpr char kSyncedDevices[] = "ash.phone_hub_synced_devices";
void ShowNudgeIfNeeded();
void HideNudge();
void MaybeRecordNudgeAction();
void OnNudgeHoverStateChanged(bool is_hovering);
void OnNudgeClicked();
void OnNudgeDismissed();
private:
FRIEND_TEST_ALL_PREFIXES(OnboardingNudgeControllerTest,
AddToSyncedDeviceListWhenNewEligibleDeviceFound);
FRIEND_TEST_ALL_PREFIXES(OnboardingNudgeControllerTest,
DoNotAddToSyncedDeviceListIfAlreadyFound);
static constexpr int kPhoneHubNudgeTotalAppearancesAllowed = 3;
static constexpr base::TimeDelta kPhoneHubNudgeDelay = base::Hours(24);
bool IsDeviceStoredInPref(const multidevice::RemoteDeviceRef& device);
void AddToEligibleDevicesPref(const multidevice::RemoteDeviceRef& device);
void ResetNudgePrefs();
void OnFeatureStatusChanged() override {}
void OnEligiblePhoneHubHostFound(
const multidevice::RemoteDeviceRefList eligible_devices) override;
bool ShouldShowNudge();
bool is_nudge_clicked_ = false;
bool is_phone_hub_icon_clicked_ = false;
raw_ptr<views::View> anchored_view_;
base::RepeatingClosure stop_animation_callback_;
base::RepeatingClosure start_animation_callback_;
raw_ptr<base::Clock> clock_;
base::WeakPtrFactory<OnboardingNudgeController> weak_ptr_factory_{this};
};
}
#endif