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 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 17 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
18 #include "chrome/common/net/gaia/google_service_auth_error.h" | 18 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 19 #include "content/common/notification_observer.h" |
| 20 #include "content/common/notification_registrar.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 : public GaiaAuthConsumer , public NotificationObserver { |
37 public: | 39 public: |
38 SigninManager(); | 40 SigninManager(); |
39 virtual ~SigninManager(); | 41 virtual ~SigninManager(); |
40 | 42 |
41 // Call to register our prefs. | 43 // Call to register our prefs. |
42 static void RegisterUserPrefs(PrefService* user_prefs); | 44 static void RegisterUserPrefs(PrefService* user_prefs); |
43 | 45 |
44 // If user was signed in, load tokens from DB if available. | 46 // If user was signed in, load tokens from DB if available. |
45 void Initialize(Profile* profile); | 47 void Initialize(Profile* profile); |
46 | 48 |
(...skipping 21 matching lines...) Expand all Loading... |
68 void SignOut(); | 70 void SignOut(); |
69 | 71 |
70 // GaiaAuthConsumer | 72 // GaiaAuthConsumer |
71 virtual void OnClientLoginSuccess(const ClientLoginResult& result); | 73 virtual void OnClientLoginSuccess(const ClientLoginResult& result); |
72 virtual void OnClientLoginFailure(const GoogleServiceAuthError& error); | 74 virtual void OnClientLoginFailure(const GoogleServiceAuthError& error); |
73 virtual void OnGetUserInfoSuccess(const std::string& key, | 75 virtual void OnGetUserInfoSuccess(const std::string& key, |
74 const std::string& value); | 76 const std::string& value); |
75 virtual void OnGetUserInfoKeyNotFound(const std::string& key); | 77 virtual void OnGetUserInfoKeyNotFound(const std::string& key); |
76 virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error); | 78 virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error); |
77 | 79 |
| 80 // NotificationObserver |
| 81 virtual void Observe(NotificationType type, |
| 82 const NotificationSource& source, |
| 83 const NotificationDetails& details) OVERRIDE; |
| 84 |
78 private: | 85 private: |
79 Profile* profile_; | 86 Profile* profile_; |
80 std::string username_; | 87 std::string username_; |
81 std::string password_; // This is kept empty whenever possible. | 88 std::string password_; // This is kept empty whenever possible. |
82 bool had_two_factor_error_; | 89 bool had_two_factor_error_; |
83 | 90 |
84 // Result of the last client login, kept pending the lookup of the | 91 // Result of the last client login, kept pending the lookup of the |
85 // canonical email. | 92 // canonical email. |
86 ClientLoginResult last_result_; | 93 ClientLoginResult last_result_; |
87 | 94 |
88 // Actual client login handler. | 95 // Actual client login handler. |
89 scoped_ptr<GaiaAuthFetcher> client_login_; | 96 scoped_ptr<GaiaAuthFetcher> client_login_; |
| 97 |
| 98 // Register for notifications from the TokenService. |
| 99 NotificationRegistrar registrar_; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(SigninManager); |
90 }; | 102 }; |
91 | 103 |
92 #endif // CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ | 104 #endif // CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ |
OLD | NEW |