#define CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_
#include <deque>
+#include <string>
+#include <utility>
+#include <vector>
#include "base/basictypes.h"
#include "base/callback_forward.h"
class AccountReconcilor : public BrowserContextKeyedService,
public content::NotificationObserver,
public GaiaAuthConsumer,
+ public MergeSessionHelper::Observer,
public OAuth2TokenService::Consumer,
public OAuth2TokenService::Observer,
public SigninManagerBase::Observer {
bool AreAllRefreshTokensChecked() const;
- const std::vector<std::string>& GetGaiaAccountsForTesting() const {
+ const std::vector<std::pair<std::string, bool> >&
+ GetGaiaAccountsForTesting() const {
return gaia_accounts_;
}
+ private:
const std::set<std::string>& GetValidChromeAccountsForTesting() const {
return valid_chrome_accounts_;
}
return invalid_chrome_accounts_;
}
- private:
// Used during GetAccountsFromCookie.
// Stores a callback for the next action to perform.
typedef base::Callback<void(
const GoogleServiceAuthError& error,
- const std::vector<std::string>&)> GetAccountsFromCookieCallback;
+ const std::vector<std::pair<std::string, bool> >&)>
+ GetAccountsFromCookieCallback;
- class AccountReconcilorTest;
+ friend class AccountReconcilorTest;
FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess);
FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure);
FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens);
FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
ValidateAccountsFromTokensFailedUserInfo);
FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
- ValidateAccountsFromTokensFailedTokenRequest);
- FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAction);
+ ValidateAccountsFromTokensFailedTokenRequest);
+ FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoop);
+ FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopMultiple);
+ FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToCookie);
+ FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToChrome);
+ FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileBadPrimary);
+ FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileOnlyOnce);
+ FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
+ StartReconcileWithSessionInfoExpiredDefault);
+ class RefreshTokenFetcher;
class UserIdFetcher;
// Register and unregister with dependent services.
bool IsProfileConnected();
- void DeleteAccessTokenRequestsAndUserIdFetchers();
+ void DeleteFetchers();
// Start and stop the periodic reconciliation.
void StartPeriodicReconciliation();
void StopPeriodicReconciliation();
void PeriodicReconciliation();
- void PerformMergeAction(const std::string& account_id);
- void StartRemoveAction(const std::string& account_id);
- void FinishRemoveAction(
+ // All actions with side effects. Virtual so that they can be overridden
+ // in tests.
+ virtual void PerformMergeAction(const std::string& account_id);
+ virtual void PerformAddToChromeAction(const std::string& account_id,
+ int session_index);
+ virtual void PerformLogoutAllAccountsAction();
+
+ // Used to remove an account from chrome and the cookie jar.
+ virtual void StartRemoveAction(const std::string& account_id);
+ virtual void FinishRemoveAction(
const std::string& account_id,
const GoogleServiceAuthError& error,
- const std::vector<std::string>& accounts);
+ const std::vector<std::pair<std::string, bool> >& accounts);
- // Used during period reconciliation.
- void StartReconcileAction();
- void FinishReconcileAction();
+ // Used during periodic reconciliation.
+ void StartReconcile();
+ void FinishReconcile();
+ void AbortReconcile();
+ void CalculateIfReconcileIsDone();
void HandleSuccessfulAccountIdCheck(const std::string& account_id);
void HandleFailedAccountIdCheck(const std::string& account_id);
+ void HandleRefreshTokenFetched(const std::string& account_id,
+ const std::string& refresh_token);
void GetAccountsFromCookie(GetAccountsFromCookieCallback callback);
void ContinueReconcileActionAfterGetGaiaAccounts(
const GoogleServiceAuthError& error,
- const std::vector<std::string>& accounts);
+ const std::vector<std::pair<std::string, bool> >& accounts);
void ValidateAccountsFromTokenService();
void OnCookieChanged(ChromeCookieDetails* details);
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
+ // Overriden from GaiaAuthConsumer.
+ virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE;
+ virtual void OnListAccountsFailure(
+ const GoogleServiceAuthError& error) OVERRIDE;
+
+ // Overriden from MergeSessionHelper::Observer.
+ virtual void MergeSessionCompleted(
+ const std::string& account_id,
+ const GoogleServiceAuthError& error) OVERRIDE;
+
// Overriden from OAuth2TokenService::Consumer.
virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
const std::string& access_token,
const std::string& password) OVERRIDE;
virtual void GoogleSignedOut(const std::string& username) OVERRIDE;
- // Overriden from GaiaAuthConsumer.
- virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE;
- virtual void OnListAccountsFailure(
- const GoogleServiceAuthError& error) OVERRIDE;
-
void MayBeDoNextListAccounts();
// The profile that this reconcilor belongs to.
content::NotificationRegistrar registrar_;
base::RepeatingTimer<AccountReconcilor> reconciliation_timer_;
MergeSessionHelper merge_session_helper_;
+ scoped_ptr<GaiaAuthFetcher> gaia_fetcher_;
bool registered_with_token_service_;
+ // True while the reconcilor is busy checking or managing the accounts in
+ // this profile.
+ bool is_reconcile_started_;
+
// Used during reconcile action.
- // These members are used used to validate the gaia cookie.
- scoped_ptr<GaiaAuthFetcher> gaia_fetcher_;
+ // These members are used used to validate the gaia cookie. |gaia_accounts_|
+ // holds the state of google accounts in the gaia cookie. Each element is
+ // a pair that holds the email address of the account and a boolean that
+ // indicates whether the account is valid or not. The accounts in the vector
+ // are ordered the in same way as the gaia cookie.
bool are_gaia_accounts_set_;
- std::vector<std::string> gaia_accounts_;
+ std::vector<std::pair<std::string, bool> > gaia_accounts_;
// Used during reconcile action.
// These members are used to validate the tokens in OAuth2TokenService.
std::vector<std::string> chrome_accounts_;
scoped_ptr<OAuth2TokenService::Request>* requests_;
ScopedVector<UserIdFetcher> user_id_fetchers_;
+ ScopedVector<RefreshTokenFetcher> refresh_token_fetchers_;
std::set<std::string> valid_chrome_accounts_;
std::set<std::string> invalid_chrome_accounts_;
+ std::vector<std::string> add_to_cookie_;
+ std::vector<std::pair<std::string, int> > add_to_chrome_;
std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_;