signin_account_id_helper.h revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
1e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// found in the LICENSE file. 4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 5e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ACCOUNT_ID_HELPER_H_ 6e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ACCOUNT_ID_HELPER_H_ 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 8e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "components/signin/core/browser/signin_manager.h" 9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/gaia/gaia_oauth_client.h" 10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/gaia/oauth2_token_service.h" 11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class CookieSettings; 13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class GaiaAuthFetcher; 14effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass ProfileOAuth2TokenService; 15effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass SigninClient; 16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// The helper class for managing the obfuscated GAIA ID of the primary 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// account. It fetches the ID when user first signs into Chrome or when user 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// opens a connected Chrome profile without an obfuscated GAIA ID, and stores 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the ID in the profile preference. 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class SigninAccountIdHelper : public SigninManagerBase::Observer, 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public OAuth2TokenService::Observer { 23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public: 24effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SigninAccountIdHelper(SigninClient* client, 25effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ProfileOAuth2TokenService* token_service, 26effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SigninManagerBase* signin_manager); 27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ~SigninAccountIdHelper(); 28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // SigninManagerBase::Observer: 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void GoogleSignedOut(const std::string& username) OVERRIDE; 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // OAuth2TokenService::Observer: 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Disables network requests for testing to avoid messing up with irrelevant 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // tests. 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static void SetDisableForTest(bool disable_for_test); 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private: 40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Invoked when receiving the response for |account_id_fetcher_|. 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void OnPrimaryAccountIdFetched(const std::string& gaia_id); 42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Helper class for fetching the obfuscated account ID. 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class GaiaIdFetcher; 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<GaiaIdFetcher> id_fetcher_; 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static bool disable_for_test_; 48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 49effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SigninClient* client_; 50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ProfileOAuth2TokenService* token_service_; 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SigninManagerBase* signin_manager_; 52a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(SigninAccountIdHelper); 54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}; 55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 56e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ACCOUNT_ID_HELPER_H_ 57