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 COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_CLIENT_H_
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_CLIENT_H_
8 #include "base/callback.h"
9 #include "base/callback_list.h"
10 #include "base/time/time.h"
11 #include "components/keyed_service/core/keyed_service.h"
12 #include "components/signin/core/browser/account_tracker_service.h"
13 #include "components/signin/core/browser/webdata/token_web_data.h"
14 #include "google_apis/gaia/gaia_auth_fetcher.h"
15 #include "net/cookies/cookie_store.h"
19 class SigninManagerBase
;
22 namespace content_settings
{
27 class URLRequestContextGetter
;
32 // TODO(msarda): http://crbug.com/358544 Remove this iOS specific code from the
34 class ProfileOAuth2TokenServiceIOSProvider
;
38 // An interface that needs to be supplied to the Signin component by its
40 class SigninClient
: public KeyedService
{
42 // The subcription for cookie changed notifications.
43 class CookieChangedSubscription
{
45 virtual ~CookieChangedSubscription() {};
48 ~SigninClient() override
{}
50 // Call when done local initialization and SigninClient can initiate any work
51 // it has to do that may require other components (like ProfileManager) to be
53 virtual void DoFinalInit() = 0;
55 // Gets the preferences associated with the client.
56 virtual PrefService
* GetPrefs() = 0;
58 // Gets the TokenWebData instance associated with the client.
59 virtual scoped_refptr
<TokenWebData
> GetDatabase() = 0;
61 // Returns whether it is possible to revoke credentials.
62 virtual bool CanRevokeCredentials() = 0;
64 // Returns device id that is scoped to single signin. This device id will be
65 // regenerated if user signs out and signs back in.
66 // When refresh token is requested for this user it will be annotated with
68 virtual std::string
GetSigninScopedDeviceId() = 0;
70 // Perform Chrome-specific sign out. This happens when user signs out or about
72 virtual void OnSignedOut() = 0;
74 // Returns the URL request context information associated with the client.
75 virtual net::URLRequestContextGetter
* GetURLRequestContext() = 0;
77 // Returns whether the user's credentials should be merged into the cookie
78 // jar on signin completion.
79 virtual bool ShouldMergeSigninCredentialsIntoCookieJar() = 0;
81 // Returns a string containing the version info of the product in which the
82 // Signin component is being used.
83 virtual std::string
GetProductVersion() = 0;
85 // Adds a callback to be called each time a cookie for |url| with name |name|
87 // Note that |callback| will always be called on the thread that
88 // |AddCookieChangedCallback| was called on.
89 virtual scoped_ptr
<CookieChangedSubscription
> AddCookieChangedCallback(
91 const std::string
& name
,
92 const net::CookieStore::CookieChangedCallback
& callback
) = 0;
94 // Called after Google signin has succeeded.
95 virtual void OnSignedIn(const std::string
& account_id
,
96 const std::string
& gaia_id
,
97 const std::string
& username
,
98 const std::string
& password
) {}
100 // Called after Google signin has succeeded and GetUserInfo has returned.
101 virtual void PostSignedIn(const std::string
& account_id
,
102 const std::string
& username
,
103 const std::string
& password
) {}
105 virtual bool IsFirstRun() const = 0;
106 virtual base::Time
GetInstallDate() = 0;
108 // Returns true if GAIA cookies are allowed in the content area.
109 virtual bool AreSigninCookiesAllowed() = 0;
111 // Adds an observer to listen for changes to the state of sign in cookie
113 virtual void AddContentSettingsObserver(
114 content_settings::Observer
* observer
) = 0;
115 virtual void RemoveContentSettingsObserver(
116 content_settings::Observer
* observer
) = 0;
118 // Allows this sign-in client to update the account info before attempting
119 // to fetch it from GAIA. This avoids fetching the account info from
120 // GAIA when the data it already available on the client.
121 // |out_account_info->account_id| is not-empty and corresponds to an existing
124 // Returns true if |out_account_info| was updated.
125 virtual bool UpdateAccountInfo(
126 AccountTrackerService::AccountInfo
* out_account_info
) = 0;
129 // TODO(msarda): http://crbug.com/358544 Remove this iOS specific code from
130 // the core SigninClient.
131 virtual ios::ProfileOAuth2TokenServiceIOSProvider
* GetIOSProvider() = 0;
134 // Execute |callback| if and when there is a network connection.
135 virtual void DelayNetworkCall(const base::Closure
& callback
) = 0;
137 // Creates and returns a new platform-specific GaiaAuthFetcher. It is the
138 // responsability of the caller to delete the returned object.
139 virtual GaiaAuthFetcher
* CreateGaiaAuthFetcher(
140 GaiaAuthConsumer
* consumer
,
141 const std::string
& source
,
142 net::URLRequestContextGetter
* getter
) = 0;
145 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_CLIENT_H_