Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: components/signin/core/browser/gaia_cookie_manager_service.h

Issue 1044933002: GaiaCookieServiceManager handles general request types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More unit tests; Reviewed LogOutInternal; other rogerta comments. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H 5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
(...skipping 17 matching lines...) Expand all
28 // changes to the cookie must be serialized. 28 // changes to the cookie must be serialized.
29 // 29 //
30 // Also checks the External CC result to ensure no services that consume the 30 // Also checks the External CC result to ensure no services that consume the
31 // GAIA cookie are blocked (such as youtube). This is executed once for the 31 // GAIA cookie are blocked (such as youtube). This is executed once for the
32 // lifetime of this object, when the first call is made to AddAccountToCookie. 32 // lifetime of this object, when the first call is made to AddAccountToCookie.
33 class GaiaCookieManagerService : public KeyedService, 33 class GaiaCookieManagerService : public KeyedService,
34 public GaiaAuthConsumer, 34 public GaiaAuthConsumer,
35 public UbertokenConsumer, 35 public UbertokenConsumer,
36 public net::URLFetcherDelegate { 36 public net::URLFetcherDelegate {
37 public: 37 public:
38 typedef base::Callback<void(const std::string& data,
39 const GoogleServiceAuthError& error)>
40 ListAccountsCallback;
41
42
43 enum GaiaCookieRequestType {
44 ADD_ACCOUNT,
45 LOG_OUT,
46 LIST_ACCOUNTS
47 };
48
49 // Contains the information and parameters for any request.
50 class GaiaCookieRequest {
51 public:
52 ~GaiaCookieRequest();
53
54 GaiaCookieRequestType request_type() const { return request_type_; }
55 const std::string& account_id() const {return account_id_; }
56 const GaiaCookieManagerService::ListAccountsCallback&
57 list_accounts_callback() const {
58 return list_accounts_callback_;
59 }
60
61 static GaiaCookieRequest CreateAddAccountRequest(
62 const std::string& account_id);
63 static GaiaCookieRequest CreateLogOutRequest();
64 static GaiaCookieRequest CreateListAccountsRequest(
65 const GaiaCookieManagerService::ListAccountsCallback&
66 list_accounts_callback);
67
68 private:
69 GaiaCookieRequest(
70 GaiaCookieRequestType request_type,
71 const std::string& account_id,
72 const GaiaCookieManagerService::ListAccountsCallback&
73 list_accounts_callback);
74
75 GaiaCookieRequestType request_type_;
76 std::string account_id_;
77 GaiaCookieManagerService::ListAccountsCallback list_accounts_callback_;
78 };
79
38 class Observer { 80 class Observer {
39 public: 81 public:
40 // Called whenever a merge session is completed. The account that was 82 // Called whenever a merge session is completed. The account that was
41 // merged is given by |account_id|. If |error| is equal to 83 // merged is given by |account_id|. If |error| is equal to
42 // GoogleServiceAuthError::AuthErrorNone() then the merge succeeeded. 84 // GoogleServiceAuthError::AuthErrorNone() then the merge succeeeded.
43 virtual void OnAddAccountToCookieCompleted( 85 virtual void OnAddAccountToCookieCompleted(
44 const std::string& account_id, 86 const std::string& account_id,
45 const GoogleServiceAuthError& error) = 0; 87 const GoogleServiceAuthError& error) = 0;
46 88
47 // Called when ExternalCcResultFetcher completes. From this moment 89 // Called when ExternalCcResultFetcher completes. From this moment
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 DISALLOW_COPY_AND_ASSIGN(ExternalCcResultFetcher); 158 DISALLOW_COPY_AND_ASSIGN(ExternalCcResultFetcher);
117 }; 159 };
118 160
119 GaiaCookieManagerService(OAuth2TokenService* token_service, 161 GaiaCookieManagerService(OAuth2TokenService* token_service,
120 const std::string& source, 162 const std::string& source,
121 SigninClient* signin_client); 163 SigninClient* signin_client);
122 ~GaiaCookieManagerService() override; 164 ~GaiaCookieManagerService() override;
123 165
124 void AddAccountToCookie(const std::string& account_id); 166 void AddAccountToCookie(const std::string& account_id);
125 167
168 void ListAccounts(const ListAccountsCallback& callback);
169
126 // Add or remove observers of this helper. 170 // Add or remove observers of this helper.
127 void AddObserver(Observer* observer); 171 void AddObserver(Observer* observer);
128 void RemoveObserver(Observer* observer); 172 void RemoveObserver(Observer* observer);
129 173
130 // Cancel all login requests. 174 // Cancel all login requests.
131 void CancelAll(); 175 void CancelAll();
132 176
133 // Signout of |account_id| given a list of accounts already signed in.
134 // Since this involves signing out of all accounts and resigning back in,
135 // the order which |accounts| are given is important as it will dictate
136 // the sign in order. |account_id| does not have to be in |accounts|.
137 void LogOut(const std::string& account_id,
138 const std::vector<std::string>& accounts);
139
140 // Signout all accounts. 177 // Signout all accounts.
141 void LogOutAllAccounts(); 178 void LogOutAllAccounts();
142 179
143 // Call observers when merge session completes. This public so that callers 180 // Call observers when merge session completes. This public so that callers
144 // that know that a given account is already in the cookie jar can simply 181 // that know that a given account is already in the cookie jar can simply
145 // inform the observers. 182 // inform the observers.
146 void SignalComplete(const std::string& account_id, 183 void SignalComplete(const std::string& account_id,
147 const GoogleServiceAuthError& error); 184 const GoogleServiceAuthError& error);
148 185
149 // Returns true of there are pending log ins or outs. 186 // Returns true of there are pending log ins or outs.
150 bool is_running() const { return accounts_.size() > 0; } 187 bool is_running() const { return requests_.size() > 0; }
151 188
152 // Start the process of fetching the external check connection result so that 189 // Start the process of fetching the external check connection result so that
153 // its ready when we try to perform a merge session. 190 // its ready when we try to perform a merge session.
154 void StartFetchingExternalCcResult(); 191 void StartFetchingExternalCcResult();
155 192
156 private: 193 private:
157 net::URLRequestContextGetter* request_context() { 194 net::URLRequestContextGetter* request_context() {
158 return signin_client_->GetURLRequestContext(); 195 return signin_client_->GetURLRequestContext();
159 } 196 }
160 197
161 // Overridden from UbertokenConsumer. 198 // Overridden from UbertokenConsumer.
162 void OnUbertokenSuccess(const std::string& token) override; 199 void OnUbertokenSuccess(const std::string& token) override;
163 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; 200 void OnUbertokenFailure(const GoogleServiceAuthError& error) override;
164 201
165 // Overridden from GaiaAuthConsumer. 202 // Overridden from GaiaAuthConsumer.
166 void OnMergeSessionSuccess(const std::string& data) override; 203 void OnMergeSessionSuccess(const std::string& data) override;
167 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; 204 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override;
168 205
169 void LogOutInternal(const std::string& account_id,
170 const std::vector<std::string>& accounts);
171
172 // Starts the proess of fetching the uber token and performing a merge session 206 // Starts the proess of fetching the uber token and performing a merge session
173 // for the next account. Virtual so that it can be overriden in tests. 207 // for the next account. Virtual so that it can be overriden in tests.
174 virtual void StartFetching(); 208 virtual void StartFetchingUbertoken();
175 209
176 // Virtual for testing purpose. 210 // Virtual for testing purpose.
177 virtual void StartLogOutUrlFetch(); 211 virtual void StartLogOutUrlFetch();
178 212
179 // Start the next merge session, if needed. 213 // Start the next request, if needed.
180 void HandleNextAccount(); 214 void HandleNextRequest();
181 215
182 // Overridden from URLFetcherDelgate. 216 // Overridden from URLFetcherDelgate.
183 void OnURLFetchComplete(const net::URLFetcher* source) override; 217 void OnURLFetchComplete(const net::URLFetcher* source) override;
184 218
185 OAuth2TokenService* token_service_; 219 OAuth2TokenService* token_service_;
186 SigninClient* signin_client_; 220 SigninClient* signin_client_;
187 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; 221 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_;
188 scoped_ptr<UbertokenFetcher> uber_token_fetcher_; 222 scoped_ptr<UbertokenFetcher> uber_token_fetcher_;
189 ExternalCcResultFetcher external_cc_result_fetcher_; 223 ExternalCcResultFetcher external_cc_result_fetcher_;
190 224
191 // A worklist for this class. Accounts names are stored here if 225 // A worklist for this class. Stores any pending requests that couldn't be
192 // we are pending a signin action for that account. Empty strings 226 // executed right away, since this class only permits one request to be
193 // represent a signout request. 227 // executed at a time.
194 std::deque<std::string> accounts_; 228 std::deque<GaiaCookieRequest> requests_;
195 229
196 // List of observers to notify when merge session completes. 230 // List of observers to notify when merge session completes.
197 // Makes sure list is empty on destruction. 231 // Makes sure list is empty on destruction.
198 ObserverList<Observer, true> observer_list_; 232 ObserverList<Observer, true> observer_list_;
199 233
200 // Source to use with GAIA endpoints for accounting. 234 // Source to use with GAIA endpoints for accounting.
201 std::string source_; 235 std::string source_;
202 236
203 DISALLOW_COPY_AND_ASSIGN(GaiaCookieManagerService); 237 DISALLOW_COPY_AND_ASSIGN(GaiaCookieManagerService);
204 }; 238 };
205 239
206 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H 240 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698