OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_ | 4 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ |
5 #define CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_ | 5 #define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 #include <functional> | 8 #include <functional> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
19 #include "components/keyed_service/core/keyed_service.h" | 19 #include "components/keyed_service/core/keyed_service.h" |
20 #include "components/signin/core/browser/signin_manager.h" | 20 #include "components/signin/core/browser/signin_manager.h" |
21 #include "google_apis/gaia/gaia_auth_consumer.h" | 21 #include "google_apis/gaia/gaia_auth_consumer.h" |
22 #include "google_apis/gaia/google_service_auth_error.h" | 22 #include "google_apis/gaia/google_service_auth_error.h" |
23 #include "google_apis/gaia/merge_session_helper.h" | 23 #include "google_apis/gaia/merge_session_helper.h" |
24 #include "google_apis/gaia/oauth2_token_service.h" | 24 #include "google_apis/gaia/oauth2_token_service.h" |
25 | 25 |
26 class GaiaAuthFetcher; | 26 class GaiaAuthFetcher; |
27 class Profile; | 27 class ProfileOAuth2TokenService; |
28 class SigninClient; | 28 class SigninClient; |
29 class SigninOAuthHelper; | 29 class SigninOAuthHelper; |
30 | 30 |
31 namespace net { | 31 namespace net { |
32 class CanonicalCookie; | 32 class CanonicalCookie; |
33 } | 33 } |
34 | 34 |
35 class AccountReconcilor : public KeyedService, | 35 class AccountReconcilor : public KeyedService, |
36 public GaiaAuthConsumer, | 36 public GaiaAuthConsumer, |
37 public MergeSessionHelper::Observer, | 37 public MergeSessionHelper::Observer, |
38 public OAuth2TokenService::Consumer, | 38 public OAuth2TokenService::Consumer, |
39 public OAuth2TokenService::Observer, | 39 public OAuth2TokenService::Observer, |
40 public SigninManagerBase::Observer { | 40 public SigninManagerBase::Observer { |
41 public: | 41 public: |
42 explicit AccountReconcilor(Profile* profile, SigninClient* client); | 42 AccountReconcilor(ProfileOAuth2TokenService* token_service, |
| 43 SigninManagerBase* signin_manager, |
| 44 SigninClient* client); |
43 virtual ~AccountReconcilor(); | 45 virtual ~AccountReconcilor(); |
44 | 46 |
45 void Initialize(bool start_reconcile_if_tokens_available); | 47 void Initialize(bool start_reconcile_if_tokens_available); |
46 | 48 |
47 // KeyedService implementation. | 49 // KeyedService implementation. |
48 virtual void Shutdown() OVERRIDE; | 50 virtual void Shutdown() OVERRIDE; |
49 | 51 |
50 // Add or remove observers for the merge session notification. | 52 // Add or remove observers for the merge session notification. |
51 void AddMergeSessionObserver(MergeSessionHelper::Observer* observer); | 53 void AddMergeSessionObserver(MergeSessionHelper::Observer* observer); |
52 void RemoveMergeSessionObserver(MergeSessionHelper::Observer* observer); | 54 void RemoveMergeSessionObserver(MergeSessionHelper::Observer* observer); |
53 | 55 |
54 Profile* profile() { return profile_; } | 56 ProfileOAuth2TokenService* token_service() { return token_service_; } |
| 57 SigninClient* client() { return client_; } |
55 | 58 |
56 private: | 59 private: |
57 // An std::set<> for use with email addresses that uses | 60 // An std::set<> for use with email addresses that uses |
58 // gaia::CanonicalizeEmail() during comparisons. | 61 // gaia::CanonicalizeEmail() during comparisons. |
59 // TODO(rogerta): this is a workaround for the fact that SigninManager and | 62 // TODO(rogerta): this is a workaround for the fact that SigninManager and |
60 // SigninOAuthHelper use the gaia "email" property when adding accounts to | 63 // SigninOAuthHelper use the gaia "email" property when adding accounts to |
61 // the token service, whereas gaia::ParseListAccountsData() returns email | 64 // the token service, whereas gaia::ParseListAccountsData() returns email |
62 // addresses that have been passed through gaia::CanonicalizeEmail(). These | 65 // addresses that have been passed through gaia::CanonicalizeEmail(). These |
63 // two types of email addresses are not directly comparable. | 66 // two types of email addresses are not directly comparable. |
64 class EmailLessFunc : public std::less<std::string> { | 67 class EmailLessFunc : public std::less<std::string> { |
(...skipping 10 matching lines...) Expand all Loading... |
75 } | 78 } |
76 | 79 |
77 bool IsRegisteredWithTokenService() const { | 80 bool IsRegisteredWithTokenService() const { |
78 return registered_with_token_service_; | 81 return registered_with_token_service_; |
79 } | 82 } |
80 | 83 |
81 bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; } | 84 bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; } |
82 | 85 |
83 bool AreAllRefreshTokensChecked() const; | 86 bool AreAllRefreshTokensChecked() const; |
84 | 87 |
85 const std::vector<std::pair<std::string, bool> >& | 88 const std::vector<std::pair<std::string, bool> >& GetGaiaAccountsForTesting() |
86 GetGaiaAccountsForTesting() const { | 89 const { |
87 return gaia_accounts_; | 90 return gaia_accounts_; |
88 } | 91 } |
89 | 92 |
90 const EmailSet& GetValidChromeAccountsForTesting() const { | 93 const EmailSet& GetValidChromeAccountsForTesting() const { |
91 return valid_chrome_accounts_; | 94 return valid_chrome_accounts_; |
92 } | 95 } |
93 | 96 |
94 const EmailSet& GetInvalidChromeAccountsForTesting() const { | 97 const EmailSet& GetInvalidChromeAccountsForTesting() const { |
95 return invalid_chrome_accounts_; | 98 return invalid_chrome_accounts_; |
96 } | 99 } |
97 | 100 |
98 // Used during GetAccountsFromCookie. | 101 // Used during GetAccountsFromCookie. |
99 // Stores a callback for the next action to perform. | 102 // Stores a callback for the next action to perform. |
100 typedef base::Callback<void( | 103 typedef base::Callback< |
101 const GoogleServiceAuthError& error, | 104 void(const GoogleServiceAuthError& error, |
102 const std::vector<std::pair<std::string, bool> >&)> | 105 const std::vector<std::pair<std::string, bool> >&)> |
103 GetAccountsFromCookieCallback; | 106 GetAccountsFromCookieCallback; |
104 | 107 |
105 friend class AccountReconcilorTest; | 108 friend class AccountReconcilorTest; |
106 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration); | 109 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration); |
107 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, Reauth); | 110 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, Reauth); |
108 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ProfileAlreadyConnected); | 111 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ProfileAlreadyConnected); |
109 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess); | 112 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess); |
110 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure); | 113 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure); |
111 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens); | 114 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens); |
112 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, | 115 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, |
113 ValidateAccountsFromTokensFailedUserInfo); | 116 ValidateAccountsFromTokensFailedUserInfo); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 void GetAccountsFromCookie(GetAccountsFromCookieCallback callback); | 171 void GetAccountsFromCookie(GetAccountsFromCookieCallback callback); |
169 void ContinueReconcileActionAfterGetGaiaAccounts( | 172 void ContinueReconcileActionAfterGetGaiaAccounts( |
170 const GoogleServiceAuthError& error, | 173 const GoogleServiceAuthError& error, |
171 const std::vector<std::pair<std::string, bool> >& accounts); | 174 const std::vector<std::pair<std::string, bool> >& accounts); |
172 void ValidateAccountsFromTokenService(); | 175 void ValidateAccountsFromTokenService(); |
173 | 176 |
174 void OnCookieChanged(const net::CanonicalCookie* cookie); | 177 void OnCookieChanged(const net::CanonicalCookie* cookie); |
175 | 178 |
176 // Overriden from GaiaAuthConsumer. | 179 // Overriden from GaiaAuthConsumer. |
177 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE; | 180 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE; |
178 virtual void OnListAccountsFailure( | 181 virtual void OnListAccountsFailure(const GoogleServiceAuthError& error) |
179 const GoogleServiceAuthError& error) OVERRIDE; | 182 OVERRIDE; |
180 | 183 |
181 // Overriden from MergeSessionHelper::Observer. | 184 // Overriden from MergeSessionHelper::Observer. |
182 virtual void MergeSessionCompleted( | 185 virtual void MergeSessionCompleted(const std::string& account_id, |
183 const std::string& account_id, | 186 const GoogleServiceAuthError& error) |
184 const GoogleServiceAuthError& error) OVERRIDE; | 187 OVERRIDE; |
185 | 188 |
186 // Overriden from OAuth2TokenService::Consumer. | 189 // Overriden from OAuth2TokenService::Consumer. |
187 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 190 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
188 const std::string& access_token, | 191 const std::string& access_token, |
189 const base::Time& expiration_time) OVERRIDE; | 192 const base::Time& expiration_time) OVERRIDE; |
190 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 193 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
191 const GoogleServiceAuthError& error) OVERRIDE; | 194 const GoogleServiceAuthError& error) OVERRIDE; |
192 | 195 |
193 // Overriden from OAuth2TokenService::Observer. | 196 // Overriden from OAuth2TokenService::Observer. |
194 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 197 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
195 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | 198 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; |
196 virtual void OnRefreshTokensLoaded() OVERRIDE; | 199 virtual void OnRefreshTokensLoaded() OVERRIDE; |
197 | 200 |
198 // Overriden from SigninManagerBase::Observer. | 201 // Overriden from SigninManagerBase::Observer. |
199 virtual void GoogleSigninSucceeded(const std::string& username, | 202 virtual void GoogleSigninSucceeded(const std::string& username, |
200 const std::string& password) OVERRIDE; | 203 const std::string& password) OVERRIDE; |
201 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; | 204 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; |
202 | 205 |
203 void MayBeDoNextListAccounts(); | 206 void MayBeDoNextListAccounts(); |
204 | 207 |
205 // The profile that this reconcilor belongs to. | 208 // The ProfileOAuth2TokenService associated with this reconcilor. |
206 Profile* profile_; | 209 ProfileOAuth2TokenService* token_service_; |
| 210 |
| 211 // The SigninManager associated with this reconcilor. |
| 212 SigninManagerBase* signin_manager_; |
207 | 213 |
208 // The SigninClient associated with this reconcilor. | 214 // The SigninClient associated with this reconcilor. |
209 SigninClient* client_; | 215 SigninClient* client_; |
210 | 216 |
211 base::RepeatingTimer<AccountReconcilor> reconciliation_timer_; | 217 base::RepeatingTimer<AccountReconcilor> reconciliation_timer_; |
212 MergeSessionHelper merge_session_helper_; | 218 MergeSessionHelper merge_session_helper_; |
213 scoped_ptr<GaiaAuthFetcher> gaia_fetcher_; | 219 scoped_ptr<GaiaAuthFetcher> gaia_fetcher_; |
214 bool registered_with_token_service_; | 220 bool registered_with_token_service_; |
215 | 221 |
216 // True while the reconcilor is busy checking or managing the accounts in | 222 // True while the reconcilor is busy checking or managing the accounts in |
(...skipping 19 matching lines...) Expand all Loading... |
236 EmailSet valid_chrome_accounts_; | 242 EmailSet valid_chrome_accounts_; |
237 EmailSet invalid_chrome_accounts_; | 243 EmailSet invalid_chrome_accounts_; |
238 std::vector<std::string> add_to_cookie_; | 244 std::vector<std::string> add_to_cookie_; |
239 std::vector<std::pair<std::string, int> > add_to_chrome_; | 245 std::vector<std::pair<std::string, int> > add_to_chrome_; |
240 | 246 |
241 std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_; | 247 std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_; |
242 | 248 |
243 DISALLOW_COPY_AND_ASSIGN(AccountReconcilor); | 249 DISALLOW_COPY_AND_ASSIGN(AccountReconcilor); |
244 }; | 250 }; |
245 | 251 |
246 #endif // CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_ | 252 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ |
OLD | NEW |