Chromium Code Reviews| 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_AUTH_ATTEMPT_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_AUTH_ATTEMPT_H_ |
| 6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_AUTH_ATTEMPT_H_ | 6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_AUTH_ATTEMPT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "components/signin/core/account_id/account_id.h" | |
| 12 | 13 |
| 13 class EasyUnlockAppManager; | 14 class EasyUnlockAppManager; |
| 14 | 15 |
| 15 // Class responsible for handling easy unlock auth attempts (both for unlocking | 16 // Class responsible for handling easy unlock auth attempts (both for unlocking |
| 16 // the screen and logging in). The auth protocol is started by calling |Start|, | 17 // the screen and logging in). The auth protocol is started by calling |Start|, |
| 17 // which notifies the easy unlock app about auth attempt. When the auth result | 18 // which notifies the easy unlock app about auth attempt. When the auth result |
| 18 // is available, |FinalizeUnlock| or |FinalizeSignin| should be called, | 19 // is available, |FinalizeUnlock| or |FinalizeSignin| should be called, |
| 19 // depending on auth type. | 20 // depending on auth type. |
| 20 // To cancel the in progress auth attempt, delete the |EasyUnlockAuthAttempt| | 21 // To cancel the in progress auth attempt, delete the |EasyUnlockAuthAttempt| |
| 21 // object. | 22 // object. |
| 22 class EasyUnlockAuthAttempt { | 23 class EasyUnlockAuthAttempt { |
| 23 public: | 24 public: |
| 24 // The auth type. | 25 // The auth type. |
| 25 enum Type { | 26 enum Type { |
| 26 TYPE_UNLOCK, | 27 TYPE_UNLOCK, |
| 27 TYPE_SIGNIN | 28 TYPE_SIGNIN |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 // A callback to be invoked after the auth attempt is finalized. |success| | 31 // A callback to be invoked after the auth attempt is finalized. |success| |
| 31 // indicates whether the attempt is successful or not. |user_id| is the | 32 // indicates whether the attempt is successful or not. |account_id| is the |
| 32 // associated user. |key_secret| is the user secret for a sign-in attempt | 33 // associated user. |key_secret| is the user secret for a sign-in attempt |
| 33 // and |key_label| is the label of the corresponding cryptohome key. | 34 // and |key_label| is the label of the corresponding cryptohome key. |
| 34 typedef base::Callback<void(Type auth_attempt_type, | 35 typedef base::Callback<void(Type auth_attempt_type, |
| 35 bool success, | 36 bool success, |
| 36 const std::string& user_id, | 37 const AccountId& account_id, |
| 37 const std::string& key_secret, | 38 const std::string& key_secret, |
| 38 const std::string& key_label)> | 39 const std::string& key_label)> FinalizedCallback; |
| 39 FinalizedCallback; | |
| 40 | 40 |
| 41 EasyUnlockAuthAttempt(EasyUnlockAppManager* app_manager, | 41 EasyUnlockAuthAttempt(EasyUnlockAppManager* app_manager, |
| 42 const std::string& user_id, | 42 const AccountId& account_id, |
| 43 Type type, | 43 Type type, |
| 44 const FinalizedCallback& finalized_callback); | 44 const FinalizedCallback& finalized_callback); |
| 45 ~EasyUnlockAuthAttempt(); | 45 ~EasyUnlockAuthAttempt(); |
| 46 | 46 |
| 47 // Starts the auth attempt by sending screenlockPrivate.onAuthAttempted event | 47 // Starts the auth attempt by sending screenlockPrivate.onAuthAttempted event |
| 48 // to easy unlock app. Returns whether the event was successfully dispatched. | 48 // to easy unlock app. Returns whether the event was successfully dispatched. |
| 49 bool Start(); | 49 bool Start(); |
| 50 | 50 |
| 51 // Finalizes an unlock attempt. It unlocks the screen if |success| is true. | 51 // Finalizes an unlock attempt. It unlocks the screen if |success| is true. |
| 52 // If |this| has TYPE_SIGNIN type, calling this method will cause signin | 52 // If |this| has TYPE_SIGNIN type, calling this method will cause signin |
| 53 // failure equivalent to cancelling the attempt. | 53 // failure equivalent to cancelling the attempt. |
| 54 void FinalizeUnlock(const std::string& user_id, bool success); | 54 void FinalizeUnlock(const AccountId& account_id, bool success); |
| 55 | 55 |
| 56 // Finalizes signin attempt. It tries to log in using the secret derived from | 56 // Finalizes signin attempt. It tries to log in using the secret derived from |
| 57 // |wrapped_secret| decrypted by |session_key|. If the decryption fails, it | 57 // |wrapped_secret| decrypted by |session_key|. If the decryption fails, it |
| 58 // fails the signin attempt. | 58 // fails the signin attempt. |
| 59 // If called on an object with TYPE_UNLOCK type, it will cause unlock failure | 59 // If called on an object with TYPE_UNLOCK type, it will cause unlock failure |
| 60 // equivalent to cancelling the request. | 60 // equivalent to cancelling the request. |
| 61 void FinalizeSignin(const std::string& user_id, | 61 void FinalizeSignin(const AccountId& account_id, |
| 62 const std::string& wrapped_secret, | 62 const std::string& wrapped_secret, |
| 63 const std::string& session_key); | 63 const std::string& session_key); |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 // The internal attempt state. | 66 // The internal attempt state. |
| 67 enum State { | 67 enum State { |
| 68 STATE_IDLE, | 68 STATE_IDLE, |
| 69 STATE_RUNNING, | 69 STATE_RUNNING, |
| 70 STATE_DONE | 70 STATE_DONE |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // Cancels the attempt. | 73 // Cancels the attempt. |
| 74 void Cancel(const std::string& user_id); | 74 void Cancel(const AccountId& account_id); |
| 75 | 75 |
| 76 EasyUnlockAppManager* app_manager_; | 76 EasyUnlockAppManager* app_manager_; |
| 77 State state_; | 77 State state_; |
| 78 std::string user_id_; | 78 AccountId account_id_; |
|
achuithb
2015/12/04 10:12:53
const?
Alexander Alekseev
2015/12/04 12:44:06
Done.
| |
| 79 Type type_; | 79 Type type_; |
| 80 | 80 |
| 81 FinalizedCallback finalized_callback_; | 81 FinalizedCallback finalized_callback_; |
| 82 | 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(EasyUnlockAuthAttempt); | 83 DISALLOW_COPY_AND_ASSIGN(EasyUnlockAuthAttempt); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_AUTH_ATTEMPT_H_ | 86 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_AUTH_ATTEMPT_H_ |
| OLD | NEW |