File: screenlock_bridge.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 (121 lines) | stat: -rw-r--r-- 3,948 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2014 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_SCREENLOCK_BRIDGE_H_
#define CHROMEOS_ASH_COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_

#include <memory>
#include <string>

#include "base/lazy_instance.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "base/values.h"
#include "chromeos/ash/components/proximity_auth/public/mojom/auth_type.mojom.h"
#include "components/account_id/account_id.h"

namespace ash {
enum class SmartLockState;
}  // namespace ash

namespace proximity_auth {

// TODO(jhawkins): Rationalize this class now that it is CrOS only and most of
// its functionality is not useful.
class ScreenlockBridge {
 public:
  class LockHandler {
   public:
    enum ScreenType { LOCK_SCREEN = 0, OTHER_SCREEN = 1 };

    // Displays |message| in a banner on the lock screen.
    virtual void ShowBannerMessage(const std::u16string& message,
                                   bool is_warning) = 0;

    // Update the status of Smart Lock for |account_id|.
    virtual void SetSmartLockState(const AccountId& account_id,
                                   ash::SmartLockState state) = 0;

    // Called after a Smart Lock authentication attempt has been made. If
    // |successful| is true, then the Smart Lock authentication attempt was
    // successful and the device should be unlocked. If false, an error message
    // should be shown to the user.
    virtual void NotifySmartLockAuthResult(const AccountId& account_id,
                                           bool successful) = 0;

    // (Re)enable lock screen UI.
    virtual void EnableInput() = 0;

    // Set the authentication type to be used on the lock screen.
    virtual void SetAuthType(const AccountId& account_id,
                             proximity_auth::mojom::AuthType auth_type,
                             const std::u16string& auth_value) = 0;

    // Returns the authentication type used for a user.
    virtual proximity_auth::mojom::AuthType GetAuthType(
        const AccountId& account_id) const = 0;

    // Returns the type of the screen -- a signin or a lock screen.
    virtual ScreenType GetScreenType() const = 0;

    // Unlocks from easy unlock app for a user.
    virtual void Unlock(const AccountId& account_id) = 0;

   protected:
    virtual ~LockHandler() {}
  };

  class Observer {
   public:
    // Invoked after the screen is locked.
    virtual void OnScreenDidLock() = 0;

    // Invoked after the screen lock is dismissed.
    virtual void OnScreenDidUnlock() = 0;

    // Invoked when the user focused on the lock screen changes.
    virtual void OnFocusedUserChanged(const AccountId& account_id) {}

   protected:
    virtual ~Observer() {}
  };

  static ScreenlockBridge* Get();

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

  void SetLockHandler(LockHandler* lock_handler);
  void SetFocusedUser(const AccountId& account_id);

  bool IsLocked() const;
  void Lock();

  // Unlocks the screen for the authenticated user with the given |user_id|.
  void Unlock(const AccountId& account_id);

  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

  LockHandler* lock_handler() { return lock_handler_; }

  const AccountId& focused_account_id() const { return focused_account_id_; }

 private:
  friend struct base::LazyInstanceTraitsBase<ScreenlockBridge>;
  friend std::default_delete<ScreenlockBridge>;

  ScreenlockBridge();
  ~ScreenlockBridge();

  raw_ptr<LockHandler> lock_handler_ = nullptr;  // Not owned

  // The last focused user's id.
  AccountId focused_account_id_;
  base::ObserverList<Observer, true>::Unchecked observers_;
};

}  // namespace proximity_auth

#endif  // CHROMEOS_ASH_COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_