OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_PROXIMITY_AUTH_UNLOCK_MANAGER_H | |
6 #define COMPONENTS_PROXIMITY_AUTH_UNLOCK_MANAGER_H | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "components/proximity_auth/client_observer.h" | |
12 #include "components/proximity_auth/controller.h" | |
13 #include "components/proximity_auth/remote_status_update.h" | |
14 #include "components/proximity_auth/screenlock_bridge.h" | |
15 #include "components/proximity_auth/screenlock_state.h" | |
16 #include "device/bluetooth/bluetooth_adapter.h" | |
17 | |
18 #if defined(OS_CHROMEOS) | |
19 #include "chromeos/dbus/power_manager_client.h" | |
20 #endif | |
21 | |
22 namespace proximity_auth { | |
23 | |
24 class Client; | |
25 class ProximityAuthClient; | |
26 class ProximityMonitor; | |
27 | |
28 // The unlock manager is responsible for controlling the lock screen UI based on | |
29 // the authentication status of the registered remote devices. | |
30 class UnlockManager : public ClientObserver, | |
31 public ScreenlockBridge::Observer, | |
32 public device::BluetoothAdapter::Observer { | |
33 public: | |
34 enum class ScreenlockType { | |
35 SESSION_LOCK, | |
36 SIGN_IN, | |
37 }; | |
38 | |
39 // The |proximity_auth_client| is not owned and should outlive the constructed | |
40 // unlock manager. | |
41 // TODO(isherman): Rather than passing a single ProximityMonitor instance, we | |
42 // should pass a factory, as the UnlockManager should create and destroy | |
43 // ProximityMonitors as needed. Currently, the expectations are misaligned | |
44 // between the ProximityMonitor and the UnlockManager classes. | |
45 UnlockManager(ScreenlockType screenlock_type, | |
46 scoped_ptr<ProximityMonitor> proximity_monitor, | |
47 ProximityAuthClient* proximity_auth_client); | |
48 ~UnlockManager() override; | |
49 | |
50 // Whether proximity-based unlocking is currently allowed. True if any one of | |
51 // the remote devices is authenticated. | |
Tim Song
2015/07/23 21:32:15
nit: and in range.
Ilya Sherman
2015/08/11 23:37:15
Done.
| |
52 bool IsUnlockAllowed(); | |
53 | |
54 // Sets the |controller| to which local events are dispatched. A null | |
55 // controller indicates that proximity-based authentication is inactive. | |
56 void SetController(Controller* controller); | |
57 | |
58 // Called when the controller's state changes to |state|. | |
Tim Song
2015/07/23 21:32:15
nit: there is no |state| argument.
Ilya Sherman
2015/08/11 23:37:15
Done.
| |
59 void OnControllerStateChanged(); | |
60 | |
61 protected: | |
62 // Called when the user pod is clicked for an authentication attempt of type | |
63 // |auth_type|. | |
64 // Exposed for testing. | |
65 void OnAuthAttempted(ScreenlockBridge::LockHandler::AuthType auth_type); | |
66 | |
67 private: | |
68 // The possible lock screen states for the remote device. | |
69 enum class RemoteScreenlockState { | |
70 UNKNOWN, | |
71 UNLOCKED, | |
72 DISABLED, | |
73 LOCKED, | |
74 }; | |
75 | |
76 // ClientObserver: | |
77 void OnUnlockEventSent(bool success) override; | |
78 void OnRemoteStatusUpdate(const RemoteStatusUpdate& status_update) override; | |
79 void OnDecryptResponse(scoped_ptr<std::string> decrypted_bytes) override; | |
80 void OnUnlockResponse(bool success) override; | |
81 void OnDisconnected() override; | |
82 | |
83 // ScreenlockBridge::Observer | |
84 void OnScreenDidLock( | |
85 ScreenlockBridge::LockHandler::ScreenType screen_type) override; | |
86 void OnScreenDidUnlock( | |
87 ScreenlockBridge::LockHandler::ScreenType screen_type) override; | |
88 void OnFocusedUserChanged(const std::string& user_id) override; | |
89 | |
90 // Called when the screenlock state changes. | |
91 void OnScreenLockStateChanged(bool is_locked); | |
92 | |
93 // Called when the Bluetooth adapter is initialized. | |
94 void OnBluetoothAdapterInitialized( | |
95 scoped_refptr<device::BluetoothAdapter> adapter); | |
96 | |
97 // device::BluetoothAdapter::Observer: | |
98 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | |
99 bool present) override; | |
100 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | |
101 bool powered) override; | |
102 | |
103 #if defined(OS_CHROMEOS) | |
104 // PowerManagerClient::Observer: | |
105 void SuspendDone(const base::TimeDelta& sleep_duration) override; | |
106 #endif // defined(OS_CHROMEOS) | |
107 | |
108 // Called when auth is attempted to send the sign-in challenge to the remote | |
109 // device for decryption. | |
110 void SendSignInChallenge(); | |
111 | |
112 // Returns the current state for the screen lock UI. | |
113 ScreenlockState GetScreenlockState(); | |
114 | |
115 // Updates the lock screen based on the manager's current state. | |
116 void UpdateLockScreen(); | |
117 | |
118 // Activates or deactivates the proximity monitor, as appropriate given the | |
119 // current state of |this| unlock manager. | |
120 void UpdateProximityMonitorState(); | |
121 | |
122 // Sets waking up state. | |
123 void SetWakingUpState(bool is_waking_up); | |
124 | |
125 // Accepts or rejects the current auth attempt according to |should_accept|. | |
126 // If the auth attempt is accepted, unlocks the screen. | |
127 void AcceptAuthAttempt(bool should_accept); | |
128 | |
129 // Returns the screen lock state corresponding to the given remote |status| | |
130 // update. | |
131 RemoteScreenlockState GetScreenlockStateFromRemoteUpdate( | |
132 RemoteStatusUpdate update); | |
133 | |
134 // Whether |this| manager is being used for sign-in or session unlock. | |
135 const ScreenlockType screenlock_type_; | |
136 | |
137 // Whether the user is present at the remote device. Unset if no remote status | |
138 // update has yet been received. | |
139 scoped_ptr<RemoteScreenlockState> remote_screenlock_state_; | |
140 | |
141 // Controls the proximity auth flow logic. Not owned, and expcted to outlive | |
142 // |this| instance. | |
143 Controller* controller_; | |
144 | |
145 // The client used to communicate with the remote device once a secure channel | |
146 // is established. Null if no secure channel has been established yet. Not | |
147 // owned, and expected to outlive |this| instance. | |
148 Client* client_; | |
149 | |
150 // Tracks whether the remote device is currently in close enough proximity to | |
151 // the local device to allow unlocking. | |
152 scoped_ptr<ProximityMonitor> proximity_monitor_; | |
153 | |
154 // Used to call into the embedder. Stored as a weak reference, and expected to | |
Tim Song
2015/07/23 21:32:15
nit: this is not stored as a weak reference.
Ilya Sherman
2015/08/11 23:37:15
Done.
| |
155 // outlive |this| instance. | |
156 ProximityAuthClient* proximity_auth_client_; | |
157 | |
158 // Whether the screen is currently locked. | |
159 bool is_locked_; | |
160 | |
161 // True if the manager is currently processing a user-initiated authentication | |
162 // attempt, which is initiated when the user pod is clicked. | |
163 bool is_attempting_auth_; | |
164 | |
165 // Whether the system is waking up from sleep. | |
166 bool is_waking_up_; | |
167 | |
168 // The Bluetooth adapter. Null if there is no adapter present on the local | |
169 // device. | |
170 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; | |
171 | |
172 // The sign-in secret received from the remote device by decrypting the | |
173 // sign-in challenge. | |
174 scoped_ptr<std::string> sign_in_secret_; | |
175 | |
176 // The state of the current screen lock UI. | |
177 ScreenlockState screenlock_state_; | |
178 | |
179 // Used to clear the waking up state after a timeout. | |
180 base::WeakPtrFactory<UnlockManager> clear_waking_up_state_weak_ptr_factory_; | |
Tim Song
2015/07/23 21:32:15
Wouldn't it be clearer to use timers instead to be
Ilya Sherman
2015/08/11 23:37:15
I tend to prefer directly posting tasks to message
| |
181 | |
182 // Used to reject auth attempts after a timeout. An in-progress auth attempt | |
183 // blocks the sign-in screen UI, so it's important to prevent the auth attempt | |
184 // from blocking the UI in case a step in the code path hangs. | |
185 base::WeakPtrFactory<UnlockManager> reject_auth_attempt_weak_ptr_factory_; | |
186 | |
187 // Used to vend all other weak pointers. | |
188 base::WeakPtrFactory<UnlockManager> weak_ptr_factory_; | |
189 | |
190 DISALLOW_COPY_AND_ASSIGN(UnlockManager); | |
191 }; | |
192 | |
193 } // namespace proximity_auth | |
194 | |
195 #endif // COMPONENTS_PROXIMITY_AUTH_UNLOCK_MANAGER_H | |
OLD | NEW |