// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_ASH_LOGIN_LOGIN_UI_PREF_CONTROLLER_H_
#define CHROME_BROWSER_UI_ASH_LOGIN_LOGIN_UI_PREF_CONTROLLER_H_

#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "components/prefs/pref_change_registrar.h"

class PrefService;

namespace ash {

class LoginUIPrefController {
 public:
  // Applies effects of login-screen prefs, e.g., mouse and touchpad settings
  // that are coming from the owner user and/or device policies.
  // `session_state` specifies whether it's the first (primary user) or
  // subsequent (secondary user) login.
  // `local_state` must be non-null and must outlive `this`.
  LoginUIPrefController(PrefService* local_state,
                        bool update_geolocation_usage_allowed);
  LoginUIPrefController(const LoginUIPrefController&) = delete;
  LoginUIPrefController& operator=(const LoginUIPrefController&) = delete;
  ~LoginUIPrefController();

 private:
  // Apply the owner preferences after local_state prefService start.
  void InitOwnerPreferences(bool success);

  // Apply "owner.mouse.primary_right" preference on the login screen.
  void UpdatePrimaryMouseButtonRight();

  // Apply "owner.pointing_stick.primary_right" preference on the login screen.
  void UpdatePrimaryPointingStickButtonRight();

  // Apply "owner.touchpad.enable_tap_to_click" preference on the login screen.
  void UpdateTapToClickEnabled();

  // Apply "ash.device.geolocation_allowed" preference on the login screen.
  void UpdateGeolocationUsageAllowed();

  const raw_ref<PrefService> local_state_;

  PrefChangeRegistrar pref_change_registrar_;

  bool update_geolocation_usage_allowed_;

  base::WeakPtrFactory<LoginUIPrefController> weak_factory_{this};
};

}  // namespace ash

#endif  // CHROME_BROWSER_UI_ASH_LOGIN_LOGIN_UI_PREF_CONTROLLER_H_
