OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // The signin manager encapsulates some functionality tracking | 5 // The signin manager encapsulates some functionality tracking |
6 // which user is signed in. When a user is signed in, a ClientLogin | 6 // which user is signed in. When a user is signed in, a ClientLogin |
7 // request is run on their behalf. Auth tokens are fetched from Google | 7 // request is run on their behalf. Auth tokens are fetched from Google |
8 // and the results are stored in the TokenService. | 8 // and the results are stored in the TokenService. |
9 | 9 |
10 #ifndef CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ | 10 #ifndef CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ |
11 #define CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ | 11 #define CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ |
12 #pragma once | 12 #pragma once |
13 | 13 |
14 #include <string> | 14 #include <string> |
| 15 |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
17 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 18 #include "chrome/common/net/gaia/authentication_consumer.h" |
| 19 #include "chrome/common/net/gaia/authentication_fetcher.h" |
18 #include "chrome/common/net/gaia/google_service_auth_error.h" | 20 #include "chrome/common/net/gaia/google_service_auth_error.h" |
19 | 21 |
20 class GaiaAuthFetcher; | 22 class GaiaAuthFetcher; |
21 class Profile; | 23 class Profile; |
22 class PrefService; | 24 class PrefService; |
23 | 25 |
24 // Details for the Notification type GOOGLE_SIGNIN_SUCCESSFUL. | 26 // Details for the Notification type GOOGLE_SIGNIN_SUCCESSFUL. |
25 // A listener might use this to make note of a username / password | 27 // A listener might use this to make note of a username / password |
26 // pair for encryption keys. | 28 // pair for encryption keys. |
27 struct GoogleServiceSigninSuccessDetails { | 29 struct GoogleServiceSigninSuccessDetails { |
28 GoogleServiceSigninSuccessDetails(const std::string& in_username, | 30 GoogleServiceSigninSuccessDetails(const std::string& in_username, |
29 const std::string& in_password) | 31 const std::string& in_password) |
30 : username(in_username), | 32 : username(in_username), |
31 password(in_password) {} | 33 password(in_password) {} |
32 std::string username; | 34 std::string username; |
33 std::string password; | 35 std::string password; |
34 }; | 36 }; |
35 | 37 |
36 class SigninManager : public GaiaAuthConsumer { | 38 class SigninManager { |
37 public: | 39 public: |
38 SigninManager(); | 40 static const char* kClientLoginVariant; |
| 41 static const char* kOAuthVariant; |
| 42 |
| 43 static SigninManager* CreateSigninManager(); |
| 44 |
| 45 static SigninManager* CreateSigninManager(const std::string& variant); |
| 46 |
39 virtual ~SigninManager(); | 47 virtual ~SigninManager(); |
40 | 48 |
41 // Call to register our prefs. | 49 // Call to register our prefs. |
42 static void RegisterUserPrefs(PrefService* user_prefs); | 50 static void RegisterUserPrefs(PrefService* user_prefs); |
43 | 51 |
44 // If user was signed in, load tokens from DB if available. | 52 // If user was signed in, load tokens from DB if available. |
45 void Initialize(Profile* profile); | 53 virtual void Initialize(Profile* profile) = 0; |
46 | 54 |
47 // If a user is signed in, this will return their name. | 55 // If a user is signed in, this will return their name. |
48 // Otherwise, it will return an empty string. | 56 // Otherwise, it will return an empty string. |
49 const std::string& GetUsername(); | 57 const std::string& GetUsername(); |
50 | 58 |
51 // Sets the user name. Used for migrating credentials from previous system. | 59 // Sets the user name. Used for migrating credentials from previous system. |
52 void SetUsername(const std::string& username); | 60 void SetUsername(const std::string& username); |
53 | 61 |
54 // Attempt to sign in this user. If successful, set a preference indicating | 62 // Attempt to sign in this user. If successful, set a preference indicating |
55 // the signed in user and send out a notification, then start fetching tokens | 63 // the signed in user and send out a notification, then start fetching tokens |
56 // for the user. | 64 // for the user. |
57 void StartSignIn(const std::string& username, | 65 virtual void StartSignIn(const std::string& username, |
58 const std::string& password, | 66 const std::string& password, |
59 const std::string& login_token, | 67 const std::string& login_token, |
60 const std::string& login_captcha); | 68 const std::string& login_captcha) = 0; |
61 | 69 |
62 // Used when a second factor access code was required to complete a signin | 70 // Used when a second factor access code was required to complete a signin |
63 // attempt. | 71 // attempt. |
64 void ProvideSecondFactorAccessCode(const std::string& access_code); | 72 virtual void ProvideSecondFactorAccessCode( |
| 73 const std::string& access_code) = 0; |
65 | 74 |
66 // Sign a user out, removing the preference, erasing all keys | 75 // Sign a user out, removing the preference, erasing all keys |
67 // associated with the user, and canceling all auth in progress. | 76 // associated with the user, and canceling all auth in progress. |
68 void SignOut(); | 77 virtual void SignOut() = 0; |
69 | 78 |
70 // GaiaAuthConsumer | 79 protected: |
71 virtual void OnClientLoginSuccess(const ClientLoginResult& result); | 80 SigninManager(); |
72 virtual void OnClientLoginFailure(const GoogleServiceAuthError& error); | |
73 virtual void OnGetUserInfoSuccess(const std::string& key, | |
74 const std::string& value); | |
75 virtual void OnGetUserInfoKeyNotFound(const std::string& key); | |
76 virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error); | |
77 | 81 |
78 private: | |
79 Profile* profile_; | 82 Profile* profile_; |
80 std::string username_; | 83 std::string username_; |
81 std::string password_; // This is kept empty whenever possible. | 84 std::string password_; // This is kept empty whenever possible. |
82 bool had_two_factor_error_; | 85 bool had_two_factor_error_; |
83 | 86 |
84 // Result of the last client login, kept pending the lookup of the | 87 // Result of the last client login, kept pending the lookup of the |
85 // canonical email. | 88 // canonical email. |
86 ClientLoginResult last_result_; | 89 scoped_ptr<AuthenticationConsumer::AuthenticationResult> last_result_; |
87 | 90 |
88 // Actual client login handler. | 91 // Actual authentication handler. |
89 scoped_ptr<GaiaAuthFetcher> client_login_; | 92 scoped_ptr<AuthenticationFetcher> fetcher_; |
90 }; | 93 }; |
91 | 94 |
92 #endif // CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ | 95 #endif // CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ |
OLD | NEW |