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
;
30 // An interface that needs to be supplied to the Signin component by its
32 class SigninClient
: public KeyedService
{
34 // The subcription for cookie changed notifications.
35 class CookieChangedSubscription
{
37 virtual ~CookieChangedSubscription() {};
40 ~SigninClient() override
{}
42 // If |for_ephemeral| is true, special kind of device ID for ephemeral users
44 static std::string
GenerateSigninScopedDeviceID(bool for_ephemeral
);
49 // Call when done local initialization and SigninClient can initiate any work
50 // it has to do that may require other components (like ProfileManager) to be
52 virtual void DoFinalInit() = 0;
54 // Gets the preferences associated with the client.
55 virtual PrefService
* GetPrefs() = 0;
57 // Gets the TokenWebData instance associated with the client.
58 virtual scoped_refptr
<TokenWebData
> GetDatabase() = 0;
60 // Returns whether it is possible to revoke credentials.
61 virtual bool CanRevokeCredentials() = 0;
63 // Returns device id that is scoped to single signin. This device id will be
64 // regenerated if user signs out and signs back in.
65 // When refresh token is requested for this user it will be annotated with
67 virtual std::string
GetSigninScopedDeviceId() = 0;
69 // Returns the URL request context information associated with the client.
70 virtual net::URLRequestContextGetter
* GetURLRequestContext() = 0;
72 // Returns whether the user's credentials should be merged into the cookie
73 // jar on signin completion.
74 virtual bool ShouldMergeSigninCredentialsIntoCookieJar() = 0;
76 // Returns a string containing the version info of the product in which the
77 // Signin component is being used.
78 virtual std::string
GetProductVersion() = 0;
80 // Adds a callback to be called each time a cookie for |url| with name |name|
82 // Note that |callback| will always be called on the thread that
83 // |AddCookieChangedCallback| was called on.
84 virtual scoped_ptr
<CookieChangedSubscription
> AddCookieChangedCallback(
86 const std::string
& name
,
87 const net::CookieStore::CookieChangedCallback
& callback
) = 0;
89 // Called after Google signin has succeeded.
90 virtual void OnSignedIn(const std::string
& account_id
,
91 const std::string
& gaia_id
,
92 const std::string
& username
,
93 const std::string
& password
) {}
95 // Called after Google signin has succeeded and GetUserInfo has returned.
96 virtual void PostSignedIn(const std::string
& account_id
,
97 const std::string
& username
,
98 const std::string
& password
) {}
100 virtual bool IsFirstRun() const = 0;
101 virtual base::Time
GetInstallDate() = 0;
103 // Returns true if GAIA cookies are allowed in the content area.
104 virtual bool AreSigninCookiesAllowed() = 0;
106 // Adds an observer to listen for changes to the state of sign in cookie
108 virtual void AddContentSettingsObserver(
109 content_settings::Observer
* observer
) = 0;
110 virtual void RemoveContentSettingsObserver(
111 content_settings::Observer
* observer
) = 0;
113 // Allows this sign-in client to update the account info before attempting
114 // to fetch it from GAIA. This avoids fetching the account info from
115 // GAIA when the data it already available on the client.
116 // |out_account_info->account_id| is not-empty and corresponds to an existing
119 // Returns true if |out_account_info| was updated.
120 virtual bool UpdateAccountInfo(
121 AccountTrackerService::AccountInfo
* out_account_info
) = 0;
123 // Execute |callback| if and when there is a network connection.
124 virtual void DelayNetworkCall(const base::Closure
& callback
) = 0;
126 // Creates and returns a new platform-specific GaiaAuthFetcher. It is the
127 // responsability of the caller to delete the returned object.
128 virtual GaiaAuthFetcher
* CreateGaiaAuthFetcher(
129 GaiaAuthConsumer
* consumer
,
130 const std::string
& source
,
131 net::URLRequestContextGetter
* getter
) = 0;
134 // Returns device id that is scoped to single signin.
135 // Stores the ID in the kGoogleServicesSigninScopedDeviceId pref.
136 std::string
GetOrCreateScopedDeviceIdPref(PrefService
* prefs
);
139 // Perform Chrome-specific sign out. This happens when user signs out or about
141 // This method should not be called from the outside of SigninClient. External
142 // callers must use SignOut() instead.
143 virtual void OnSignedOut() = 0;
146 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_CLIENT_H_