| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 ProfileOAuth2TokenServiceFactory::GetForProfile( | 202 ProfileOAuth2TokenServiceFactory::GetForProfile( |
| 203 delegate_->GetBrowserProfile()); | 203 delegate_->GetBrowserProfile()); |
| 204 if (!service) { | 204 if (!service) { |
| 205 // This can happen in some test paths. | 205 // This can happen in some test paths. |
| 206 LOG(WARNING) << "User has no token service"; | 206 LOG(WARNING) << "User has no token service"; |
| 207 delegate_->OnProfileDownloadFailure( | 207 delegate_->OnProfileDownloadFailure( |
| 208 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 208 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
| 209 return; | 209 return; |
| 210 } | 210 } |
| 211 | 211 |
| 212 if (service->RefreshTokenIsAvailable()) { | 212 if (service->RefreshTokenIsAvailable( |
| 213 service->GetPrimaryAccountId())) { |
| 213 StartFetchingOAuth2AccessToken(); | 214 StartFetchingOAuth2AccessToken(); |
| 214 } else { | 215 } else { |
| 215 service->AddObserver(this); | 216 service->AddObserver(this); |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 | 219 |
| 219 string16 ProfileDownloader::GetProfileFullName() const { | 220 string16 ProfileDownloader::GetProfileFullName() const { |
| 220 return profile_full_name_; | 221 return profile_full_name_; |
| 221 } | 222 } |
| 222 | 223 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 245 user_entry_fetcher_->SetExtraRequestHeaders( | 246 user_entry_fetcher_->SetExtraRequestHeaders( |
| 246 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 247 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| 247 } | 248 } |
| 248 user_entry_fetcher_->Start(); | 249 user_entry_fetcher_->Start(); |
| 249 } | 250 } |
| 250 | 251 |
| 251 void ProfileDownloader::StartFetchingOAuth2AccessToken() { | 252 void ProfileDownloader::StartFetchingOAuth2AccessToken() { |
| 252 Profile* profile = delegate_->GetBrowserProfile(); | 253 Profile* profile = delegate_->GetBrowserProfile(); |
| 253 OAuth2TokenService::ScopeSet scopes; | 254 OAuth2TokenService::ScopeSet scopes; |
| 254 scopes.insert(kAPIScope); | 255 scopes.insert(kAPIScope); |
| 255 oauth2_access_token_request_ = | 256 ProfileOAuth2TokenService* token_service = |
| 256 ProfileOAuth2TokenServiceFactory::GetForProfile(profile) | 257 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 257 ->StartRequestWithContext(profile->GetRequestContext(), scopes, this); | 258 oauth2_access_token_request_ = token_service->StartRequest( |
| 259 token_service->GetPrimaryAccountId(), scopes, this); |
| 258 } | 260 } |
| 259 | 261 |
| 260 ProfileDownloader::~ProfileDownloader() {} | 262 ProfileDownloader::~ProfileDownloader() {} |
| 261 | 263 |
| 262 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { | 264 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
| 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 264 std::string data; | 266 std::string data; |
| 265 source->GetResponseAsString(&data); | 267 source->GetResponseAsString(&data); |
| 266 bool network_error = | 268 bool network_error = |
| 267 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; | 269 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 // Callback for OAuth2TokenService::Request on failure. | 369 // Callback for OAuth2TokenService::Request on failure. |
| 368 void ProfileDownloader::OnGetTokenFailure( | 370 void ProfileDownloader::OnGetTokenFailure( |
| 369 const OAuth2TokenService::Request* request, | 371 const OAuth2TokenService::Request* request, |
| 370 const GoogleServiceAuthError& error) { | 372 const GoogleServiceAuthError& error) { |
| 371 DCHECK_EQ(request, oauth2_access_token_request_.get()); | 373 DCHECK_EQ(request, oauth2_access_token_request_.get()); |
| 372 oauth2_access_token_request_.reset(); | 374 oauth2_access_token_request_.reset(); |
| 373 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; | 375 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; |
| 374 delegate_->OnProfileDownloadFailure( | 376 delegate_->OnProfileDownloadFailure( |
| 375 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 377 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
| 376 } | 378 } |
| OLD | NEW |