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:
301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void GoogleSignedOut(const std::string& account_id,
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                               const std::string& username) OVERRIDE;
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // OAuth2TokenService::Observer:
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Disables network requests for testing to avoid messing up with irrelevant
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // tests.
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static void SetDisableForTest(bool disable_for_test);
39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private:
41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Invoked when receiving the response for |account_id_fetcher_|.
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void OnPrimaryAccountIdFetched(const std::string& gaia_id);
43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Helper class for fetching the obfuscated account ID.
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  class GaiaIdFetcher;
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<GaiaIdFetcher> id_fetcher_;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static bool disable_for_test_;
49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  SigninClient* client_;
51effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ProfileOAuth2TokenService* token_service_;
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SigninManagerBase* signin_manager_;
53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SigninAccountIdHelper);
55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)};
56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
57e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#endif  // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ACCOUNT_ID_HELPER_H_
58