| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 &url)) { | 216 &url)) { |
| 217 return url.spec(); | 217 return url.spec(); |
| 218 } | 218 } |
| 219 return account_info_.picture_url; | 219 return account_info_.picture_url; |
| 220 } | 220 } |
| 221 | 221 |
| 222 void ProfileDownloader::StartFetchingImage() { | 222 void ProfileDownloader::StartFetchingImage() { |
| 223 VLOG(1) << "Fetching user entry with token: " << auth_token_; | 223 VLOG(1) << "Fetching user entry with token: " << auth_token_; |
| 224 account_info_ = account_tracker_service_->GetAccountInfo(account_id_); | 224 account_info_ = account_tracker_service_->GetAccountInfo(account_id_); |
| 225 | 225 |
| 226 if (delegate_->IsPreSignin()) { |
| 227 AccountFetcherServiceFactory::GetForProfile(delegate_->GetBrowserProfile()) |
| 228 ->FetchUserInfoBeforeSignin(account_id_); |
| 229 } |
| 230 |
| 226 if (account_info_.IsValid()) | 231 if (account_info_.IsValid()) |
| 227 FetchImageData(); | 232 FetchImageData(); |
| 228 else | 233 else |
| 229 waiting_for_account_info_ = true; | 234 waiting_for_account_info_ = true; |
| 230 | |
| 231 if (delegate_->IsPreSignin()) { | |
| 232 AccountFetcherServiceFactory::GetForProfile(delegate_->GetBrowserProfile()) | |
| 233 ->FetchUserInfoBeforeSignin(account_id_); | |
| 234 } | |
| 235 } | 235 } |
| 236 | 236 |
| 237 void ProfileDownloader::StartFetchingOAuth2AccessToken() { | 237 void ProfileDownloader::StartFetchingOAuth2AccessToken() { |
| 238 Profile* profile = delegate_->GetBrowserProfile(); | 238 Profile* profile = delegate_->GetBrowserProfile(); |
| 239 OAuth2TokenService::ScopeSet scopes; | 239 OAuth2TokenService::ScopeSet scopes; |
| 240 scopes.insert(GaiaConstants::kGoogleUserInfoProfile); | 240 scopes.insert(GaiaConstants::kGoogleUserInfoProfile); |
| 241 // Increase scope to get hd attribute to determine if lock should be enabled. | 241 // Increase scope to get hd attribute to determine if lock should be enabled. |
| 242 if (switches::IsNewProfileManagement()) | 242 if (switches::IsNewProfileManagement()) |
| 243 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); | 243 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); |
| 244 ProfileOAuth2TokenService* token_service = | 244 ProfileOAuth2TokenService* token_service = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 295 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| 296 } | 296 } |
| 297 | 297 |
| 298 profile_image_fetcher_->Start(); | 298 profile_image_fetcher_->Start(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { | 301 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
| 302 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 302 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 303 std::string data; | 303 std::string data; |
| 304 source->GetResponseAsString(&data); | 304 source->GetResponseAsString(&data); |
| 305 LOG(WARNING) << "Profile image URL fetch for image at " | |
| 306 << source->GetURL().possibly_invalid_spec() | |
| 307 << " completed with status: " | |
| 308 << source->GetStatus().status() | |
| 309 << " and response code: " << source->GetResponseCode() | |
| 310 << " data size: " << data.size(); | |
| 311 bool network_error = | 305 bool network_error = |
| 312 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; | 306 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; |
| 313 if (network_error || source->GetResponseCode() != 200) { | 307 if (network_error || source->GetResponseCode() != 200) { |
| 314 LOG(WARNING) << "Fetching profile data failed"; | 308 LOG(WARNING) << "Fetching profile data failed"; |
| 315 DVLOG(1) << " Status: " << source->GetStatus().status(); | 309 DVLOG(1) << " Status: " << source->GetStatus().status(); |
| 316 DVLOG(1) << " Error: " << source->GetStatus().error(); | 310 DVLOG(1) << " Error: " << source->GetStatus().error(); |
| 317 DVLOG(1) << " Response code: " << source->GetResponseCode(); | 311 DVLOG(1) << " Response code: " << source->GetResponseCode(); |
| 318 DVLOG(1) << " Url: " << source->GetURL().spec(); | 312 DVLOG(1) << " Url: " << source->GetURL().spec(); |
| 319 profile_image_fetcher_.reset(); | 313 profile_image_fetcher_.reset(); |
| 320 delegate_->OnProfileDownloadFailure(this, network_error ? | 314 delegate_->OnProfileDownloadFailure(this, network_error ? |
| 321 ProfileDownloaderDelegate::NETWORK_ERROR : | 315 ProfileDownloaderDelegate::NETWORK_ERROR : |
| 322 ProfileDownloaderDelegate::SERVICE_ERROR); | 316 ProfileDownloaderDelegate::SERVICE_ERROR); |
| 323 } else { | 317 } else { |
| 324 profile_image_fetcher_.reset(); | 318 profile_image_fetcher_.reset(); |
| 319 VLOG(1) << "Decoding the image..."; |
| 325 ImageDecoder::Start(this, data); | 320 ImageDecoder::Start(this, data); |
| 326 } | 321 } |
| 327 } | 322 } |
| 328 | 323 |
| 329 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { | 324 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { |
| 330 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 325 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 331 int image_size = delegate_->GetDesiredImageSideLength(); | 326 int image_size = delegate_->GetDesiredImageSideLength(); |
| 332 profile_picture_ = skia::ImageOperations::Resize( | 327 profile_picture_ = skia::ImageOperations::Resize( |
| 333 decoded_image, | 328 decoded_image, |
| 334 skia::ImageOperations::RESIZE_BEST, | 329 skia::ImageOperations::RESIZE_BEST, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 account_info_ = info; | 379 account_info_ = info; |
| 385 | 380 |
| 386 // If the StartFetchingImage was called before we had valid info, the | 381 // If the StartFetchingImage was called before we had valid info, the |
| 387 // downloader has been waiting so we need to fetch the image data now. | 382 // downloader has been waiting so we need to fetch the image data now. |
| 388 if (waiting_for_account_info_) { | 383 if (waiting_for_account_info_) { |
| 389 FetchImageData(); | 384 FetchImageData(); |
| 390 waiting_for_account_info_ = false; | 385 waiting_for_account_info_ = false; |
| 391 } | 386 } |
| 392 } | 387 } |
| 393 } | 388 } |
| OLD | NEW |