Chromium Code Reviews| 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; | |
| 28 class SigninClient; | 27 class SigninClient; |
| 29 class SigninOAuthHelper; | 28 class SigninOAuthHelper; |
| 30 | 29 |
| 31 namespace net { | 30 namespace net { |
| 32 class CanonicalCookie; | 31 class CanonicalCookie; |
| 33 } | 32 } |
| 34 | 33 |
| 35 class AccountReconcilor : public KeyedService, | 34 class AccountReconcilor : public KeyedService, |
| 36 public GaiaAuthConsumer, | 35 public GaiaAuthConsumer, |
| 37 public MergeSessionHelper::Observer, | 36 public MergeSessionHelper::Observer, |
| 38 public OAuth2TokenService::Consumer, | 37 public OAuth2TokenService::Consumer, |
| 39 public OAuth2TokenService::Observer, | 38 public OAuth2TokenService::Observer, |
| 40 public SigninManagerBase::Observer { | 39 public SigninManagerBase::Observer { |
| 41 public: | 40 public: |
| 42 explicit AccountReconcilor(Profile* profile, SigninClient* client); | 41 AccountReconcilor(ProfileOAuth2TokenService* token_service, |
| 42 SigninManager* signin_manager, | |
| 43 SigninClient* client); | |
| 43 virtual ~AccountReconcilor(); | 44 virtual ~AccountReconcilor(); |
| 44 | 45 |
| 45 void Initialize(bool start_reconcile_if_tokens_available); | 46 void Initialize(bool start_reconcile_if_tokens_available); |
| 46 | 47 |
| 47 // KeyedService implementation. | 48 // KeyedService implementation. |
| 48 virtual void Shutdown() OVERRIDE; | 49 virtual void Shutdown() OVERRIDE; |
| 49 | 50 |
| 50 // Add or remove observers for the merge session notification. | 51 // Add or remove observers for the merge session notification. |
| 51 void AddMergeSessionObserver(MergeSessionHelper::Observer* observer); | 52 void AddMergeSessionObserver(MergeSessionHelper::Observer* observer); |
| 52 void RemoveMergeSessionObserver(MergeSessionHelper::Observer* observer); | 53 void RemoveMergeSessionObserver(MergeSessionHelper::Observer* observer); |
| 53 | 54 |
| 54 Profile* profile() { return profile_; } | 55 ProfileOAuth2TokenService* token_service() { return token_service_; } |
| 56 SigninClient* client() { return client_; } | |
| 55 | 57 |
| 56 private: | 58 private: |
| 57 // An std::set<> for use with email addresses that uses | 59 // An std::set<> for use with email addresses that uses |
| 58 // gaia::CanonicalizeEmail() during comparisons. | 60 // gaia::CanonicalizeEmail() during comparisons. |
| 59 // TODO(rogerta): this is a workaround for the fact that SigninManager and | 61 // TODO(rogerta): this is a workaround for the fact that SigninManager and |
| 60 // SigninOAuthHelper use the gaia "email" property when adding accounts to | 62 // SigninOAuthHelper use the gaia "email" property when adding accounts to |
| 61 // the token service, whereas gaia::ParseListAccountsData() returns email | 63 // the token service, whereas gaia::ParseListAccountsData() returns email |
| 62 // addresses that have been passed through gaia::CanonicalizeEmail(). These | 64 // addresses that have been passed through gaia::CanonicalizeEmail(). These |
| 63 // two types of email addresses are not directly comparable. | 65 // two types of email addresses are not directly comparable. |
| 64 class EmailLessFunc : public std::less<std::string> { | 66 class EmailLessFunc : public std::less<std::string> { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 75 } | 77 } |
| 76 | 78 |
| 77 bool IsRegisteredWithTokenService() const { | 79 bool IsRegisteredWithTokenService() const { |
| 78 return registered_with_token_service_; | 80 return registered_with_token_service_; |
| 79 } | 81 } |
| 80 | 82 |
| 81 bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; } | 83 bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; } |
| 82 | 84 |
| 83 bool AreAllRefreshTokensChecked() const; | 85 bool AreAllRefreshTokensChecked() const; |
| 84 | 86 |
| 85 const std::vector<std::pair<std::string, bool> >& | 87 const std::vector<std::pair<std::string, bool> >& GetGaiaAccountsForTesting() |
| 86 GetGaiaAccountsForTesting() const { | 88 const { |
| 87 return gaia_accounts_; | 89 return gaia_accounts_; |
| 88 } | 90 } |
| 89 | 91 |
| 90 const EmailSet& GetValidChromeAccountsForTesting() const { | 92 const EmailSet& GetValidChromeAccountsForTesting() const { |
| 91 return valid_chrome_accounts_; | 93 return valid_chrome_accounts_; |
| 92 } | 94 } |
| 93 | 95 |
| 94 const EmailSet& GetInvalidChromeAccountsForTesting() const { | 96 const EmailSet& GetInvalidChromeAccountsForTesting() const { |
| 95 return invalid_chrome_accounts_; | 97 return invalid_chrome_accounts_; |
| 96 } | 98 } |
| 97 | 99 |
| 98 // Used during GetAccountsFromCookie. | 100 // Used during GetAccountsFromCookie. |
| 99 // Stores a callback for the next action to perform. | 101 // Stores a callback for the next action to perform. |
| 100 typedef base::Callback<void( | 102 typedef base::Callback< |
| 101 const GoogleServiceAuthError& error, | 103 void(const GoogleServiceAuthError& error, |
| 102 const std::vector<std::pair<std::string, bool> >&)> | 104 const std::vector<std::pair<std::string, bool> >&)> |
| 103 GetAccountsFromCookieCallback; | 105 GetAccountsFromCookieCallback; |
| 104 | 106 |
| 105 friend class AccountReconcilorTest; | 107 friend class AccountReconcilorTest; |
| 106 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration); | 108 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration); |
| 107 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, Reauth); | 109 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, Reauth); |
| 108 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ProfileAlreadyConnected); | 110 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ProfileAlreadyConnected); |
| 109 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess); | 111 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess); |
| 110 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure); | 112 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure); |
| 111 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens); | 113 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens); |
| 112 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, | 114 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, |
| 113 ValidateAccountsFromTokensFailedUserInfo); | 115 ValidateAccountsFromTokensFailedUserInfo); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 124 StartReconcileWithSessionInfoExpiredDefault); | 126 StartReconcileWithSessionInfoExpiredDefault); |
| 125 | 127 |
| 126 // Register and unregister with dependent services. | 128 // Register and unregister with dependent services. |
| 127 void RegisterForCookieChanges(); | 129 void RegisterForCookieChanges(); |
| 128 void UnregisterForCookieChanges(); | 130 void UnregisterForCookieChanges(); |
| 129 void RegisterWithSigninManager(); | 131 void RegisterWithSigninManager(); |
| 130 void UnregisterWithSigninManager(); | 132 void UnregisterWithSigninManager(); |
| 131 void RegisterWithTokenService(); | 133 void RegisterWithTokenService(); |
| 132 void UnregisterWithTokenService(); | 134 void UnregisterWithTokenService(); |
| 133 | 135 |
| 134 bool IsProfileConnected(); | 136 bool IsUserSignedIn(); |
|
Roger Tawa OOO till Jul 10th
2014/04/01 02:26:26
I actually prefer the term "IsProfileConnected".
blundell
2014/04/01 20:40:00
Done.
| |
| 135 | 137 |
| 136 void DeleteFetchers(); | 138 void DeleteFetchers(); |
| 137 | 139 |
| 138 // Start and stop the periodic reconciliation. | 140 // Start and stop the periodic reconciliation. |
| 139 void StartPeriodicReconciliation(); | 141 void StartPeriodicReconciliation(); |
| 140 void StopPeriodicReconciliation(); | 142 void StopPeriodicReconciliation(); |
| 141 void PeriodicReconciliation(); | 143 void PeriodicReconciliation(); |
| 142 | 144 |
| 143 // All actions with side effects. Virtual so that they can be overridden | 145 // All actions with side effects. Virtual so that they can be overridden |
| 144 // in tests. | 146 // in tests. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 168 void GetAccountsFromCookie(GetAccountsFromCookieCallback callback); | 170 void GetAccountsFromCookie(GetAccountsFromCookieCallback callback); |
| 169 void ContinueReconcileActionAfterGetGaiaAccounts( | 171 void ContinueReconcileActionAfterGetGaiaAccounts( |
| 170 const GoogleServiceAuthError& error, | 172 const GoogleServiceAuthError& error, |
| 171 const std::vector<std::pair<std::string, bool> >& accounts); | 173 const std::vector<std::pair<std::string, bool> >& accounts); |
| 172 void ValidateAccountsFromTokenService(); | 174 void ValidateAccountsFromTokenService(); |
| 173 | 175 |
| 174 void OnCookieChanged(const net::CanonicalCookie* cookie); | 176 void OnCookieChanged(const net::CanonicalCookie* cookie); |
| 175 | 177 |
| 176 // Overriden from GaiaAuthConsumer. | 178 // Overriden from GaiaAuthConsumer. |
| 177 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE; | 179 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE; |
| 178 virtual void OnListAccountsFailure( | 180 virtual void OnListAccountsFailure(const GoogleServiceAuthError& error) |
| 179 const GoogleServiceAuthError& error) OVERRIDE; | 181 OVERRIDE; |
| 180 | 182 |
| 181 // Overriden from MergeSessionHelper::Observer. | 183 // Overriden from MergeSessionHelper::Observer. |
| 182 virtual void MergeSessionCompleted( | 184 virtual void MergeSessionCompleted(const std::string& account_id, |
| 183 const std::string& account_id, | 185 const GoogleServiceAuthError& error) |
| 184 const GoogleServiceAuthError& error) OVERRIDE; | 186 OVERRIDE; |
| 185 | 187 |
| 186 // Overriden from OAuth2TokenService::Consumer. | 188 // Overriden from OAuth2TokenService::Consumer. |
| 187 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 189 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 188 const std::string& access_token, | 190 const std::string& access_token, |
| 189 const base::Time& expiration_time) OVERRIDE; | 191 const base::Time& expiration_time) OVERRIDE; |
| 190 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 192 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 191 const GoogleServiceAuthError& error) OVERRIDE; | 193 const GoogleServiceAuthError& error) OVERRIDE; |
| 192 | 194 |
| 193 // Overriden from OAuth2TokenService::Observer. | 195 // Overriden from OAuth2TokenService::Observer. |
| 194 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 196 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 195 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | 197 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; |
| 196 virtual void OnRefreshTokensLoaded() OVERRIDE; | 198 virtual void OnRefreshTokensLoaded() OVERRIDE; |
| 197 | 199 |
| 198 // Overriden from SigninManagerBase::Observer. | 200 // Overriden from SigninManagerBase::Observer. |
| 199 virtual void GoogleSigninSucceeded(const std::string& username, | 201 virtual void GoogleSigninSucceeded(const std::string& username, |
| 200 const std::string& password) OVERRIDE; | 202 const std::string& password) OVERRIDE; |
| 201 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; | 203 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; |
| 202 | 204 |
| 203 void MayBeDoNextListAccounts(); | 205 void MayBeDoNextListAccounts(); |
| 204 | 206 |
| 205 // The profile that this reconcilor belongs to. | 207 // The ProfileOAuth2TokenService associated with this reconcilor. |
| 206 Profile* profile_; | 208 ProfileOAuth2TokenService* token_service_; |
| 209 | |
| 210 // The SigninManager associated with this reconcilor. | |
| 211 SigninManager* signin_manager_; | |
| 207 | 212 |
| 208 // The SigninClient associated with this reconcilor. | 213 // The SigninClient associated with this reconcilor. |
| 209 SigninClient* client_; | 214 SigninClient* client_; |
| 210 | 215 |
| 211 base::RepeatingTimer<AccountReconcilor> reconciliation_timer_; | 216 base::RepeatingTimer<AccountReconcilor> reconciliation_timer_; |
| 212 MergeSessionHelper merge_session_helper_; | 217 MergeSessionHelper merge_session_helper_; |
| 213 scoped_ptr<GaiaAuthFetcher> gaia_fetcher_; | 218 scoped_ptr<GaiaAuthFetcher> gaia_fetcher_; |
| 214 bool registered_with_token_service_; | 219 bool registered_with_token_service_; |
| 215 | 220 |
| 216 // True while the reconcilor is busy checking or managing the accounts in | 221 // True while the reconcilor is busy checking or managing the accounts in |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 236 EmailSet valid_chrome_accounts_; | 241 EmailSet valid_chrome_accounts_; |
| 237 EmailSet invalid_chrome_accounts_; | 242 EmailSet invalid_chrome_accounts_; |
| 238 std::vector<std::string> add_to_cookie_; | 243 std::vector<std::string> add_to_cookie_; |
| 239 std::vector<std::pair<std::string, int> > add_to_chrome_; | 244 std::vector<std::pair<std::string, int> > add_to_chrome_; |
| 240 | 245 |
| 241 std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_; | 246 std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_; |
| 242 | 247 |
| 243 DISALLOW_COPY_AND_ASSIGN(AccountReconcilor); | 248 DISALLOW_COPY_AND_ASSIGN(AccountReconcilor); |
| 244 }; | 249 }; |
| 245 | 250 |
| 246 #endif // CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_ | 251 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ |
| OLD | NEW |