| 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 CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ | 6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
| 14 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class DictionaryValue; | 18 class DictionaryValue; |
| 18 class ListValue; | 19 class ListValue; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace user_prefs { | 22 namespace user_prefs { |
| 22 class PrefRegistrySyncable; | 23 class PrefRegistrySyncable; |
| 23 } | 24 } |
| 24 | 25 |
| 25 class EasyUnlockScreenlockStateHandler; | 26 class EasyUnlockAuthAttempt; |
| 26 class EasyUnlockServiceObserver; | 27 class EasyUnlockServiceObserver; |
| 27 class Profile; | 28 class Profile; |
| 28 | 29 |
| 29 class EasyUnlockService : public KeyedService { | 30 class EasyUnlockService : public KeyedService { |
| 30 public: | 31 public: |
| 31 enum TurnOffFlowStatus { | 32 enum TurnOffFlowStatus { |
| 32 IDLE, | 33 IDLE, |
| 33 PENDING, | 34 PENDING, |
| 34 FAIL, | 35 FAIL, |
| 35 }; | 36 }; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 66 | 67 |
| 67 // Runs the flow for turning Easy unlock off. | 68 // Runs the flow for turning Easy unlock off. |
| 68 virtual void RunTurnOffFlow() = 0; | 69 virtual void RunTurnOffFlow() = 0; |
| 69 | 70 |
| 70 // Resets the turn off flow if one is in progress. | 71 // Resets the turn off flow if one is in progress. |
| 71 virtual void ResetTurnOffFlow() = 0; | 72 virtual void ResetTurnOffFlow() = 0; |
| 72 | 73 |
| 73 // Returns the current turn off flow status. | 74 // Returns the current turn off flow status. |
| 74 virtual TurnOffFlowStatus GetTurnOffFlowStatus() const = 0; | 75 virtual TurnOffFlowStatus GetTurnOffFlowStatus() const = 0; |
| 75 | 76 |
| 76 // Gets the challenge bytes for the currently associated user. | 77 // Gets the challenge bytes for the user currently associated with the |
| 78 // service. |
| 77 virtual std::string GetChallenge() const = 0; | 79 virtual std::string GetChallenge() const = 0; |
| 78 | 80 |
| 79 // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not | 81 // Retrieved wrapped secret that should be used to unlock cryptohome for the |
| 80 // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance | 82 // user currently associated with the service. If the service does not support |
| 81 // is created. Do not cache the returned value, as it may go away if Easy | 83 // signin (i.e. service for a regular profile) or there is no secret available |
| 82 // Unlock gets disabled. | 84 // for the user, returns an empty string. |
| 83 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(); | 85 virtual std::string GetWrappedSecret() const = 0; |
| 84 | 86 |
| 85 // Whether easy unlock is allowed to be used. If the controlling preference | 87 // Whether easy unlock is allowed to be used. If the controlling preference |
| 86 // is set (from policy), this returns the preference value. Otherwise, it is | 88 // is set (from policy), this returns the preference value. Otherwise, it is |
| 87 // permitted either the flag is enabled or its field trial is enabled. | 89 // permitted either the flag is enabled or its field trial is enabled. |
| 88 bool IsAllowed(); | 90 bool IsAllowed(); |
| 89 | 91 |
| 92 // Updates the user pod on the signin/lock screen for the user associated with |
| 93 // the service to reflect the provided screenlock state. |
| 94 bool UpdateScreenlockState(EasyUnlockScreenlockStateHandler::State state); |
| 95 |
| 96 // Starts an auth attempt for the user associated with the service. The |
| 97 // attempt type (unlock vs. signin) will depend on the service type. |
| 98 void AttemptAuth(const std::string& user_id); |
| 99 |
| 100 // Finalizes the previously started auth attempt for easy unlock. If called on |
| 101 // signin profile service, it will cancel the current auth attempt if one |
| 102 // exists. |
| 103 void FinalizeUnlock(bool success); |
| 104 |
| 105 // Finalizes previously started auth attempt for easy signin. If called on |
| 106 // regular profile service, it will cancel the current auth attempt if one |
| 107 // exists. |
| 108 void FinalizeSignin(const std::string& secret); |
| 109 |
| 90 void AddObserver(EasyUnlockServiceObserver* observer); | 110 void AddObserver(EasyUnlockServiceObserver* observer); |
| 91 void RemoveObserver(EasyUnlockServiceObserver* observer); | 111 void RemoveObserver(EasyUnlockServiceObserver* observer); |
| 92 | 112 |
| 93 protected: | 113 protected: |
| 94 explicit EasyUnlockService(Profile* profile); | 114 explicit EasyUnlockService(Profile* profile); |
| 95 virtual ~EasyUnlockService(); | 115 virtual ~EasyUnlockService(); |
| 96 | 116 |
| 97 // Does a service type specific initialization. | 117 // Does a service type specific initialization. |
| 98 virtual void InitializeInternal() = 0; | 118 virtual void InitializeInternal() = 0; |
| 99 | 119 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 126 | 146 |
| 127 // Checks whether Easy unlock should be running and updates app state. | 147 // Checks whether Easy unlock should be running and updates app state. |
| 128 void UpdateAppState(); | 148 void UpdateAppState(); |
| 129 | 149 |
| 130 // Notifies the easy unlock app that the user state has been updated. | 150 // Notifies the easy unlock app that the user state has been updated. |
| 131 void NotifyUserUpdated(); | 151 void NotifyUserUpdated(); |
| 132 | 152 |
| 133 // Notifies observers that the turn off flow status changed. | 153 // Notifies observers that the turn off flow status changed. |
| 134 void NotifyTurnOffOperationStatusChanged(); | 154 void NotifyTurnOffOperationStatusChanged(); |
| 135 | 155 |
| 136 // Resets |screenlock_state_handler_|. | 156 // Resets the screenlock state set by this service. |
| 137 void ResetScreenlockStateHandler(); | 157 void ResetScreenlockState(); |
| 138 | 158 |
| 139 private: | 159 private: |
| 140 // A class to detect whether a bluetooth adapter is present. | 160 // A class to detect whether a bluetooth adapter is present. |
| 141 class BluetoothDetector; | 161 class BluetoothDetector; |
| 142 | 162 |
| 143 // Initializes the service after ExtensionService is ready. | 163 // Initializes the service after ExtensionService is ready. |
| 144 void Initialize(); | 164 void Initialize(); |
| 145 | 165 |
| 166 // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not |
| 167 // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance |
| 168 // is created. Do not cache the returned value, as it may go away if Easy |
| 169 // Unlock gets disabled. |
| 170 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(); |
| 171 |
| 146 // Callback when Bluetooth adapter present state changes. | 172 // Callback when Bluetooth adapter present state changes. |
| 147 void OnBluetoothAdapterPresentChanged(); | 173 void OnBluetoothAdapterPresentChanged(); |
| 148 | 174 |
| 149 Profile* profile_; | 175 Profile* profile_; |
| 150 | 176 |
| 151 // Created lazily in |GetScreenlockStateHandler|. | 177 // Created lazily in |GetScreenlockStateHandler|. |
| 152 scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_; | 178 scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_; |
| 153 | 179 |
| 180 // The handler for the current auth attempt. Set iff an auth attempt is in |
| 181 // progress. |
| 182 scoped_ptr<EasyUnlockAuthAttempt> auth_attempt_; |
| 183 |
| 154 scoped_ptr<BluetoothDetector> bluetooth_detector_; | 184 scoped_ptr<BluetoothDetector> bluetooth_detector_; |
| 155 | 185 |
| 156 #if defined(OS_CHROMEOS) | 186 #if defined(OS_CHROMEOS) |
| 157 // Monitors suspend and wake state of ChromeOS. | 187 // Monitors suspend and wake state of ChromeOS. |
| 158 class PowerMonitor; | 188 class PowerMonitor; |
| 159 scoped_ptr<PowerMonitor> power_monitor_; | 189 scoped_ptr<PowerMonitor> power_monitor_; |
| 160 #endif | 190 #endif |
| 161 | 191 |
| 162 // Whether the service has been shut down. | 192 // Whether the service has been shut down. |
| 163 bool shut_down_; | 193 bool shut_down_; |
| 164 | 194 |
| 165 ObserverList<EasyUnlockServiceObserver> observers_; | 195 ObserverList<EasyUnlockServiceObserver> observers_; |
| 166 | 196 |
| 167 base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_; | 197 base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_; |
| 168 | 198 |
| 169 DISALLOW_COPY_AND_ASSIGN(EasyUnlockService); | 199 DISALLOW_COPY_AND_ASSIGN(EasyUnlockService); |
| 170 }; | 200 }; |
| 171 | 201 |
| 172 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ | 202 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ |
| OLD | NEW |