File: proximity_auth_profile_pref_manager.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (92 lines) | stat: -rw-r--r-- 3,576 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PROFILE_PREF_MANAGER_H_
#define CHROMEOS_ASH_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PROFILE_PREF_MANAGER_H_

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/account_id/account_id.h"

class PrefService;

namespace ash::multidevice_setup {
class MultiDeviceSetupClient;
}  // namespace ash::multidevice_setup

namespace user_prefs {
class PrefRegistrySyncable;
}  // namespace user_prefs

namespace proximity_auth {

// Interface for setting and getting persistent user preferences for a logged in
// session with a user profile.
class ProximityAuthProfilePrefManager {
 public:
  // Creates a pref manager backed by preferences registered in
  // |pref_service| (persistent across browser restarts). |pref_service| should
  // have been registered using RegisterPrefs(). Not owned, must out live this
  // instance.
  ProximityAuthProfilePrefManager(
      PrefService* pref_service,
      ash::multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client);

  ProximityAuthProfilePrefManager(const ProximityAuthProfilePrefManager&) =
      delete;
  ProximityAuthProfilePrefManager& operator=(
      const ProximityAuthProfilePrefManager&) = delete;

  ~ProximityAuthProfilePrefManager();

  // Registers the prefs used by this class to the given |pref_service|.
  static void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry);

  // Returns true if SmartLock/EasyUnlock is allowed. Note: there is no
  // corresponding setter because this pref is pushed through an enterprise
  // policy. Note that this pref completely disables EasyUnlock, hiding even the
  // UI. See IsEasyUnlockEnabled() for comparison.
  bool IsEasyUnlockAllowed() const;

  // Returns true if SmartLock/EasyUnlock is enabled, i.e. the user has gone
  // through the setup flow and has at least one phone as an unlock key. Compare
  // to IsEasyUnlockAllowed(), which completely removes the feature from
  // existence.
  void SetIsEasyUnlockEnabled(bool is_easy_unlock_enabled) const;
  bool IsEasyUnlockEnabled() const;

  // Returns true if SmartLock/EasyUnlock has ever been enabled, regardless of
  // whether the feature is currently enabled or disabled. Compare to
  // IsEasyUnlockEnabled(), which flags the latter case.
  void SetEasyUnlockEnabledStateSet() const;
  bool IsEasyUnlockEnabledStateSet() const;

  // Setter and getter for the timestamp of the last time the promotion was
  // shown to the user.
  void SetLastPromotionCheckTimestampMs(int64_t timestamp_ms);
  int64_t GetLastPromotionCheckTimestampMs() const;

  // Setter and getter for the number of times the promotion was shown to the
  // user.
  void SetPromotionShownCount(int count);
  int GetPromotionShownCount() const;

 private:
  // Contains perferences that outlive the lifetime of this object and across
  // process restarts. Not owned and must outlive this instance.
  raw_ptr<PrefService> pref_service_ = nullptr;

  // The account id of the current profile.
  AccountId account_id_;

  // Used to determine the FeatureState of Smart Lock.
  raw_ptr<ash::multidevice_setup::MultiDeviceSetupClient>
      multidevice_setup_client_ = nullptr;

  base::WeakPtrFactory<ProximityAuthProfilePrefManager> weak_ptr_factory_{this};
};

}  // namespace proximity_auth

#endif  // CHROMEOS_ASH_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PROFILE_PREF_MANAGER_H_