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 #include "components/signin/core/browser/gaia_cookie_manager_service.h" | 5 #include "components/signin/core/browser/gaia_cookie_manager_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <queue> | 9 #include <queue> |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 1000 * 60 * 60 * 4, // 15 minutes. | 50 1000 * 60 * 60 * 4, // 15 minutes. |
51 | 51 |
52 // Time to keep an entry from being discarded even when it | 52 // Time to keep an entry from being discarded even when it |
53 // has no significant state, -1 to never discard. | 53 // has no significant state, -1 to never discard. |
54 -1, | 54 -1, |
55 | 55 |
56 // Don't use initial delay unless the last request was an error. | 56 // Don't use initial delay unless the last request was an error. |
57 false, | 57 false, |
58 }; | 58 }; |
59 | 59 |
60 // The maximum number of retries for a fetcher used in this class. | |
60 const int kMaxFetcherRetries = 8; | 61 const int kMaxFetcherRetries = 8; |
61 | 62 |
62 // Name of the GAIA cookie that is being observed to detect when available | 63 // Name of the GAIA cookie that is being observed to detect when available |
63 // accounts have changed in the content-area. | 64 // accounts have changed in the content-area. |
64 const char* kGaiaCookieName = "APISID"; | 65 const char* kGaiaCookieName = "APISID"; |
65 | 66 |
66 enum GaiaCookieRequestType { | 67 enum GaiaCookieRequestType { |
67 ADD_ACCOUNT, | 68 ADD_ACCOUNT, |
68 LOG_OUT_ALL_ACCOUNTS, | 69 LOG_OUT_ALL_ACCOUNTS, |
69 LOG_OUT_ONE_ACCOUNT, | 70 LOG_OUT_ONE_ACCOUNT, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 GaiaCookieManagerService::ExternalCcResultFetcher::GetExternalCcResult() { | 124 GaiaCookieManagerService::ExternalCcResultFetcher::GetExternalCcResult() { |
124 std::vector<std::string> results; | 125 std::vector<std::string> results; |
125 for (ResultMap::const_iterator it = results_.begin(); it != results_.end(); | 126 for (ResultMap::const_iterator it = results_.begin(); it != results_.end(); |
126 ++it) { | 127 ++it) { |
127 results.push_back(it->first + ":" + it->second); | 128 results.push_back(it->first + ":" + it->second); |
128 } | 129 } |
129 return base::JoinString(results, ","); | 130 return base::JoinString(results, ","); |
130 } | 131 } |
131 | 132 |
132 void GaiaCookieManagerService::ExternalCcResultFetcher::Start() { | 133 void GaiaCookieManagerService::ExternalCcResultFetcher::Start() { |
134 DCHECK(!helper_->external_cc_result_fetched_); | |
133 m_external_cc_result_start_time_ = base::Time::Now(); | 135 m_external_cc_result_start_time_ = base::Time::Now(); |
134 | 136 |
135 CleanupTransientState(); | 137 CleanupTransientState(); |
136 results_.clear(); | 138 results_.clear(); |
137 helper_->gaia_auth_fetcher_.reset( | 139 helper_->gaia_auth_fetcher_.reset( |
138 helper_->signin_client_->CreateGaiaAuthFetcher( | 140 helper_->signin_client_->CreateGaiaAuthFetcher( |
139 this, helper_->GetDefaultSourceForRequest(), | 141 this, helper_->GetDefaultSourceForRequest(), |
140 helper_->request_context())); | 142 helper_->request_context())); |
141 helper_->gaia_auth_fetcher_->StartGetCheckConnectionInfo(); | 143 helper_->gaia_auth_fetcher_->StartGetCheckConnectionInfo(); |
142 | 144 |
143 // Some fetches may timeout. Start a timer to decide when the result fetcher | 145 // Some fetches may timeout. Start a timer to decide when the result fetcher |
144 // has waited long enough. | 146 // has waited long enough. |
145 // TODO(rogerta): I have no idea how long to wait before timing out. | 147 // TODO(rogerta): I have no idea how long to wait before timing out. |
146 // Gaia folks say this should take no more than 2 second even in mobile. | 148 // Gaia folks say this should take no more than 2 second even in mobile. |
147 // This will need to be tweaked. | 149 // This will need to be tweaked. |
148 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), this, | 150 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), this, |
149 &GaiaCookieManagerService::ExternalCcResultFetcher::Timeout); | 151 &GaiaCookieManagerService::ExternalCcResultFetcher::Timeout); |
150 } | 152 } |
151 | 153 |
152 bool GaiaCookieManagerService::ExternalCcResultFetcher::IsRunning() { | 154 bool GaiaCookieManagerService::ExternalCcResultFetcher::IsRunning() { |
153 return helper_->gaia_auth_fetcher_ || fetchers_.size() > 0u; | 155 return helper_->gaia_auth_fetcher_ || fetchers_.size() > 0u || |
156 timer_.IsRunning(); | |
Roger Tawa OOO till Jul 10th
2017/03/10 16:48:51
Since there are no longer retries, this change is
msarda
2017/03/10 16:53:20
This fetcher is running as long as the timer did n
| |
154 } | 157 } |
155 | 158 |
156 void GaiaCookieManagerService::ExternalCcResultFetcher::TimeoutForTests() { | 159 void GaiaCookieManagerService::ExternalCcResultFetcher::TimeoutForTests() { |
157 Timeout(); | 160 Timeout(); |
158 } | 161 } |
159 | 162 |
160 void GaiaCookieManagerService::ExternalCcResultFetcher:: | 163 void GaiaCookieManagerService::ExternalCcResultFetcher:: |
161 OnGetCheckConnectionInfoSuccess(const std::string& data) { | 164 OnGetCheckConnectionInfoSuccess(const std::string& data) { |
162 helper_->fetcher_backoff_.InformOfRequest(true); | |
163 gaia_auth_fetcher_timer_.Stop(); | |
164 std::unique_ptr<base::Value> value = base::JSONReader::Read(data); | 165 std::unique_ptr<base::Value> value = base::JSONReader::Read(data); |
165 const base::ListValue* list; | 166 const base::ListValue* list; |
166 if (!value || !value->GetAsList(&list)) { | 167 if (!value || !value->GetAsList(&list)) { |
167 CleanupTransientState(); | 168 CleanupTransientState(); |
168 GetCheckConnectionInfoCompleted(false); | 169 GetCheckConnectionInfoCompleted(false); |
169 return; | 170 return; |
170 } | 171 } |
171 | 172 |
172 // If there is nothing to check, terminate immediately. | 173 // If there is nothing to check, terminate immediately. |
173 if (list->GetSize() == 0) { | 174 if (list->GetSize() == 0) { |
(...skipping 14 matching lines...) Expand all Loading... | |
188 net::URLFetcher* fetcher = CreateFetcher(GURL(url)).release(); | 189 net::URLFetcher* fetcher = CreateFetcher(GURL(url)).release(); |
189 fetchers_[fetcher->GetOriginalURL()] = std::make_pair(token, fetcher); | 190 fetchers_[fetcher->GetOriginalURL()] = std::make_pair(token, fetcher); |
190 fetcher->Start(); | 191 fetcher->Start(); |
191 } | 192 } |
192 } | 193 } |
193 } | 194 } |
194 } | 195 } |
195 | 196 |
196 void GaiaCookieManagerService::ExternalCcResultFetcher:: | 197 void GaiaCookieManagerService::ExternalCcResultFetcher:: |
197 OnGetCheckConnectionInfoError(const GoogleServiceAuthError& error) { | 198 OnGetCheckConnectionInfoError(const GoogleServiceAuthError& error) { |
198 if (++helper_->fetcher_retries_ < kMaxFetcherRetries && | 199 VLOG(1) << "GaiaCookieManagerService::ExternalCcResultFetcher::" |
199 error.IsTransientError()) { | 200 << "OnGetCheckConnectionInfoError " << error.ToString(); |
200 helper_->fetcher_backoff_.InformOfRequest(false); | |
201 gaia_auth_fetcher_timer_.Start( | |
202 FROM_HERE, helper_->fetcher_backoff_.GetTimeUntilRelease(), | |
203 this, &GaiaCookieManagerService::ExternalCcResultFetcher::Start); | |
204 return; | |
205 } | |
206 | 201 |
202 // Chrome does not have any retry logic for fetching ExternalCcResult. The | |
203 // ExternalCcResult is only used to inform Gaia that Chrome has already | |
204 // checked the connection to other sites. | |
205 // | |
206 // In case fetching the ExternalCcResult fails: | |
207 // * The result of merging accounts to Gaia cookies will not be affected. | |
208 // * Gaia will need make its own call about whether to check them itself, | |
209 // of make some other assumptions. | |
207 CleanupTransientState(); | 210 CleanupTransientState(); |
208 GetCheckConnectionInfoCompleted(false); | 211 GetCheckConnectionInfoCompleted(false); |
209 } | 212 } |
210 | 213 |
211 std::unique_ptr<net::URLFetcher> | 214 std::unique_ptr<net::URLFetcher> |
212 GaiaCookieManagerService::ExternalCcResultFetcher::CreateFetcher( | 215 GaiaCookieManagerService::ExternalCcResultFetcher::CreateFetcher( |
213 const GURL& url) { | 216 const GURL& url) { |
214 std::unique_ptr<net::URLFetcher> fetcher = | 217 std::unique_ptr<net::URLFetcher> fetcher = |
215 net::URLFetcher::Create(0, url, net::URLFetcher::GET, this); | 218 net::URLFetcher::Create(0, url, net::URLFetcher::GET, this); |
216 fetcher->SetRequestContext(helper_->request_context()); | 219 fetcher->SetRequestContext(helper_->request_context()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 // If all expected responses have been received, cancel the timer and | 252 // If all expected responses have been received, cancel the timer and |
250 // report the result. | 253 // report the result. |
251 if (fetchers_.empty()) { | 254 if (fetchers_.empty()) { |
252 CleanupTransientState(); | 255 CleanupTransientState(); |
253 GetCheckConnectionInfoCompleted(true); | 256 GetCheckConnectionInfoCompleted(true); |
254 } | 257 } |
255 } | 258 } |
256 } | 259 } |
257 | 260 |
258 void GaiaCookieManagerService::ExternalCcResultFetcher::Timeout() { | 261 void GaiaCookieManagerService::ExternalCcResultFetcher::Timeout() { |
262 VLOG(1) << " GaiaCookieManagerService::ExternalCcResultFetcher::Timeout"; | |
259 CleanupTransientState(); | 263 CleanupTransientState(); |
260 GetCheckConnectionInfoCompleted(false); | 264 GetCheckConnectionInfoCompleted(false); |
261 } | 265 } |
262 | 266 |
263 void GaiaCookieManagerService::ExternalCcResultFetcher:: | 267 void GaiaCookieManagerService::ExternalCcResultFetcher:: |
264 CleanupTransientState() { | 268 CleanupTransientState() { |
265 timer_.Stop(); | 269 timer_.Stop(); |
266 helper_->gaia_auth_fetcher_.reset(); | 270 helper_->gaia_auth_fetcher_.reset(); |
267 | 271 |
268 for (URLToTokenAndFetcher::const_iterator it = fetchers_.begin(); | 272 for (URLToTokenAndFetcher::const_iterator it = fetchers_.begin(); |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
794 break; | 798 break; |
795 case GaiaCookieRequestType::LIST_ACCOUNTS: | 799 case GaiaCookieRequestType::LIST_ACCOUNTS: |
796 uber_token_fetcher_.reset(); | 800 uber_token_fetcher_.reset(); |
797 signin_client_->DelayNetworkCall( | 801 signin_client_->DelayNetworkCall( |
798 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, | 802 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, |
799 base::Unretained(this))); | 803 base::Unretained(this))); |
800 break; | 804 break; |
801 } | 805 } |
802 } | 806 } |
803 } | 807 } |
OLD | NEW |