Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / components / signin / core / browser / signin_account_id_helper.h
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ACCOUNT_ID_HELPER_H_
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ACCOUNT_ID_HELPER_H_
7
8 #include "components/signin/core/browser/signin_manager.h"
9 #include "google_apis/gaia/gaia_oauth_client.h"
10 #include "google_apis/gaia/oauth2_token_service.h"
11
12 class CookieSettings;
13 class GaiaAuthFetcher;
14 class ProfileOAuth2TokenService;
15 class SigninClient;
16
17 // The helper class for managing the obfuscated GAIA ID of the primary
18 // account. It fetches the ID when user first signs into Chrome or when user
19 // opens a connected Chrome profile without an obfuscated GAIA ID, and stores
20 // the ID in the profile preference.
21 class SigninAccountIdHelper : public SigninManagerBase::Observer,
22                               public OAuth2TokenService::Observer {
23  public:
24   SigninAccountIdHelper(SigninClient* client,
25                         ProfileOAuth2TokenService* token_service,
26                         SigninManagerBase* signin_manager);
27   virtual ~SigninAccountIdHelper();
28
29   // SigninManagerBase::Observer:
30   virtual void GoogleSignedOut(const std::string& username) OVERRIDE;
31
32   // OAuth2TokenService::Observer:
33   virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
34
35   // Disables network requests for testing to avoid messing up with irrelevant
36   // tests.
37   static void SetDisableForTest(bool disable_for_test);
38
39  private:
40   // Invoked when receiving the response for |account_id_fetcher_|.
41   void OnPrimaryAccountIdFetched(const std::string& gaia_id);
42
43   // Helper class for fetching the obfuscated account ID.
44   class GaiaIdFetcher;
45   scoped_ptr<GaiaIdFetcher> id_fetcher_;
46
47   static bool disable_for_test_;
48
49   SigninClient* client_;
50   ProfileOAuth2TokenService* token_service_;
51   SigninManagerBase* signin_manager_;
52
53   DISALLOW_COPY_AND_ASSIGN(SigninAccountIdHelper);
54 };
55
56 #endif  // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ACCOUNT_ID_HELPER_H_