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 "google_apis/gaia/merge_session_helper.h" | 5 #include "google_apis/gaia/merge_session_helper.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 ++it) { | 36 ++it) { |
37 results.push_back(it->first + ":" + it->second); | 37 results.push_back(it->first + ":" + it->second); |
38 } | 38 } |
39 return JoinString(results, ","); | 39 return JoinString(results, ","); |
40 } | 40 } |
41 | 41 |
42 void MergeSessionHelper::ExternalCcResultFetcher::Start() { | 42 void MergeSessionHelper::ExternalCcResultFetcher::Start() { |
43 CleanupTransientState(); | 43 CleanupTransientState(); |
44 results_.clear(); | 44 results_.clear(); |
45 gaia_auth_fetcher_.reset( | 45 gaia_auth_fetcher_.reset( |
46 new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, | 46 new GaiaAuthFetcher(this, helper_->source_, |
47 helper_->request_context())); | 47 helper_->request_context())); |
48 gaia_auth_fetcher_->StartGetCheckConnectionInfo(); | 48 gaia_auth_fetcher_->StartGetCheckConnectionInfo(); |
49 } | 49 } |
50 | 50 |
51 bool MergeSessionHelper::ExternalCcResultFetcher::IsRunning() { | 51 bool MergeSessionHelper::ExternalCcResultFetcher::IsRunning() { |
52 return gaia_auth_fetcher_ || fetchers_.size() > 0u; | 52 return gaia_auth_fetcher_ || fetchers_.size() > 0u; |
53 } | 53 } |
54 | 54 |
55 void MergeSessionHelper::ExternalCcResultFetcher::TimeoutForTests() { | 55 void MergeSessionHelper::ExternalCcResultFetcher::TimeoutForTests() { |
56 Timeout(); | 56 Timeout(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 for (URLToTokenAndFetcher::const_iterator it = fetchers_.begin(); | 146 for (URLToTokenAndFetcher::const_iterator it = fetchers_.begin(); |
147 it != fetchers_.end(); ++it) { | 147 it != fetchers_.end(); ++it) { |
148 delete it->second.second; | 148 delete it->second.second; |
149 } | 149 } |
150 fetchers_.clear(); | 150 fetchers_.clear(); |
151 } | 151 } |
152 | 152 |
153 MergeSessionHelper::MergeSessionHelper( | 153 MergeSessionHelper::MergeSessionHelper( |
154 OAuth2TokenService* token_service, | 154 OAuth2TokenService* token_service, |
| 155 const std::string& source, |
155 net::URLRequestContextGetter* request_context, | 156 net::URLRequestContextGetter* request_context, |
156 Observer* observer) | 157 Observer* observer) |
157 : token_service_(token_service), | 158 : token_service_(token_service), |
158 request_context_(request_context), | 159 request_context_(request_context), |
159 result_fetcher_(this) { | 160 result_fetcher_(this), |
| 161 source_(source) { |
160 if (observer) | 162 if (observer) |
161 AddObserver(observer); | 163 AddObserver(observer); |
162 } | 164 } |
163 | 165 |
164 MergeSessionHelper::~MergeSessionHelper() { | 166 MergeSessionHelper::~MergeSessionHelper() { |
165 DCHECK(accounts_.empty()); | 167 DCHECK(accounts_.empty()); |
166 } | 168 } |
167 | 169 |
168 void MergeSessionHelper::LogIn(const std::string& account_id) { | 170 void MergeSessionHelper::LogIn(const std::string& account_id) { |
169 DCHECK(!account_id.empty()); | 171 DCHECK(!account_id.empty()); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 result_fetcher_.Start(); | 257 result_fetcher_.Start(); |
256 } | 258 } |
257 | 259 |
258 bool MergeSessionHelper::StillFetchingExternalCcResult() { | 260 bool MergeSessionHelper::StillFetchingExternalCcResult() { |
259 return result_fetcher_.IsRunning(); | 261 return result_fetcher_.IsRunning(); |
260 } | 262 } |
261 | 263 |
262 void MergeSessionHelper::StartLogOutUrlFetch() { | 264 void MergeSessionHelper::StartLogOutUrlFetch() { |
263 DCHECK(accounts_.front().empty()); | 265 DCHECK(accounts_.front().empty()); |
264 VLOG(1) << "MergeSessionHelper::StartLogOutUrlFetch"; | 266 VLOG(1) << "MergeSessionHelper::StartLogOutUrlFetch"; |
265 GURL logout_url(GaiaUrls::GetInstance()->service_logout_url()); | 267 GURL logout_url(GaiaUrls::GetInstance()->service_logout_url().Resolve( |
| 268 base::StringPrintf("?source=%s", source_.c_str()))); |
266 net::URLFetcher* fetcher = | 269 net::URLFetcher* fetcher = |
267 net::URLFetcher::Create(logout_url, net::URLFetcher::GET, this); | 270 net::URLFetcher::Create(logout_url, net::URLFetcher::GET, this); |
268 fetcher->SetRequestContext(request_context_); | 271 fetcher->SetRequestContext(request_context_); |
269 fetcher->Start(); | 272 fetcher->Start(); |
270 } | 273 } |
271 | 274 |
272 void MergeSessionHelper::OnUbertokenSuccess(const std::string& uber_token) { | 275 void MergeSessionHelper::OnUbertokenSuccess(const std::string& uber_token) { |
273 VLOG(1) << "MergeSessionHelper::OnUbertokenSuccess" | 276 VLOG(1) << "MergeSessionHelper::OnUbertokenSuccess" |
274 << " account=" << accounts_.front(); | 277 << " account=" << accounts_.front(); |
275 gaia_auth_fetcher_.reset(new GaiaAuthFetcher(this, | 278 gaia_auth_fetcher_.reset(new GaiaAuthFetcher(this, |
276 GaiaConstants::kChromeSource, | 279 source_, |
277 request_context_)); | 280 request_context_)); |
278 | 281 |
279 // It's possible that not all external checks have completed. | 282 // It's possible that not all external checks have completed. |
280 // GetExternalCcResult() returns results for those that have. | 283 // GetExternalCcResult() returns results for those that have. |
281 gaia_auth_fetcher_->StartMergeSession(uber_token, | 284 gaia_auth_fetcher_->StartMergeSession(uber_token, |
282 result_fetcher_.GetExternalCcResult()); | 285 result_fetcher_.GetExternalCcResult()); |
283 } | 286 } |
284 | 287 |
285 void MergeSessionHelper::OnUbertokenFailure( | 288 void MergeSessionHelper::OnUbertokenFailure( |
286 const GoogleServiceAuthError& error) { | 289 const GoogleServiceAuthError& error) { |
(...skipping 20 matching lines...) Expand all Loading... |
307 const std::string account_id = accounts_.front(); | 310 const std::string account_id = accounts_.front(); |
308 HandleNextAccount(); | 311 HandleNextAccount(); |
309 SignalComplete(account_id, error); | 312 SignalComplete(account_id, error); |
310 } | 313 } |
311 | 314 |
312 void MergeSessionHelper::StartFetching() { | 315 void MergeSessionHelper::StartFetching() { |
313 VLOG(1) << "MergeSessionHelper::StartFetching account_id=" | 316 VLOG(1) << "MergeSessionHelper::StartFetching account_id=" |
314 << accounts_.front(); | 317 << accounts_.front(); |
315 uber_token_fetcher_.reset(new UbertokenFetcher(token_service_, | 318 uber_token_fetcher_.reset(new UbertokenFetcher(token_service_, |
316 this, | 319 this, |
| 320 source_, |
317 request_context_)); | 321 request_context_)); |
318 uber_token_fetcher_->StartFetchingToken(accounts_.front()); | 322 uber_token_fetcher_->StartFetchingToken(accounts_.front()); |
319 } | 323 } |
320 | 324 |
321 void MergeSessionHelper::OnURLFetchComplete(const net::URLFetcher* source) { | 325 void MergeSessionHelper::OnURLFetchComplete(const net::URLFetcher* source) { |
322 DCHECK(accounts_.front().empty()); | 326 DCHECK(accounts_.front().empty()); |
323 VLOG(1) << "MergeSessionHelper::OnURLFetchComplete"; | 327 VLOG(1) << "MergeSessionHelper::OnURLFetchComplete"; |
324 HandleNextAccount(); | 328 HandleNextAccount(); |
325 } | 329 } |
326 | 330 |
327 void MergeSessionHelper::HandleNextAccount() { | 331 void MergeSessionHelper::HandleNextAccount() { |
328 VLOG(1) << "MergeSessionHelper::HandleNextAccount"; | 332 VLOG(1) << "MergeSessionHelper::HandleNextAccount"; |
329 accounts_.pop_front(); | 333 accounts_.pop_front(); |
330 gaia_auth_fetcher_.reset(); | 334 gaia_auth_fetcher_.reset(); |
331 if (accounts_.empty()) { | 335 if (accounts_.empty()) { |
332 VLOG(1) << "MergeSessionHelper::HandleNextAccount: no more"; | 336 VLOG(1) << "MergeSessionHelper::HandleNextAccount: no more"; |
333 uber_token_fetcher_.reset(); | 337 uber_token_fetcher_.reset(); |
334 } else { | 338 } else { |
335 if (accounts_.front().empty()) { | 339 if (accounts_.front().empty()) { |
336 StartLogOutUrlFetch(); | 340 StartLogOutUrlFetch(); |
337 } else { | 341 } else { |
338 StartFetching(); | 342 StartFetching(); |
339 } | 343 } |
340 } | 344 } |
341 } | 345 } |
OLD | NEW |