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 CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_ |
| 5 #define CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_ | 5 #define CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_ |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <string> | |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 8 | 11 |
| 9 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 10 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 11 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 14 #include "chrome/browser/signin/signin_manager.h" | 17 #include "chrome/browser/signin/signin_manager.h" |
| 15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | 18 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" |
| 16 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 } | 52 } |
| 50 | 53 |
| 51 bool IsRegisteredWithTokenService() const { | 54 bool IsRegisteredWithTokenService() const { |
| 52 return registered_with_token_service_; | 55 return registered_with_token_service_; |
| 53 } | 56 } |
| 54 | 57 |
| 55 bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; } | 58 bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; } |
| 56 | 59 |
| 57 bool AreAllRefreshTokensChecked() const; | 60 bool AreAllRefreshTokensChecked() const; |
| 58 | 61 |
| 59 const std::vector<std::string>& GetGaiaAccountsForTesting() const { | 62 const std::vector<std::pair<std::string, bool> >& |
| 63 GetGaiaAccountsForTesting() const { | |
| 60 return gaia_accounts_; | 64 return gaia_accounts_; |
| 61 } | 65 } |
| 62 | 66 |
| 67 private: | |
| 63 const std::set<std::string>& GetValidChromeAccountsForTesting() const { | 68 const std::set<std::string>& GetValidChromeAccountsForTesting() const { |
| 64 return valid_chrome_accounts_; | 69 return valid_chrome_accounts_; |
| 65 } | 70 } |
| 66 | 71 |
| 67 const std::set<std::string>& GetInvalidChromeAccountsForTesting() const { | 72 const std::set<std::string>& GetInvalidChromeAccountsForTesting() const { |
| 68 return invalid_chrome_accounts_; | 73 return invalid_chrome_accounts_; |
| 69 } | 74 } |
| 70 | 75 |
| 71 private: | |
| 72 // Used during GetAccountsFromCookie. | 76 // Used during GetAccountsFromCookie. |
| 73 // Stores a callback for the next action to perform. | 77 // Stores a callback for the next action to perform. |
| 74 typedef base::Callback<void( | 78 typedef base::Callback<void( |
| 75 const GoogleServiceAuthError& error, | 79 const GoogleServiceAuthError& error, |
| 76 const std::vector<std::string>&)> GetAccountsFromCookieCallback; | 80 const std::vector<std::pair<std::string, bool> >&)> |
| 81 GetAccountsFromCookieCallback; | |
| 77 | 82 |
| 78 friend class AccountReconcilorTest; | 83 friend class AccountReconcilorTest; |
| 79 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess); | 84 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess); |
| 80 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure); | 85 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure); |
| 81 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens); | 86 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens); |
| 82 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, | 87 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, |
| 83 ValidateAccountsFromTokensFailedUserInfo); | 88 ValidateAccountsFromTokensFailedUserInfo); |
| 84 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, | 89 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, |
| 85 ValidateAccountsFromTokensFailedTokenRequest); | 90 ValidateAccountsFromTokensFailedTokenRequest); |
| 86 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoop); | 91 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoop); |
| 87 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopMultiple); | 92 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopMultiple); |
| 88 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToCookie); | 93 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToCookie); |
| 89 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToChrome); | 94 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToChrome); |
| 90 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileBadPrimary); | 95 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileBadPrimary); |
| 91 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileOnlyOnce); | 96 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileOnlyOnce); |
| 97 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, | |
| 98 StartReconcileWithSessionInfoExpiredDefault); | |
| 92 | 99 |
| 93 class RefreshTokenFetcher; | 100 class RefreshTokenFetcher; |
| 94 class UserIdFetcher; | 101 class UserIdFetcher; |
| 95 | 102 |
| 96 // Register and unregister with dependent services. | 103 // Register and unregister with dependent services. |
| 97 void RegisterWithCookieMonster(); | 104 void RegisterWithCookieMonster(); |
| 98 void UnregisterWithCookieMonster(); | 105 void UnregisterWithCookieMonster(); |
| 99 void RegisterWithSigninManager(); | 106 void RegisterWithSigninManager(); |
| 100 void UnregisterWithSigninManager(); | 107 void UnregisterWithSigninManager(); |
| 101 void RegisterWithTokenService(); | 108 void RegisterWithTokenService(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 115 virtual void PerformMergeAction(const std::string& account_id); | 122 virtual void PerformMergeAction(const std::string& account_id); |
| 116 virtual void PerformAddToChromeAction(const std::string& account_id, | 123 virtual void PerformAddToChromeAction(const std::string& account_id, |
| 117 int session_index); | 124 int session_index); |
| 118 virtual void PerformLogoutAllAccountsAction(); | 125 virtual void PerformLogoutAllAccountsAction(); |
| 119 | 126 |
| 120 // Used to remove an account from chrome and the cookie jar. | 127 // Used to remove an account from chrome and the cookie jar. |
| 121 virtual void StartRemoveAction(const std::string& account_id); | 128 virtual void StartRemoveAction(const std::string& account_id); |
| 122 virtual void FinishRemoveAction( | 129 virtual void FinishRemoveAction( |
| 123 const std::string& account_id, | 130 const std::string& account_id, |
| 124 const GoogleServiceAuthError& error, | 131 const GoogleServiceAuthError& error, |
| 125 const std::vector<std::string>& accounts); | 132 const std::vector<std::pair<std::string, bool> >& accounts); |
| 126 | 133 |
| 127 // Used during periodic reconciliation. | 134 // Used during periodic reconciliation. |
| 128 void StartReconcile(); | 135 void StartReconcile(); |
| 129 void FinishReconcile(); | 136 void FinishReconcile(); |
| 130 void AbortReconcile(); | 137 void AbortReconcile(); |
| 131 void CalculateIfReconcileIsDone(); | 138 void CalculateIfReconcileIsDone(); |
| 132 void HandleSuccessfulAccountIdCheck(const std::string& account_id); | 139 void HandleSuccessfulAccountIdCheck(const std::string& account_id); |
| 133 void HandleFailedAccountIdCheck(const std::string& account_id); | 140 void HandleFailedAccountIdCheck(const std::string& account_id); |
| 134 void HandleRefreshTokenFetched(const std::string& account_id, | 141 void HandleRefreshTokenFetched(const std::string& account_id, |
| 135 const std::string& refresh_token); | 142 const std::string& refresh_token); |
| 136 | 143 |
| 137 void GetAccountsFromCookie(GetAccountsFromCookieCallback callback); | 144 void GetAccountsFromCookie(GetAccountsFromCookieCallback callback); |
| 138 void ContinueReconcileActionAfterGetGaiaAccounts( | 145 void ContinueReconcileActionAfterGetGaiaAccounts( |
| 139 const GoogleServiceAuthError& error, | 146 const GoogleServiceAuthError& error, |
| 140 const std::vector<std::string>& accounts); | 147 const std::vector<std::pair<std::string, bool> >& accounts); |
| 141 void ValidateAccountsFromTokenService(); | 148 void ValidateAccountsFromTokenService(); |
| 142 | 149 |
| 143 void OnCookieChanged(ChromeCookieDetails* details); | 150 void OnCookieChanged(ChromeCookieDetails* details); |
| 144 | 151 |
| 145 // Overriden from content::NotificationObserver. | 152 // Overriden from content::NotificationObserver. |
| 146 virtual void Observe(int type, | 153 virtual void Observe(int type, |
| 147 const content::NotificationSource& source, | 154 const content::NotificationSource& source, |
| 148 const content::NotificationDetails& details) OVERRIDE; | 155 const content::NotificationDetails& details) OVERRIDE; |
| 149 | 156 |
| 150 // Overriden from GaiaAuthConsumer. | 157 // Overriden from GaiaAuthConsumer. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 MergeSessionHelper merge_session_helper_; | 190 MergeSessionHelper merge_session_helper_; |
| 184 scoped_ptr<GaiaAuthFetcher> gaia_fetcher_; | 191 scoped_ptr<GaiaAuthFetcher> gaia_fetcher_; |
| 185 bool registered_with_token_service_; | 192 bool registered_with_token_service_; |
| 186 | 193 |
| 187 // True while the reconcilor is busy checking or managing the accounts in | 194 // True while the reconcilor is busy checking or managing the accounts in |
| 188 // this profile. | 195 // this profile. |
| 189 bool is_reconcile_started_; | 196 bool is_reconcile_started_; |
| 190 | 197 |
| 191 // Used during reconcile action. | 198 // Used during reconcile action. |
| 192 // These members are used used to validate the gaia cookie. | 199 // These members are used used to validate the gaia cookie. |
| 193 bool are_gaia_accounts_set_; | 200 bool are_gaia_accounts_set_; |
|
acleung1
2014/02/18 21:00:24
Can you document on what the bool represent here?
Roger Tawa OOO till Jul 10th
2014/02/19 22:57:01
Added docs.
| |
| 194 std::vector<std::string> gaia_accounts_; | 201 std::vector<std::pair<std::string, bool> > gaia_accounts_; |
| 195 | 202 |
| 196 // Used during reconcile action. | 203 // Used during reconcile action. |
| 197 // These members are used to validate the tokens in OAuth2TokenService. | 204 // These members are used to validate the tokens in OAuth2TokenService. |
| 198 std::string primary_account_; | 205 std::string primary_account_; |
| 199 std::vector<std::string> chrome_accounts_; | 206 std::vector<std::string> chrome_accounts_; |
| 200 scoped_ptr<OAuth2TokenService::Request>* requests_; | 207 scoped_ptr<OAuth2TokenService::Request>* requests_; |
| 201 ScopedVector<UserIdFetcher> user_id_fetchers_; | 208 ScopedVector<UserIdFetcher> user_id_fetchers_; |
| 202 ScopedVector<RefreshTokenFetcher> refresh_token_fetchers_; | 209 ScopedVector<RefreshTokenFetcher> refresh_token_fetchers_; |
| 203 std::set<std::string> valid_chrome_accounts_; | 210 std::set<std::string> valid_chrome_accounts_; |
| 204 std::set<std::string> invalid_chrome_accounts_; | 211 std::set<std::string> invalid_chrome_accounts_; |
| 205 std::vector<std::string> add_to_cookie_; | 212 std::vector<std::string> add_to_cookie_; |
| 206 std::vector<std::pair<std::string, int> > add_to_chrome_; | 213 std::vector<std::pair<std::string, int> > add_to_chrome_; |
| 207 | 214 |
| 208 std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_; | 215 std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_; |
| 209 | 216 |
| 210 DISALLOW_COPY_AND_ASSIGN(AccountReconcilor); | 217 DISALLOW_COPY_AND_ASSIGN(AccountReconcilor); |
| 211 }; | 218 }; |
| 212 | 219 |
| 213 #endif // CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_ | 220 #endif // CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_ |
| OLD | NEW |