| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return picture_status_; | 238 return picture_status_; |
| 239 } | 239 } |
| 240 | 240 |
| 241 std::string ProfileDownloader::GetProfilePictureURL() const { | 241 std::string ProfileDownloader::GetProfilePictureURL() const { |
| 242 return picture_url_; | 242 return picture_url_; |
| 243 } | 243 } |
| 244 | 244 |
| 245 void ProfileDownloader::StartFetchingImage() { | 245 void ProfileDownloader::StartFetchingImage() { |
| 246 VLOG(1) << "Fetching user entry with token: " << auth_token_; | 246 VLOG(1) << "Fetching user entry with token: " << auth_token_; |
| 247 user_entry_fetcher_.reset(content::URLFetcher::Create( | 247 user_entry_fetcher_.reset(content::URLFetcher::Create( |
| 248 GURL(kUserEntryURL), content::URLFetcher::GET, this)); | 248 GURL(kUserEntryURL), net::URLFetcher::GET, this)); |
| 249 user_entry_fetcher_->SetRequestContext( | 249 user_entry_fetcher_->SetRequestContext( |
| 250 delegate_->GetBrowserProfile()->GetRequestContext()); | 250 delegate_->GetBrowserProfile()->GetRequestContext()); |
| 251 user_entry_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 251 user_entry_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 252 net::LOAD_DO_NOT_SAVE_COOKIES); | 252 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 253 if (!auth_token_.empty()) { | 253 if (!auth_token_.empty()) { |
| 254 user_entry_fetcher_->SetExtraRequestHeaders( | 254 user_entry_fetcher_->SetExtraRequestHeaders( |
| 255 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 255 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| 256 } | 256 } |
| 257 user_entry_fetcher_->Start(); | 257 user_entry_fetcher_->Start(); |
| 258 } | 258 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 302 } |
| 303 if (!image_url.empty() && image_url == delegate_->GetCachedPictureURL()) { | 303 if (!image_url.empty() && image_url == delegate_->GetCachedPictureURL()) { |
| 304 VLOG(1) << "Picture URL matches cached picture URL"; | 304 VLOG(1) << "Picture URL matches cached picture URL"; |
| 305 picture_status_ = PICTURE_CACHED; | 305 picture_status_ = PICTURE_CACHED; |
| 306 delegate_->OnDownloadComplete(this, true); | 306 delegate_->OnDownloadComplete(this, true); |
| 307 return; | 307 return; |
| 308 } | 308 } |
| 309 VLOG(1) << "Fetching profile image from " << image_url; | 309 VLOG(1) << "Fetching profile image from " << image_url; |
| 310 picture_url_ = image_url; | 310 picture_url_ = image_url; |
| 311 profile_image_fetcher_.reset(content::URLFetcher::Create( | 311 profile_image_fetcher_.reset(content::URLFetcher::Create( |
| 312 GURL(image_url), content::URLFetcher::GET, this)); | 312 GURL(image_url), net::URLFetcher::GET, this)); |
| 313 profile_image_fetcher_->SetRequestContext( | 313 profile_image_fetcher_->SetRequestContext( |
| 314 delegate_->GetBrowserProfile()->GetRequestContext()); | 314 delegate_->GetBrowserProfile()->GetRequestContext()); |
| 315 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 315 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 316 net::LOAD_DO_NOT_SAVE_COOKIES); | 316 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 317 if (!auth_token_.empty()) { | 317 if (!auth_token_.empty()) { |
| 318 profile_image_fetcher_->SetExtraRequestHeaders( | 318 profile_image_fetcher_->SetExtraRequestHeaders( |
| 319 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 319 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| 320 } | 320 } |
| 321 profile_image_fetcher_->Start(); | 321 profile_image_fetcher_->Start(); |
| 322 } else if (source == profile_image_fetcher_.get()) { | 322 } else if (source == profile_image_fetcher_.get()) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) { | 375 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) { |
| 376 auth_token_ = access_token; | 376 auth_token_ = access_token; |
| 377 StartFetchingImage(); | 377 StartFetchingImage(); |
| 378 } | 378 } |
| 379 | 379 |
| 380 // Callback for OAuth2AccessTokenFetcher on failure. | 380 // Callback for OAuth2AccessTokenFetcher on failure. |
| 381 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) { | 381 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) { |
| 382 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; | 382 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; |
| 383 delegate_->OnDownloadComplete(this, false); | 383 delegate_->OnDownloadComplete(this, false); |
| 384 } | 384 } |
| OLD | NEW |