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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 picture_status_(PICTURE_FAILED) { | 198 picture_status_(PICTURE_FAILED) { |
199 DCHECK(delegate_); | 199 DCHECK(delegate_); |
200 } | 200 } |
201 | 201 |
202 void ProfileDownloader::Start() { | 202 void ProfileDownloader::Start() { |
203 StartForAccount(std::string()); | 203 StartForAccount(std::string()); |
204 } | 204 } |
205 | 205 |
206 void ProfileDownloader::StartForAccount(const std::string& account_id) { | 206 void ProfileDownloader::StartForAccount(const std::string& account_id) { |
207 VLOG(1) << "Starting profile downloader..."; | 207 VLOG(1) << "Starting profile downloader..."; |
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
209 | 209 |
210 ProfileOAuth2TokenService* service = | 210 ProfileOAuth2TokenService* service = |
211 ProfileOAuth2TokenServiceFactory::GetForProfile( | 211 ProfileOAuth2TokenServiceFactory::GetForProfile( |
212 delegate_->GetBrowserProfile()); | 212 delegate_->GetBrowserProfile()); |
213 if (!service) { | 213 if (!service) { |
214 // This can happen in some test paths. | 214 // This can happen in some test paths. |
215 LOG(WARNING) << "User has no token service"; | 215 LOG(WARNING) << "User has no token service"; |
216 delegate_->OnProfileDownloadFailure( | 216 delegate_->OnProfileDownloadFailure( |
217 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 217 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
218 return; | 218 return; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 } | 342 } |
343 | 343 |
344 void ProfileDownloader::OnNetworkError(int response_code) { | 344 void ProfileDownloader::OnNetworkError(int response_code) { |
345 LOG(WARNING) << "OnNetworkError: Fetching profile data failed"; | 345 LOG(WARNING) << "OnNetworkError: Fetching profile data failed"; |
346 DVLOG(1) << " Response code: " << response_code; | 346 DVLOG(1) << " Response code: " << response_code; |
347 delegate_->OnProfileDownloadFailure( | 347 delegate_->OnProfileDownloadFailure( |
348 this, ProfileDownloaderDelegate::NETWORK_ERROR); | 348 this, ProfileDownloaderDelegate::NETWORK_ERROR); |
349 } | 349 } |
350 | 350 |
351 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { | 351 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 352 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
353 std::string data; | 353 std::string data; |
354 source->GetResponseAsString(&data); | 354 source->GetResponseAsString(&data); |
355 bool network_error = | 355 bool network_error = |
356 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; | 356 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; |
357 if (network_error || source->GetResponseCode() != 200) { | 357 if (network_error || source->GetResponseCode() != 200) { |
358 LOG(WARNING) << "Fetching profile data failed"; | 358 LOG(WARNING) << "Fetching profile data failed"; |
359 DVLOG(1) << " Status: " << source->GetStatus().status(); | 359 DVLOG(1) << " Status: " << source->GetStatus().status(); |
360 DVLOG(1) << " Error: " << source->GetStatus().error(); | 360 DVLOG(1) << " Error: " << source->GetStatus().error(); |
361 DVLOG(1) << " Response code: " << source->GetResponseCode(); | 361 DVLOG(1) << " Response code: " << source->GetResponseCode(); |
362 DVLOG(1) << " Url: " << source->GetURL().spec(); | 362 DVLOG(1) << " Url: " << source->GetURL().spec(); |
363 delegate_->OnProfileDownloadFailure(this, network_error ? | 363 delegate_->OnProfileDownloadFailure(this, network_error ? |
364 ProfileDownloaderDelegate::NETWORK_ERROR : | 364 ProfileDownloaderDelegate::NETWORK_ERROR : |
365 ProfileDownloaderDelegate::SERVICE_ERROR); | 365 ProfileDownloaderDelegate::SERVICE_ERROR); |
366 return; | 366 return; |
367 } | 367 } |
368 | 368 |
369 VLOG(1) << "Decoding the image..."; | 369 VLOG(1) << "Decoding the image..."; |
370 ImageDecoder::Start(this, data); | 370 ImageDecoder::Start(this, data); |
371 } | 371 } |
372 | 372 |
373 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { | 373 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { |
374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 374 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
375 int image_size = delegate_->GetDesiredImageSideLength(); | 375 int image_size = delegate_->GetDesiredImageSideLength(); |
376 profile_picture_ = skia::ImageOperations::Resize( | 376 profile_picture_ = skia::ImageOperations::Resize( |
377 decoded_image, | 377 decoded_image, |
378 skia::ImageOperations::RESIZE_BEST, | 378 skia::ImageOperations::RESIZE_BEST, |
379 image_size, | 379 image_size, |
380 image_size); | 380 image_size); |
381 picture_status_ = PICTURE_SUCCESS; | 381 picture_status_ = PICTURE_SUCCESS; |
382 delegate_->OnProfileDownloadSuccess(this); | 382 delegate_->OnProfileDownloadSuccess(this); |
383 } | 383 } |
384 | 384 |
385 void ProfileDownloader::OnDecodeImageFailed() { | 385 void ProfileDownloader::OnDecodeImageFailed() { |
386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 386 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
387 delegate_->OnProfileDownloadFailure( | 387 delegate_->OnProfileDownloadFailure( |
388 this, ProfileDownloaderDelegate::IMAGE_DECODE_FAILED); | 388 this, ProfileDownloaderDelegate::IMAGE_DECODE_FAILED); |
389 } | 389 } |
390 | 390 |
391 void ProfileDownloader::OnRefreshTokenAvailable(const std::string& account_id) { | 391 void ProfileDownloader::OnRefreshTokenAvailable(const std::string& account_id) { |
392 ProfileOAuth2TokenService* service = | 392 ProfileOAuth2TokenService* service = |
393 ProfileOAuth2TokenServiceFactory::GetForProfile( | 393 ProfileOAuth2TokenServiceFactory::GetForProfile( |
394 delegate_->GetBrowserProfile()); | 394 delegate_->GetBrowserProfile()); |
395 if (account_id != account_id_) | 395 if (account_id != account_id_) |
396 return; | 396 return; |
(...skipping 18 matching lines...) Expand all Loading... |
415 void ProfileDownloader::OnGetTokenFailure( | 415 void ProfileDownloader::OnGetTokenFailure( |
416 const OAuth2TokenService::Request* request, | 416 const OAuth2TokenService::Request* request, |
417 const GoogleServiceAuthError& error) { | 417 const GoogleServiceAuthError& error) { |
418 DCHECK_EQ(request, oauth2_access_token_request_.get()); | 418 DCHECK_EQ(request, oauth2_access_token_request_.get()); |
419 oauth2_access_token_request_.reset(); | 419 oauth2_access_token_request_.reset(); |
420 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:" | 420 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:" |
421 << error.ToString(); | 421 << error.ToString(); |
422 delegate_->OnProfileDownloadFailure( | 422 delegate_->OnProfileDownloadFailure( |
423 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 423 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
424 } | 424 } |
OLD | NEW |