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.
5 #ifndef CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_
6 #define CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "components/signin/core/browser/signin_client.h"
11 #include "components/signin/core/browser/signin_error_controller.h"
12 #include "google_apis/gaia/gaia_oauth_client.h"
13 #include "google_apis/gaia/oauth2_token_service.h"
15 #if !defined(OS_CHROMEOS)
16 #include "net/base/network_change_notifier.h"
22 class ChromeSigninClient
23 : public SigninClient
,
24 #if !defined(OS_CHROMEOS)
25 public net::NetworkChangeNotifier::NetworkChangeObserver
,
27 public SigninErrorController::Observer
,
28 public gaia::GaiaOAuthClient::Delegate
,
29 public OAuth2TokenService::Consumer
{
31 explicit ChromeSigninClient(
32 Profile
* profile
, SigninErrorController
* signin_error_controller
);
33 ~ChromeSigninClient() override
;
34 void Shutdown() override
;
35 void DoFinalInit() override
;
38 static bool ProfileAllowsSigninCookies(Profile
* profile
);
39 static bool SettingsAllowSigninCookies(CookieSettings
* cookie_settings
);
41 // If |for_ephemeral| is true, special kind of device ID for ephemeral users
43 static std::string
GenerateSigninScopedDeviceID(bool for_ephemeral
);
45 // SigninClient implementation.
46 PrefService
* GetPrefs() override
;
47 scoped_refptr
<TokenWebData
> GetDatabase() override
;
48 bool CanRevokeCredentials() override
;
49 std::string
GetSigninScopedDeviceId() override
;
50 void OnSignedOut() override
;
51 net::URLRequestContextGetter
* GetURLRequestContext() override
;
52 bool ShouldMergeSigninCredentialsIntoCookieJar() override
;
53 bool IsFirstRun() const override
;
54 base::Time
GetInstallDate() override
;
55 bool AreSigninCookiesAllowed() override
;
56 void AddContentSettingsObserver(
57 content_settings::Observer
* observer
) override
;
58 void RemoveContentSettingsObserver(
59 content_settings::Observer
* observer
) override
;
60 void DelayNetworkCall(const base::Closure
& callback
) override
;
61 GaiaAuthFetcher
* CreateGaiaAuthFetcher(
62 GaiaAuthConsumer
* consumer
,
63 const std::string
& source
,
64 net::URLRequestContextGetter
* getter
) override
;
66 // Returns a string describing the chrome version environment. Version format:
67 // <Build Info> <OS> <Version number> (<Last change>)<channel or "-devel">
68 // If version information is unavailable, returns "invalid."
69 std::string
GetProductVersion() override
;
70 scoped_ptr
<CookieChangedSubscription
> AddCookieChangedCallback(
72 const std::string
& name
,
73 const net::CookieStore::CookieChangedCallback
& callback
) override
;
74 void OnSignedIn(const std::string
& account_id
,
75 const std::string
& gaia_id
,
76 const std::string
& username
,
77 const std::string
& password
) override
;
78 void PostSignedIn(const std::string
& account_id
,
79 const std::string
& username
,
80 const std::string
& password
) override
;
81 bool UpdateAccountInfo(
82 AccountTrackerService::AccountInfo
* out_account_info
) override
;
84 // SigninErrorController::Observer implementation.
85 void OnErrorChanged() override
;
87 // gaia::GaiaOAuthClient::Delegate implementation.
88 void OnGetTokenInfoResponse(
89 scoped_ptr
<base::DictionaryValue
> token_info
) override
;
90 void OnOAuthError() override
;
91 void OnNetworkError(int response_code
) override
;
93 // OAuth2TokenService::Consumer implementation
94 void OnGetTokenSuccess(const OAuth2TokenService::Request
* request
,
95 const std::string
& access_token
,
96 const base::Time
& expiration_time
) override
;
97 void OnGetTokenFailure(const OAuth2TokenService::Request
* request
,
98 const GoogleServiceAuthError
& error
) override
;
100 #if !defined(OS_CHROMEOS)
101 // net::NetworkChangeController::NetworkChangeObserver implementation.
102 void OnNetworkChanged(net::NetworkChangeNotifier::ConnectionType type
)
107 void MaybeFetchSigninTokenHandle();
111 SigninErrorController
* signin_error_controller_
;
112 #if !defined(OS_CHROMEOS)
113 std::list
<base::Closure
> delayed_callbacks_
;
116 scoped_ptr
<gaia::GaiaOAuthClient
> oauth_client_
;
117 scoped_ptr
<OAuth2TokenService::Request
> oauth_request_
;
119 DISALLOW_COPY_AND_ASSIGN(ChromeSigninClient
);
122 #endif // CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_