Unwind the URL-based experiment IDs.
[chromium-blink-merge.git] / chrome / browser / signin / easy_unlock_auth_attempt.h
blob18bc9afa722751a9a6a7eee5c1b1dddb1d11e281
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_AUTH_ATTEMPT_H_
6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_AUTH_ATTEMPT_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/macros.h"
13 class EasyUnlockAppManager;
15 // 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 // which notifies the easy unlock app about auth attempt. When the auth result
18 // is available, |FinalizeUnlock| or |FinalizeSignin| should be called,
19 // depending on auth type.
20 // To cancel the in progress auth attempt, delete the |EasyUnlockAuthAttempt|
21 // object.
22 class EasyUnlockAuthAttempt {
23 public:
24 // The auth type.
25 enum Type {
26 TYPE_UNLOCK,
27 TYPE_SIGNIN
30 // 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 // 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 typedef base::Callback<void(Type auth_attempt_type,
35 bool success,
36 const std::string& user_id,
37 const std::string& key_secret,
38 const std::string& key_label)>
39 FinalizedCallback;
41 EasyUnlockAuthAttempt(EasyUnlockAppManager* app_manager,
42 const std::string& user_id,
43 Type type,
44 const FinalizedCallback& finalized_callback);
45 ~EasyUnlockAuthAttempt();
47 // Starts the auth attempt by sending screenlockPrivate.onAuthAttempted event
48 // to easy unlock app. Returns whether the event was successfully dispatched.
49 bool Start();
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
53 // failure equivalent to cancelling the attempt.
54 void FinalizeUnlock(const std::string& user_id, bool success);
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
58 // fails the signin attempt.
59 // If called on an object with TYPE_UNLOCK type, it will cause unlock failure
60 // equivalent to cancelling the request.
61 void FinalizeSignin(const std::string& user_id,
62 const std::string& wrapped_secret,
63 const std::string& session_key);
65 private:
66 // The internal attempt state.
67 enum State {
68 STATE_IDLE,
69 STATE_RUNNING,
70 STATE_DONE
73 // Cancels the attempt.
74 void Cancel(const std::string& user_id);
76 EasyUnlockAppManager* app_manager_;
77 State state_;
78 std::string user_id_;
79 Type type_;
81 FinalizedCallback finalized_callback_;
83 DISALLOW_COPY_AND_ASSIGN(EasyUnlockAuthAttempt);
86 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_AUTH_ATTEMPT_H_