Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 12 #include "components/signin/core/browser/signin_client.h" | 12 #include "components/signin/core/browser/signin_client.h" |
| 13 #include "google_apis/gaia/gaia_auth_consumer.h" | 13 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 14 #include "google_apis/gaia/ubertoken_fetcher.h" | 14 #include "google_apis/gaia/ubertoken_fetcher.h" |
| 15 #include "net/url_request/url_fetcher_delegate.h" | 15 #include "net/url_request/url_fetcher_delegate.h" |
| 16 | 16 |
| 17 class GaiaAuthFetcher; | 17 class GaiaAuthFetcher; |
| 18 class GaiaCookieRequest; | |
|
Roger Tawa OOO till Jul 10th
2015/03/30 18:57:23
What is this forward declare for?
Mike Lerman
2015/04/01 16:39:35
For... no good reason.
| |
| 18 class GoogleServiceAuthError; | 19 class GoogleServiceAuthError; |
| 19 class OAuth2TokenService; | 20 class OAuth2TokenService; |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 class URLFetcher; | 23 class URLFetcher; |
| 23 } | 24 } |
| 24 | 25 |
| 25 // Merges a Google account known to Chrome into the cookie jar. When merging | 26 // Merges a Google account known to Chrome into the cookie jar. When merging |
| 26 // multiple accounts, one instance of the helper is better than multiple | 27 // multiple accounts, one instance of the helper is better than multiple |
| 27 // instances if there is the possibility that they run concurrently, since | 28 // instances if there is the possibility that they run concurrently, since |
| 28 // changes to the cookie must be serialized. | 29 // changes to the cookie must be serialized. |
| 29 // | 30 // |
| 30 // Also checks the External CC result to ensure no services that consume the | 31 // 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 | 32 // 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. | 33 // lifetime of this object, when the first call is made to AddAccountToCookie. |
| 33 class GaiaCookieManagerService : public KeyedService, | 34 class GaiaCookieManagerService : public KeyedService, |
| 34 public GaiaAuthConsumer, | 35 public GaiaAuthConsumer, |
| 35 public UbertokenConsumer, | 36 public UbertokenConsumer, |
| 36 public net::URLFetcherDelegate { | 37 public net::URLFetcherDelegate { |
| 37 public: | 38 public: |
| 39 typedef base::Callback<void(const std::string& data, | |
| 40 const GoogleServiceAuthError& error)> | |
| 41 ListAccountsCallback; | |
| 42 | |
| 43 | |
| 44 enum GaiaCookieRequestType { | |
| 45 ADD_ACCOUNT, | |
| 46 LOG_OUT, | |
| 47 LIST_ACCOUNTS | |
| 48 }; | |
| 49 | |
| 50 // Contains the information and parameters for any request. | |
| 51 class GaiaCookieRequest { | |
| 52 public: | |
| 53 ~GaiaCookieRequest(); | |
| 54 | |
| 55 GaiaCookieRequestType request_type() const { return request_type_; } | |
| 56 const std::string& account_id() const {return account_id_; } | |
| 57 const GaiaCookieManagerService::ListAccountsCallback& | |
| 58 list_accounts_callback() const { | |
| 59 return list_accounts_callback_; | |
| 60 } | |
| 61 | |
| 62 static GaiaCookieRequest AddAccountRequest( | |
| 63 const std::string& account_id); | |
| 64 static GaiaCookieRequest LogOutRequest(); | |
| 65 static GaiaCookieRequest ListAccountsRequest( | |
| 66 const GaiaCookieManagerService::ListAccountsCallback& | |
| 67 list_accounts_callback); | |
|
Roger Tawa OOO till Jul 10th
2015/03/30 18:57:23
Should these be called CreateXXX() ?
Mike Lerman
2015/04/01 16:39:35
Sure.
| |
| 68 | |
| 69 private: | |
| 70 GaiaCookieRequest( | |
| 71 GaiaCookieRequestType request_type, | |
| 72 const std::string& account_id, | |
| 73 const GaiaCookieManagerService::ListAccountsCallback& | |
| 74 list_accounts_callback); | |
| 75 | |
| 76 GaiaCookieRequestType request_type_; | |
| 77 std::string account_id_; | |
| 78 GaiaCookieManagerService::ListAccountsCallback list_accounts_callback_; | |
| 79 }; | |
| 80 | |
| 38 class Observer { | 81 class Observer { |
| 39 public: | 82 public: |
| 40 // Called whenever a merge session is completed. The account that was | 83 // Called whenever a merge session is completed. The account that was |
| 41 // merged is given by |account_id|. If |error| is equal to | 84 // merged is given by |account_id|. If |error| is equal to |
| 42 // GoogleServiceAuthError::AuthErrorNone() then the merge succeeeded. | 85 // GoogleServiceAuthError::AuthErrorNone() then the merge succeeeded. |
| 43 virtual void OnAddAccountToCookieCompleted( | 86 virtual void OnAddAccountToCookieCompleted( |
| 44 const std::string& account_id, | 87 const std::string& account_id, |
| 45 const GoogleServiceAuthError& error) = 0; | 88 const GoogleServiceAuthError& error) = 0; |
| 46 | 89 |
| 47 // Called when ExternalCcResultFetcher completes. From this moment | 90 // Called when ExternalCcResultFetcher completes. From this moment |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 DISALLOW_COPY_AND_ASSIGN(ExternalCcResultFetcher); | 159 DISALLOW_COPY_AND_ASSIGN(ExternalCcResultFetcher); |
| 117 }; | 160 }; |
| 118 | 161 |
| 119 GaiaCookieManagerService(OAuth2TokenService* token_service, | 162 GaiaCookieManagerService(OAuth2TokenService* token_service, |
| 120 const std::string& source, | 163 const std::string& source, |
| 121 SigninClient* signin_client); | 164 SigninClient* signin_client); |
| 122 ~GaiaCookieManagerService() override; | 165 ~GaiaCookieManagerService() override; |
| 123 | 166 |
| 124 void AddAccountToCookie(const std::string& account_id); | 167 void AddAccountToCookie(const std::string& account_id); |
| 125 | 168 |
| 169 void ListAccounts(const ListAccountsCallback& callback); | |
| 170 | |
| 126 // Add or remove observers of this helper. | 171 // Add or remove observers of this helper. |
| 127 void AddObserver(Observer* observer); | 172 void AddObserver(Observer* observer); |
| 128 void RemoveObserver(Observer* observer); | 173 void RemoveObserver(Observer* observer); |
| 129 | 174 |
| 130 // Cancel all login requests. | 175 // Cancel all login requests. |
| 131 void CancelAll(); | 176 void CancelAll(); |
| 132 | 177 |
| 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. | 178 // Signout all accounts. |
| 141 void LogOutAllAccounts(); | 179 void LogOutAllAccounts(); |
| 142 | 180 |
| 143 // Call observers when merge session completes. This public so that callers | 181 // 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 | 182 // that know that a given account is already in the cookie jar can simply |
| 145 // inform the observers. | 183 // inform the observers. |
| 146 void SignalComplete(const std::string& account_id, | 184 void SignalComplete(const std::string& account_id, |
| 147 const GoogleServiceAuthError& error); | 185 const GoogleServiceAuthError& error); |
| 148 | 186 |
| 149 // Returns true of there are pending log ins or outs. | 187 // Returns true of there are pending log ins or outs. |
| 150 bool is_running() const { return accounts_.size() > 0; } | 188 bool is_running() const { return requests_.size() > 0; } |
| 151 | 189 |
| 152 // Start the process of fetching the external check connection result so that | 190 // Start the process of fetching the external check connection result so that |
| 153 // its ready when we try to perform a merge session. | 191 // its ready when we try to perform a merge session. |
| 154 void StartFetchingExternalCcResult(); | 192 void StartFetchingExternalCcResult(); |
| 155 | 193 |
| 156 private: | 194 private: |
| 157 net::URLRequestContextGetter* request_context() { | 195 net::URLRequestContextGetter* request_context() { |
| 158 return signin_client_->GetURLRequestContext(); | 196 return signin_client_->GetURLRequestContext(); |
| 159 } | 197 } |
| 160 | 198 |
| 161 // Overridden from UbertokenConsumer. | 199 // Overridden from UbertokenConsumer. |
| 162 void OnUbertokenSuccess(const std::string& token) override; | 200 void OnUbertokenSuccess(const std::string& token) override; |
| 163 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; | 201 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; |
| 164 | 202 |
| 165 // Overridden from GaiaAuthConsumer. | 203 // Overridden from GaiaAuthConsumer. |
| 166 void OnMergeSessionSuccess(const std::string& data) override; | 204 void OnMergeSessionSuccess(const std::string& data) override; |
| 167 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; | 205 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; |
| 168 | 206 |
| 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 | 207 // 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. | 208 // for the next account. Virtual so that it can be overriden in tests. |
| 174 virtual void StartFetching(); | 209 virtual void StartFetchingUbertoken(); |
| 175 | 210 |
| 176 // Virtual for testing purpose. | 211 // Virtual for testing purpose. |
| 177 virtual void StartLogOutUrlFetch(); | 212 virtual void StartLogOutUrlFetch(); |
| 178 | 213 |
| 179 // Start the next merge session, if needed. | 214 // Start the next request, if needed. |
| 180 void HandleNextAccount(); | 215 void HandleNextRequest(); |
| 181 | 216 |
| 182 // Overridden from URLFetcherDelgate. | 217 // Overridden from URLFetcherDelgate. |
| 183 void OnURLFetchComplete(const net::URLFetcher* source) override; | 218 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 184 | 219 |
| 185 OAuth2TokenService* token_service_; | 220 OAuth2TokenService* token_service_; |
| 186 SigninClient* signin_client_; | 221 SigninClient* signin_client_; |
| 187 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | 222 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; |
| 188 scoped_ptr<UbertokenFetcher> uber_token_fetcher_; | 223 scoped_ptr<UbertokenFetcher> uber_token_fetcher_; |
| 189 ExternalCcResultFetcher external_cc_result_fetcher_; | 224 ExternalCcResultFetcher external_cc_result_fetcher_; |
| 190 | 225 |
| 191 // A worklist for this class. Accounts names are stored here if | 226 // 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 | 227 // executed right away, since this class only permits one request to be |
| 193 // represent a signout request. | 228 // executed at a time. |
| 194 std::deque<std::string> accounts_; | 229 std::deque<GaiaCookieRequest> requests_; |
| 195 | 230 |
| 196 // List of observers to notify when merge session completes. | 231 // List of observers to notify when merge session completes. |
| 197 // Makes sure list is empty on destruction. | 232 // Makes sure list is empty on destruction. |
| 198 ObserverList<Observer, true> observer_list_; | 233 ObserverList<Observer, true> observer_list_; |
| 199 | 234 |
| 200 // Source to use with GAIA endpoints for accounting. | 235 // Source to use with GAIA endpoints for accounting. |
| 201 std::string source_; | 236 std::string source_; |
| 202 | 237 |
| 203 DISALLOW_COPY_AND_ASSIGN(GaiaCookieManagerService); | 238 DISALLOW_COPY_AND_ASSIGN(GaiaCookieManagerService); |
| 204 }; | 239 }; |
| 205 | 240 |
| 206 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H | 241 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H |
| OLD | NEW |