| 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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // changes to the cookie must be serialized. | 29 // changes to the cookie must be serialized. |
| 30 // | 30 // |
| 31 // 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 |
| 32 // 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 |
| 33 // 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. |
| 34 class GaiaCookieManagerService : public KeyedService, | 34 class GaiaCookieManagerService : public KeyedService, |
| 35 public GaiaAuthConsumer, | 35 public GaiaAuthConsumer, |
| 36 public UbertokenConsumer, | 36 public UbertokenConsumer, |
| 37 public net::URLFetcherDelegate { | 37 public net::URLFetcherDelegate { |
| 38 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 CreateAddAccountRequest( |
| 63 const std::string& account_id); |
| 64 static GaiaCookieRequest CreateLogOutRequest(); |
| 65 static GaiaCookieRequest CreateListAccountsRequest( |
| 66 const GaiaCookieManagerService::ListAccountsCallback& |
| 67 list_accounts_callback); |
| 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 |
| 39 class Observer { | 81 class Observer { |
| 40 public: | 82 public: |
| 41 // Called whenever a merge session is completed. The account that was | 83 // Called whenever a merge session is completed. The account that was |
| 42 // merged is given by |account_id|. If |error| is equal to | 84 // merged is given by |account_id|. If |error| is equal to |
| 43 // GoogleServiceAuthError::AuthErrorNone() then the merge succeeeded. | 85 // GoogleServiceAuthError::AuthErrorNone() then the merge succeeeded. |
| 44 virtual void OnAddAccountToCookieCompleted( | 86 virtual void OnAddAccountToCookieCompleted( |
| 45 const std::string& account_id, | 87 const std::string& account_id, |
| 46 const GoogleServiceAuthError& error) = 0; | 88 const GoogleServiceAuthError& error) = 0; |
| 47 | 89 |
| 48 // 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... |
| 117 DISALLOW_COPY_AND_ASSIGN(ExternalCcResultFetcher); | 159 DISALLOW_COPY_AND_ASSIGN(ExternalCcResultFetcher); |
| 118 }; | 160 }; |
| 119 | 161 |
| 120 GaiaCookieManagerService(OAuth2TokenService* token_service, | 162 GaiaCookieManagerService(OAuth2TokenService* token_service, |
| 121 const std::string& source, | 163 const std::string& source, |
| 122 SigninClient* signin_client); | 164 SigninClient* signin_client); |
| 123 ~GaiaCookieManagerService() override; | 165 ~GaiaCookieManagerService() override; |
| 124 | 166 |
| 125 void AddAccountToCookie(const std::string& account_id); | 167 void AddAccountToCookie(const std::string& account_id); |
| 126 | 168 |
| 169 void ListAccounts(const ListAccountsCallback& callback); |
| 170 |
| 127 // Add or remove observers of this helper. | 171 // Add or remove observers of this helper. |
| 128 void AddObserver(Observer* observer); | 172 void AddObserver(Observer* observer); |
| 129 void RemoveObserver(Observer* observer); | 173 void RemoveObserver(Observer* observer); |
| 130 | 174 |
| 131 // Cancel all login requests. | 175 // Cancel all login requests. |
| 132 void CancelAll(); | 176 void CancelAll(); |
| 133 | 177 |
| 134 // Signout of |account_id| given a list of accounts already signed in. | |
| 135 // Since this involves signing out of all accounts and resigning back in, | |
| 136 // the order which |accounts| are given is important as it will dictate | |
| 137 // the sign in order. |account_id| does not have to be in |accounts|. | |
| 138 void LogOut(const std::string& account_id, | |
| 139 const std::vector<std::string>& accounts); | |
| 140 | |
| 141 // Signout all accounts. | 178 // Signout all accounts. |
| 142 void LogOutAllAccounts(); | 179 void LogOutAllAccounts(); |
| 143 | 180 |
| 144 // Call observers when merge session completes. This public so that callers | 181 // Call observers when merge session completes. This public so that callers |
| 145 // 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 |
| 146 // inform the observers. | 183 // inform the observers. |
| 147 void SignalComplete(const std::string& account_id, | 184 void SignalComplete(const std::string& account_id, |
| 148 const GoogleServiceAuthError& error); | 185 const GoogleServiceAuthError& error); |
| 149 | 186 |
| 150 // Returns true of there are pending log ins or outs. | 187 // Returns true of there are pending log ins or outs. |
| 151 bool is_running() const { return accounts_.size() > 0; } | 188 bool is_running() const { return requests_.size() > 0; } |
| 152 | 189 |
| 153 // 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 |
| 154 // its ready when we try to perform a merge session. | 191 // its ready when we try to perform a merge session. |
| 155 void StartFetchingExternalCcResult(); | 192 void StartFetchingExternalCcResult(); |
| 156 | 193 |
| 157 private: | 194 private: |
| 158 net::URLRequestContextGetter* request_context() { | 195 net::URLRequestContextGetter* request_context() { |
| 159 return signin_client_->GetURLRequestContext(); | 196 return signin_client_->GetURLRequestContext(); |
| 160 } | 197 } |
| 161 | 198 |
| 162 // Overridden from UbertokenConsumer. | 199 // Overridden from UbertokenConsumer. |
| 163 void OnUbertokenSuccess(const std::string& token) override; | 200 void OnUbertokenSuccess(const std::string& token) override; |
| 164 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; | 201 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; |
| 165 | 202 |
| 166 // Overridden from GaiaAuthConsumer. | 203 // Overridden from GaiaAuthConsumer. |
| 167 void OnMergeSessionSuccess(const std::string& data) override; | 204 void OnMergeSessionSuccess(const std::string& data) override; |
| 168 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; | 205 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; |
| 169 | 206 |
| 170 void LogOutInternal(const std::string& account_id, | 207 // Starts the proess of fetching the uber token and performing a merge session |
| 171 const std::vector<std::string>& accounts); | 208 // for the next account. Virtual so that it can be overriden in tests. |
| 172 | 209 virtual void StartFetchingUbertoken(); |
| 173 // Starts the process of fetching the uber token and then performing a merge | |
| 174 // session for the next account. Virtual so that it can be overriden in tests. | |
| 175 virtual void StartFetching(); | |
| 176 | 210 |
| 177 // Virtual for testing purposes. | 211 // Virtual for testing purposes. |
| 178 virtual void StartFetchingMergeSession(); | 212 virtual void StartFetchingMergeSession(); |
| 179 | 213 |
| 180 // Virtual for testing purpose. | 214 // Virtual for testing purpose. |
| 181 virtual void StartLogOutUrlFetch(); | 215 virtual void StartLogOutUrlFetch(); |
| 182 | 216 |
| 183 // Start the next merge session, if needed. | 217 // Start the next request, if needed. |
| 184 void HandleNextAccount(); | 218 void HandleNextRequest(); |
| 185 | 219 |
| 186 // Overridden from URLFetcherDelgate. | 220 // Overridden from URLFetcherDelgate. |
| 187 void OnURLFetchComplete(const net::URLFetcher* source) override; | 221 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 188 | 222 |
| 189 OAuth2TokenService* token_service_; | 223 OAuth2TokenService* token_service_; |
| 190 SigninClient* signin_client_; | 224 SigninClient* signin_client_; |
| 191 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | 225 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; |
| 192 scoped_ptr<UbertokenFetcher> uber_token_fetcher_; | 226 scoped_ptr<UbertokenFetcher> uber_token_fetcher_; |
| 193 ExternalCcResultFetcher external_cc_result_fetcher_; | 227 ExternalCcResultFetcher external_cc_result_fetcher_; |
| 194 | 228 |
| 195 // If the GaiaAuthFetcher fails, retry with exponential backoff. | 229 // If the GaiaAuthFetcher fails, retry with exponential backoff. |
| 196 net::BackoffEntry gaia_auth_fetcher_backoff_; | 230 net::BackoffEntry gaia_auth_fetcher_backoff_; |
| 197 base::OneShotTimer<GaiaCookieManagerService> gaia_auth_fetcher_timer_; | 231 base::OneShotTimer<GaiaCookieManagerService> gaia_auth_fetcher_timer_; |
| 198 int gaia_auth_fetcher_retries_; | 232 int gaia_auth_fetcher_retries_; |
| 199 | 233 |
| 200 // The last fetched ubertoken, for use in MergeSession retries. | 234 // The last fetched ubertoken, for use in MergeSession retries. |
| 201 std::string uber_token_; | 235 std::string uber_token_; |
| 202 | 236 |
| 203 // A worklist for this class. Accounts names are stored here if | 237 // A worklist for this class. Stores any pending requests that couldn't be |
| 204 // we are pending a signin action for that account. Empty strings | 238 // executed right away, since this class only permits one request to be |
| 205 // represent a signout request. | 239 // executed at a time. |
| 206 std::deque<std::string> accounts_; | 240 std::deque<GaiaCookieRequest> requests_; |
| 207 | 241 |
| 208 // List of observers to notify when merge session completes. | 242 // List of observers to notify when merge session completes. |
| 209 // Makes sure list is empty on destruction. | 243 // Makes sure list is empty on destruction. |
| 210 ObserverList<Observer, true> observer_list_; | 244 ObserverList<Observer, true> observer_list_; |
| 211 | 245 |
| 212 // Source to use with GAIA endpoints for accounting. | 246 // Source to use with GAIA endpoints for accounting. |
| 213 std::string source_; | 247 std::string source_; |
| 214 | 248 |
| 215 DISALLOW_COPY_AND_ASSIGN(GaiaCookieManagerService); | 249 DISALLOW_COPY_AND_ASSIGN(GaiaCookieManagerService); |
| 216 }; | 250 }; |
| 217 | 251 |
| 218 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H | 252 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H |
| OLD | NEW |