account_reconcilor.h revision 116680a4aac90f2aa7413d9095a592090648e557
1c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 28bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 38bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// found in the LICENSE file. 4c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ 5c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ 68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <deque> 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <functional> 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <set> 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <string> 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <utility> 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <vector> 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/basictypes.h" 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/callback_forward.h" 168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/compiler_specific.h" 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_vector.h" 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/core/keyed_service.h" 20e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "components/signin/core/browser/signin_manager.h" 21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "google_apis/gaia/gaia_auth_consumer.h" 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "google_apis/gaia/google_service_auth_error.h" 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "google_apis/gaia/merge_session_helper.h" 241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "google_apis/gaia/oauth2_token_service.h" 258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class GaiaAuthFetcher; 27c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass ProfileOAuth2TokenService; 28e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochclass SigninClient; 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class SigninOAuthHelper; 308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 31e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochnamespace net { 32e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochclass CanonicalCookie; 33e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 34e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class AccountReconcilor : public KeyedService, 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public GaiaAuthConsumer, 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public MergeSessionHelper::Observer, 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public OAuth2TokenService::Consumer, 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public OAuth2TokenService::Observer, 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public SigninManagerBase::Observer { 418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public: 42c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch AccountReconcilor(ProfileOAuth2TokenService* token_service, 43c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SigninManagerBase* signin_manager, 44c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SigninClient* client); 458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual ~AccountReconcilor(); 468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void Initialize(bool start_reconcile_if_tokens_available); 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 49f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Signal that the status of the new_profile_management flag has changed. 50f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Pass the new status as an explicit parameter since disabling the flag 51f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // doesn't remove it from the CommandLine::ForCurrentProcess(). 52f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) void OnNewProfileManagementFlagChanged(bool new_flag_status); 53f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // KeyedService implementation. 558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void Shutdown() OVERRIDE; 568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add or remove observers for the merge session notification. 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void AddMergeSessionObserver(MergeSessionHelper::Observer* observer); 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void RemoveMergeSessionObserver(MergeSessionHelper::Observer* observer); 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 61c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ProfileOAuth2TokenService* token_service() { return token_service_; } 62c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SigninClient* client() { return client_; } 638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch protected: 65116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Used during GetAccountsFromCookie. 66116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Stores a callback for the next action to perform. 67116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch typedef base::Callback< 68116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void(const GoogleServiceAuthError& error, 69116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const std::vector<std::pair<std::string, bool> >&)> 70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch GetAccountsFromCookieCallback; 71116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 72116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void GetAccountsFromCookie(GetAccountsFromCookieCallback callback); 73116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 74a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private: 75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // An std::set<> for use with email addresses that uses 76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // gaia::CanonicalizeEmail() during comparisons. 77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // TODO(rogerta): this is a workaround for the fact that SigninManager and 78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // SigninOAuthHelper use the gaia "email" property when adding accounts to 79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // the token service, whereas gaia::ParseListAccountsData() returns email 80a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // addresses that have been passed through gaia::CanonicalizeEmail(). These 81a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // two types of email addresses are not directly comparable. 82a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) class EmailLessFunc : public std::less<std::string> { 83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public: 84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool operator()(const std::string& s1, const std::string& s2) const; 85a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) }; 86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) typedef std::set<std::string, EmailLessFunc> EmailSet; 87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) class RefreshTokenFetcher; 89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) class UserIdFetcher; 90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool IsRegisteredWithTokenService() const { 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return registered_with_token_service_; 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; } 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool AreAllRefreshTokensChecked() const; 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 99c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const std::vector<std::pair<std::string, bool> >& GetGaiaAccountsForTesting() 100c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const { 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return gaia_accounts_; 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const EmailSet& GetValidChromeAccountsForTesting() const { 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return valid_chrome_accounts_; 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const EmailSet& GetInvalidChromeAccountsForTesting() const { 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return invalid_chrome_accounts_; 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) friend class AccountReconcilorTest; 114a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration); 115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, Reauth); 116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ProfileAlreadyConnected); 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess); 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure); 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens); 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ValidateAccountsFromTokensFailedUserInfo); 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ValidateAccountsFromTokensFailedTokenRequest); 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoop); 125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopWithDots); 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopMultiple); 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToCookie); 1286d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, 1296d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) StartReconcileAddToCookieTwice); 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToChrome); 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileBadPrimary); 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileOnlyOnce); 133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, 134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) StartReconcileWithSessionInfoExpiredDefault); 135116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, 136116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch MergeSessionCompletedWithBogusAccount); 137f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Register and unregister with dependent services. 139e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch void RegisterForCookieChanges(); 140e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch void UnregisterForCookieChanges(); 1411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void RegisterWithSigninManager(); 1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void UnregisterWithSigninManager(); 1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void RegisterWithTokenService(); 1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void UnregisterWithTokenService(); 1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 146f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool IsProfileConnected(); 147f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void DeleteFetchers(); 149f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // All actions with side effects. Virtual so that they can be overridden 1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // in tests. 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void PerformMergeAction(const std::string& account_id); 153116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void PerformAddToChromeAction( 154116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const std::string& account_id, 155116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch int session_index, 156116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const std::string& signin_scoped_device_id); 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void PerformLogoutAllAccountsAction(); 158cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void PerformAddAccountToTokenService( 159cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const std::string& account_id, 160cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const std::string& refresh_token); 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Used to remove an account from chrome and the cookie jar. 163cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void PerformStartRemoveAction(const std::string& account_id); 164cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void PerformFinishRemoveAction( 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& account_id, 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GoogleServiceAuthError& error, 167a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::vector<std::pair<std::string, bool> >& accounts); 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Used during periodic reconciliation. 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void StartReconcile(); 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void FinishReconcile(); 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void AbortReconcile(); 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void CalculateIfReconcileIsDone(); 174a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void ScheduleStartReconcileIfChromeAccountsChanged(); 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HandleSuccessfulAccountIdCheck(const std::string& account_id); 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HandleFailedAccountIdCheck(const std::string& account_id); 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HandleRefreshTokenFetched(const std::string& account_id, 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& refresh_token); 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void ContinueReconcileActionAfterGetGaiaAccounts( 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GoogleServiceAuthError& error, 182a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::vector<std::pair<std::string, bool> >& accounts); 183f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void ValidateAccountsFromTokenService(); 1846d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Note internally that this |account_id| is added to the cookie jar. 185116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool MarkAccountAsAddedToCookie(const std::string& account_id); 1866d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Note internally that this |account_id| is added to the token service. 1876d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) void MarkAccountAsAddedToChrome(const std::string& account_id); 188f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 189e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch void OnCookieChanged(const net::CanonicalCookie* cookie); 1901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Overriden from GaiaAuthConsumer. 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE; 193c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch virtual void OnListAccountsFailure(const GoogleServiceAuthError& error) 194c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch OVERRIDE; 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Overriden from MergeSessionHelper::Observer. 197c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch virtual void MergeSessionCompleted(const std::string& account_id, 198c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const GoogleServiceAuthError& error) 199c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch OVERRIDE; 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Overriden from OAuth2TokenService::Consumer. 202f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, 203f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const std::string& access_token, 204f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const base::Time& expiration_time) OVERRIDE; 205f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, 206f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const GoogleServiceAuthError& error) OVERRIDE; 2071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Overriden from OAuth2TokenService::Observer. 2091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; 210116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void OnEndBatchChanges() OVERRIDE; 2118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Overriden from SigninManagerBase::Observer. 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void GoogleSigninSucceeded(const std::string& username, 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& password) OVERRIDE; 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void GoogleSignedOut(const std::string& username) OVERRIDE; 2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void MayBeDoNextListAccounts(); 218f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 219c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // The ProfileOAuth2TokenService associated with this reconcilor. 220c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ProfileOAuth2TokenService* token_service_; 221c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 222c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // The SigninManager associated with this reconcilor. 223c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SigninManagerBase* signin_manager_; 224e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 225e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // The SigninClient associated with this reconcilor. 226e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch SigninClient* client_; 227e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeSessionHelper merge_session_helper_; 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<GaiaAuthFetcher> gaia_fetcher_; 2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool registered_with_token_service_; 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // True while the reconcilor is busy checking or managing the accounts in 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // this profile. 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool is_reconcile_started_; 235f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 236cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // True iff this is the first time the reconcilor is executing. 237cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool first_execution_; 238cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 239f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Used during reconcile action. 240a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // These members are used used to validate the gaia cookie. |gaia_accounts_| 241a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // holds the state of google accounts in the gaia cookie. Each element is 242a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // a pair that holds the email address of the account and a boolean that 243a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // indicates whether the account is valid or not. The accounts in the vector 244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // are ordered the in same way as the gaia cookie. 245f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool are_gaia_accounts_set_; 246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::vector<std::pair<std::string, bool> > gaia_accounts_; 247f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 248f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Used during reconcile action. 249f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // These members are used to validate the tokens in OAuth2TokenService. 250f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) std::string primary_account_; 251f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) std::vector<std::string> chrome_accounts_; 252f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<OAuth2TokenService::Request>* requests_; 2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ScopedVector<UserIdFetcher> user_id_fetchers_; 254a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ScopedVector<SigninOAuthHelper> refresh_token_fetchers_; 255a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EmailSet valid_chrome_accounts_; 256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EmailSet invalid_chrome_accounts_; 2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<std::string> add_to_cookie_; 2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<std::pair<std::string, int> > add_to_chrome_; 2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_; 261f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AccountReconcilor); 2638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}; 2648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 265c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ 266