| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H | 6 #define COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time/clock.h" |
| 13 #include "components/cryptauth/remote_device.h" | 14 #include "components/cryptauth/remote_device.h" |
| 14 #include "components/proximity_auth/remote_device_life_cycle.h" | 15 #include "components/proximity_auth/remote_device_life_cycle.h" |
| 15 #include "components/proximity_auth/screenlock_bridge.h" | 16 #include "components/proximity_auth/screenlock_bridge.h" |
| 16 #include "components/signin/core/account_id/account_id.h" | 17 #include "components/signin/core/account_id/account_id.h" |
| 17 | 18 |
| 18 namespace proximity_auth { | 19 namespace proximity_auth { |
| 19 | 20 |
| 20 class ProximityAuthClient; | 21 class ProximityAuthClient; |
| 22 class ProximityAuthPrefManager; |
| 21 class RemoteDeviceLifeCycle; | 23 class RemoteDeviceLifeCycle; |
| 22 class UnlockManager; | 24 class UnlockManager; |
| 23 | 25 |
| 24 // This is the main entry point to start Proximity Auth, the underlying system | 26 // This is the main entry point to start Proximity Auth, the underlying system |
| 25 // for the Smart Lock feature. Given a list of remote devices (i.e. a | 27 // for the Smart Lock feature. Given a list of remote devices (i.e. a |
| 26 // phone) for each registered user, the system will handle the connection, | 28 // phone) for each registered user, the system will handle the connection, |
| 27 // authentication, and messenging protocol when the screen is locked and the | 29 // authentication, and messenging protocol when the screen is locked and the |
| 28 // registered user is focused. | 30 // registered user is focused. |
| 29 class ProximityAuthSystem : public RemoteDeviceLifeCycle::Observer, | 31 class ProximityAuthSystem : public RemoteDeviceLifeCycle::Observer, |
| 30 public ScreenlockBridge::Observer { | 32 public ScreenlockBridge::Observer { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 void OnSuspend(); | 64 void OnSuspend(); |
| 63 | 65 |
| 64 // Called when the system wakes up from a suspended state. | 66 // Called when the system wakes up from a suspended state. |
| 65 void OnSuspendDone(); | 67 void OnSuspendDone(); |
| 66 | 68 |
| 67 protected: | 69 protected: |
| 68 // Constructor which allows passing in a custom |unlock_manager_|. | 70 // Constructor which allows passing in a custom |unlock_manager_|. |
| 69 // Exposed for testing. | 71 // Exposed for testing. |
| 70 ProximityAuthSystem(ScreenlockType screenlock_type, | 72 ProximityAuthSystem(ScreenlockType screenlock_type, |
| 71 ProximityAuthClient* proximity_auth_client, | 73 ProximityAuthClient* proximity_auth_client, |
| 72 std::unique_ptr<UnlockManager> unlock_manager); | 74 std::unique_ptr<UnlockManager> unlock_manager, |
| 75 std::unique_ptr<base::Clock> clock, |
| 76 std::unique_ptr<ProximityAuthPrefManager> pref_manager); |
| 73 | 77 |
| 74 // Creates the RemoteDeviceLifeCycle for |remote_device|. | 78 // Creates the RemoteDeviceLifeCycle for |remote_device|. |
| 75 // Exposed for testing. | 79 // Exposed for testing. |
| 76 virtual std::unique_ptr<RemoteDeviceLifeCycle> CreateRemoteDeviceLifeCycle( | 80 virtual std::unique_ptr<RemoteDeviceLifeCycle> CreateRemoteDeviceLifeCycle( |
| 77 const cryptauth::RemoteDevice& remote_device); | 81 const cryptauth::RemoteDevice& remote_device); |
| 78 | 82 |
| 79 // RemoteDeviceLifeCycle::Observer: | 83 // RemoteDeviceLifeCycle::Observer: |
| 80 void OnLifeCycleStateChanged(RemoteDeviceLifeCycle::State old_state, | 84 void OnLifeCycleStateChanged(RemoteDeviceLifeCycle::State old_state, |
| 81 RemoteDeviceLifeCycle::State new_state) override; | 85 RemoteDeviceLifeCycle::State new_state) override; |
| 82 | 86 |
| 83 // ScreenlockBridge::Observer: | 87 // ScreenlockBridge::Observer: |
| 84 void OnScreenDidLock( | 88 void OnScreenDidLock( |
| 85 ScreenlockBridge::LockHandler::ScreenType screen_type) override; | 89 ScreenlockBridge::LockHandler::ScreenType screen_type) override; |
| 86 void OnScreenDidUnlock( | 90 void OnScreenDidUnlock( |
| 87 ScreenlockBridge::LockHandler::ScreenType screen_type) override; | 91 ScreenlockBridge::LockHandler::ScreenType screen_type) override; |
| 88 void OnFocusedUserChanged(const AccountId& account_id) override; | 92 void OnFocusedUserChanged(const AccountId& account_id) override; |
| 89 | 93 |
| 90 private: | 94 private: |
| 91 // Resumes |remote_device_life_cycle_| after device wakes up and waits a | 95 // Resumes |remote_device_life_cycle_| after device wakes up and waits a |
| 92 // timeout. | 96 // timeout. |
| 93 void ResumeAfterWakeUpTimeout(); | 97 void ResumeAfterWakeUpTimeout(); |
| 94 | 98 |
| 99 // Returns true if the user should be forced to use a password to authenticate |
| 100 // rather than EasyUnlock. |
| 101 bool ShouldForcePassword(); |
| 102 |
| 95 // Lists of remote devices, keyed by user account id. | 103 // Lists of remote devices, keyed by user account id. |
| 96 std::map<AccountId, cryptauth::RemoteDeviceList> remote_devices_map_; | 104 std::map<AccountId, cryptauth::RemoteDeviceList> remote_devices_map_; |
| 97 | 105 |
| 98 // Delegate for Chrome dependent functionality. | 106 // Delegate for Chrome dependent functionality. |
| 99 ProximityAuthClient* proximity_auth_client_; | 107 ProximityAuthClient* proximity_auth_client_; |
| 100 | 108 |
| 101 // Responsible for the life cycle of connecting and authenticating to | 109 // Responsible for the life cycle of connecting and authenticating to |
| 102 // the RemoteDevice of the currently focused user. | 110 // the RemoteDevice of the currently focused user. |
| 103 std::unique_ptr<RemoteDeviceLifeCycle> remote_device_life_cycle_; | 111 std::unique_ptr<RemoteDeviceLifeCycle> remote_device_life_cycle_; |
| 104 | 112 |
| 105 // Handles the interaction with the lock screen UI. | 113 // Handles the interaction with the lock screen UI. |
| 106 std::unique_ptr<UnlockManager> unlock_manager_; | 114 std::unique_ptr<UnlockManager> unlock_manager_; |
| 107 | 115 |
| 116 // Used to get the current timestamp. |
| 117 std::unique_ptr<base::Clock> clock_; |
| 118 |
| 119 // Fetches EasyUnlock preferences. |
| 120 std::unique_ptr<ProximityAuthPrefManager> pref_manager_; |
| 121 |
| 108 // True if the system is suspended. | 122 // True if the system is suspended. |
| 109 bool suspended_; | 123 bool suspended_; |
| 110 | 124 |
| 111 // True if the system is started_. | 125 // True if the system is started_. |
| 112 bool started_; | 126 bool started_; |
| 113 | 127 |
| 114 base::WeakPtrFactory<ProximityAuthSystem> weak_ptr_factory_; | 128 base::WeakPtrFactory<ProximityAuthSystem> weak_ptr_factory_; |
| 115 | 129 |
| 116 DISALLOW_COPY_AND_ASSIGN(ProximityAuthSystem); | 130 DISALLOW_COPY_AND_ASSIGN(ProximityAuthSystem); |
| 117 }; | 131 }; |
| 118 | 132 |
| 119 } // namespace proximity_auth | 133 } // namespace proximity_auth |
| 120 | 134 |
| 121 #endif // COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H | 135 #endif // COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H |
| OLD | NEW |