| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/profiles/profile_downloader.h" | 5 #include "chrome/browser/profiles/profile_downloader.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 ProfileOAuth2TokenServiceFactory::GetForProfile( | 210 ProfileOAuth2TokenServiceFactory::GetForProfile( |
| 211 delegate_->GetBrowserProfile()); | 211 delegate_->GetBrowserProfile()); |
| 212 if (!service) { | 212 if (!service) { |
| 213 // This can happen in some test paths. | 213 // This can happen in some test paths. |
| 214 LOG(WARNING) << "User has no token service"; | 214 LOG(WARNING) << "User has no token service"; |
| 215 delegate_->OnProfileDownloadFailure( | 215 delegate_->OnProfileDownloadFailure( |
| 216 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 216 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
| 217 return; | 217 return; |
| 218 } | 218 } |
| 219 | 219 |
| 220 if (service->RefreshTokenIsAvailable()) { | 220 if (service->RefreshTokenIsAvailable( |
| 221 service->GetPrimaryAccountId())) { |
| 221 StartFetchingOAuth2AccessToken(); | 222 StartFetchingOAuth2AccessToken(); |
| 222 } else { | 223 } else { |
| 223 service->AddObserver(this); | 224 service->AddObserver(this); |
| 224 } | 225 } |
| 225 } | 226 } |
| 226 | 227 |
| 227 string16 ProfileDownloader::GetProfileFullName() const { | 228 string16 ProfileDownloader::GetProfileFullName() const { |
| 228 return profile_full_name_; | 229 return profile_full_name_; |
| 229 } | 230 } |
| 230 | 231 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 257 user_entry_fetcher_->SetExtraRequestHeaders( | 258 user_entry_fetcher_->SetExtraRequestHeaders( |
| 258 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 259 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| 259 } | 260 } |
| 260 user_entry_fetcher_->Start(); | 261 user_entry_fetcher_->Start(); |
| 261 } | 262 } |
| 262 | 263 |
| 263 void ProfileDownloader::StartFetchingOAuth2AccessToken() { | 264 void ProfileDownloader::StartFetchingOAuth2AccessToken() { |
| 264 Profile* profile = delegate_->GetBrowserProfile(); | 265 Profile* profile = delegate_->GetBrowserProfile(); |
| 265 OAuth2TokenService::ScopeSet scopes; | 266 OAuth2TokenService::ScopeSet scopes; |
| 266 scopes.insert(kAPIScope); | 267 scopes.insert(kAPIScope); |
| 267 oauth2_access_token_request_ = | 268 ProfileOAuth2TokenService* token_service = |
| 268 ProfileOAuth2TokenServiceFactory::GetForProfile(profile) | 269 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 269 ->StartRequestWithContext(profile->GetRequestContext(), scopes, this); | 270 oauth2_access_token_request_ = token_service->StartRequest( |
| 271 token_service->GetPrimaryAccountId(), scopes, this); |
| 270 } | 272 } |
| 271 | 273 |
| 272 ProfileDownloader::~ProfileDownloader() {} | 274 ProfileDownloader::~ProfileDownloader() {} |
| 273 | 275 |
| 274 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { | 276 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
| 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 276 std::string data; | 278 std::string data; |
| 277 source->GetResponseAsString(&data); | 279 source->GetResponseAsString(&data); |
| 278 bool network_error = | 280 bool network_error = |
| 279 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; | 281 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // Callback for OAuth2TokenService::Request on failure. | 384 // Callback for OAuth2TokenService::Request on failure. |
| 383 void ProfileDownloader::OnGetTokenFailure( | 385 void ProfileDownloader::OnGetTokenFailure( |
| 384 const OAuth2TokenService::Request* request, | 386 const OAuth2TokenService::Request* request, |
| 385 const GoogleServiceAuthError& error) { | 387 const GoogleServiceAuthError& error) { |
| 386 DCHECK_EQ(request, oauth2_access_token_request_.get()); | 388 DCHECK_EQ(request, oauth2_access_token_request_.get()); |
| 387 oauth2_access_token_request_.reset(); | 389 oauth2_access_token_request_.reset(); |
| 388 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; | 390 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; |
| 389 delegate_->OnProfileDownloadFailure( | 391 delegate_->OnProfileDownloadFailure( |
| 390 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 392 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
| 391 } | 393 } |
| OLD | NEW |