Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / ios / chrome / browser / signin / signin_client_impl.h
blob1babc485352301e976bb2d25922d446d8f3dc491
1 // Copyright 2015 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 IOS_CHROME_BROWSER_SIGNIN_SIGNIN_CLIENT_IMPL_H_
6 #define IOS_CHROME_BROWSER_SIGNIN_SIGNIN_CLIENT_IMPL_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/signin/core/browser/signin_client.h"
13 #include "components/signin/core/browser/signin_error_controller.h"
14 #include "google_apis/gaia/gaia_oauth_client.h"
15 #include "google_apis/gaia/oauth2_token_service.h"
16 #include "net/base/network_change_notifier.h"
18 namespace content_settings {
19 class CookieSettings;
22 namespace ios {
23 class ChromeBrowserState;
26 class SigninClientImpl
27 : public SigninClient,
28 public net::NetworkChangeNotifier::NetworkChangeObserver,
29 public SigninErrorController::Observer,
30 public gaia::GaiaOAuthClient::Delegate,
31 public OAuth2TokenService::Consumer {
32 public:
33 SigninClientImpl(ios::ChromeBrowserState* browser_state,
34 SigninErrorController* signin_error_controller);
35 ~SigninClientImpl() override;
37 // Utility method.
38 static bool AllowsSigninCookies(ios::ChromeBrowserState* browser_state);
40 // If |for_ephemeral| is true, special kind of device ID for ephemeral users
41 // is generated.
42 static std::string GenerateSigninScopedDeviceID(bool for_ephemeral);
44 // SigninClient implementation.
45 void DoFinalInit() override;
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 // KeyedService implementation.
67 void Shutdown() override;
69 // Returns a string describing the chrome version environment. Version format:
70 // <Build Info> <OS> <Version number> (<Last change>)<channel or "-devel">
71 // If version information is unavailable, returns "invalid."
72 std::string GetProductVersion() override;
73 scoped_ptr<CookieChangedSubscription> AddCookieChangedCallback(
74 const GURL& url,
75 const std::string& name,
76 const net::CookieStore::CookieChangedCallback& callback) override;
77 void OnSignedIn(const std::string& account_id,
78 const std::string& gaia_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 // net::NetworkChangeController::NetworkChangeObserver implementation.
101 void OnNetworkChanged(
102 net::NetworkChangeNotifier::ConnectionType type) override;
104 private:
105 ios::ChromeBrowserState* browser_state_;
107 SigninErrorController* signin_error_controller_;
108 std::list<base::Closure> delayed_callbacks_;
110 scoped_ptr<gaia::GaiaOAuthClient> oauth_client_;
111 scoped_ptr<OAuth2TokenService::Request> oauth_request_;
113 DISALLOW_COPY_AND_ASSIGN(SigninClientImpl);
116 #endif // IOS_CHROME_BROWSER_SIGNIN_SIGNIN_CLIENT_IMPL_H_