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"
19 namespace content_settings
{
25 class ChromeSigninClient
26 : public SigninClient
,
27 #if !defined(OS_CHROMEOS)
28 public net::NetworkChangeNotifier::NetworkChangeObserver
,
30 public SigninErrorController::Observer
,
31 public gaia::GaiaOAuthClient::Delegate
,
32 public OAuth2TokenService::Consumer
{
34 explicit ChromeSigninClient(
35 Profile
* profile
, SigninErrorController
* signin_error_controller
);
36 ~ChromeSigninClient() override
;
37 void Shutdown() override
;
38 void DoFinalInit() override
;
41 static bool ProfileAllowsSigninCookies(Profile
* profile
);
43 // SigninClient implementation.
44 PrefService
* GetPrefs() override
;
45 scoped_refptr
<TokenWebData
> GetDatabase() override
;
46 bool CanRevokeCredentials() override
;
47 std::string
GetSigninScopedDeviceId() override
;
48 void OnSignedOut() override
;
49 net::URLRequestContextGetter
* GetURLRequestContext() override
;
50 bool ShouldMergeSigninCredentialsIntoCookieJar() override
;
51 bool IsFirstRun() const override
;
52 base::Time
GetInstallDate() override
;
53 bool AreSigninCookiesAllowed() override
;
54 void AddContentSettingsObserver(
55 content_settings::Observer
* observer
) override
;
56 void RemoveContentSettingsObserver(
57 content_settings::Observer
* observer
) override
;
58 void DelayNetworkCall(const base::Closure
& callback
) override
;
59 GaiaAuthFetcher
* CreateGaiaAuthFetcher(
60 GaiaAuthConsumer
* consumer
,
61 const std::string
& source
,
62 net::URLRequestContextGetter
* getter
) override
;
64 // Returns a string describing the chrome version environment. Version format:
65 // <Build Info> <OS> <Version number> (<Last change>)<channel or "-devel">
66 // If version information is unavailable, returns "invalid."
67 std::string
GetProductVersion() override
;
68 scoped_ptr
<CookieChangedSubscription
> AddCookieChangedCallback(
70 const std::string
& name
,
71 const net::CookieStore::CookieChangedCallback
& callback
) override
;
72 void OnSignedIn(const std::string
& account_id
,
73 const std::string
& gaia_id
,
74 const std::string
& username
,
75 const std::string
& password
) override
;
76 void PostSignedIn(const std::string
& account_id
,
77 const std::string
& username
,
78 const std::string
& password
) override
;
79 bool UpdateAccountInfo(AccountInfo
* out_account_info
) override
;
81 // SigninErrorController::Observer implementation.
82 void OnErrorChanged() override
;
84 // gaia::GaiaOAuthClient::Delegate implementation.
85 void OnGetTokenInfoResponse(
86 scoped_ptr
<base::DictionaryValue
> token_info
) override
;
87 void OnOAuthError() override
;
88 void OnNetworkError(int response_code
) override
;
90 // OAuth2TokenService::Consumer implementation
91 void OnGetTokenSuccess(const OAuth2TokenService::Request
* request
,
92 const std::string
& access_token
,
93 const base::Time
& expiration_time
) override
;
94 void OnGetTokenFailure(const OAuth2TokenService::Request
* request
,
95 const GoogleServiceAuthError
& error
) override
;
97 #if !defined(OS_CHROMEOS)
98 // net::NetworkChangeController::NetworkChangeObserver implementation.
99 void OnNetworkChanged(net::NetworkChangeNotifier::ConnectionType type
)
104 void MaybeFetchSigninTokenHandle();
108 SigninErrorController
* signin_error_controller_
;
109 #if !defined(OS_CHROMEOS)
110 std::list
<base::Closure
> delayed_callbacks_
;
113 scoped_ptr
<gaia::GaiaOAuthClient
> oauth_client_
;
114 scoped_ptr
<OAuth2TokenService::Request
> oauth_request_
;
116 DISALLOW_COPY_AND_ASSIGN(ChromeSigninClient
);
119 #endif // CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_