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/user_manager/user_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. |user_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 user_manager::UserID& user_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)> |
39 FinalizedCallback; | 40 FinalizedCallback; |
40 | 41 |
41 EasyUnlockAuthAttempt(EasyUnlockAppManager* app_manager, | 42 EasyUnlockAuthAttempt(EasyUnlockAppManager* app_manager, |
42 const std::string& user_id, | 43 const user_manager::UserID& user_id, |
43 Type type, | 44 Type type, |
44 const FinalizedCallback& finalized_callback); | 45 const FinalizedCallback& finalized_callback); |
45 ~EasyUnlockAuthAttempt(); | 46 ~EasyUnlockAuthAttempt(); |
46 | 47 |
47 // Starts the auth attempt by sending screenlockPrivate.onAuthAttempted event | 48 // Starts the auth attempt by sending screenlockPrivate.onAuthAttempted event |
48 // to easy unlock app. Returns whether the event was successfully dispatched. | 49 // to easy unlock app. Returns whether the event was successfully dispatched. |
49 bool Start(); | 50 bool Start(); |
50 | 51 |
51 // Finalizes an unlock attempt. It unlocks the screen if |success| is true. | 52 // 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 | 53 // If |this| has TYPE_SIGNIN type, calling this method will cause signin |
53 // failure equivalent to cancelling the attempt. | 54 // failure equivalent to cancelling the attempt. |
54 void FinalizeUnlock(const std::string& user_id, bool success); | 55 void FinalizeUnlock(const user_manager::UserID& user_id, bool success); |
55 | 56 |
56 // Finalizes signin attempt. It tries to log in using the secret derived from | 57 // 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 | 58 // |wrapped_secret| decrypted by |session_key|. If the decryption fails, it |
58 // fails the signin attempt. | 59 // fails the signin attempt. |
59 // If called on an object with TYPE_UNLOCK type, it will cause unlock failure | 60 // If called on an object with TYPE_UNLOCK type, it will cause unlock failure |
60 // equivalent to cancelling the request. | 61 // equivalent to cancelling the request. |
61 void FinalizeSignin(const std::string& user_id, | 62 void FinalizeSignin(const user_manager::UserID& user_id, |
62 const std::string& wrapped_secret, | 63 const std::string& wrapped_secret, |
63 const std::string& session_key); | 64 const std::string& session_key); |
64 | 65 |
65 private: | 66 private: |
66 // The internal attempt state. | 67 // The internal attempt state. |
67 enum State { | 68 enum State { |
68 STATE_IDLE, | 69 STATE_IDLE, |
69 STATE_RUNNING, | 70 STATE_RUNNING, |
70 STATE_DONE | 71 STATE_DONE |
71 }; | 72 }; |
72 | 73 |
73 // Cancels the attempt. | 74 // Cancels the attempt. |
74 void Cancel(const std::string& user_id); | 75 void Cancel(const user_manager::UserID& user_id); |
75 | 76 |
76 EasyUnlockAppManager* app_manager_; | 77 EasyUnlockAppManager* app_manager_; |
77 State state_; | 78 State state_; |
78 std::string user_id_; | 79 user_manager::UserID user_id_; |
79 Type type_; | 80 Type type_; |
80 | 81 |
81 FinalizedCallback finalized_callback_; | 82 FinalizedCallback finalized_callback_; |
82 | 83 |
83 DISALLOW_COPY_AND_ASSIGN(EasyUnlockAuthAttempt); | 84 DISALLOW_COPY_AND_ASSIGN(EasyUnlockAuthAttempt); |
84 }; | 85 }; |
85 | 86 |
86 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_AUTH_ATTEMPT_H_ | 87 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_AUTH_ATTEMPT_H_ |
OLD | NEW |