| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/login/image_downloader.h" | 5 #include "chrome/browser/chromeos/login/image_downloader.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
| 15 #include "content/common/net/url_fetcher.h" |
| 15 | 16 |
| 16 namespace chromeos { | 17 namespace chromeos { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Template for optional authorization header. | 21 // Template for optional authorization header. |
| 21 const char kAuthorizationHeader[] = "Authorization: GoogleLogin auth=%s"; | 22 const char kAuthorizationHeader[] = "Authorization: GoogleLogin auth=%s"; |
| 22 | 23 |
| 23 } // namespace | 24 } // namespace |
| 24 | 25 |
| 25 ImageDownloader::ImageDownloader(ImageDecoder::Delegate* delegate, | 26 ImageDownloader::ImageDownloader(ImageDecoder::Delegate* delegate, |
| 26 const GURL& image_url, | 27 const GURL& image_url, |
| 27 const std::string& auth_token) | 28 const std::string& auth_token) |
| 28 : delegate_(delegate) { | 29 : delegate_(delegate) { |
| 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 30 image_fetcher_.reset(new URLFetcher(GURL(image_url), URLFetcher::GET, this)); | 31 image_fetcher_.reset(new URLFetcher(GURL(image_url), URLFetcher::GET, this)); |
| 31 image_fetcher_->set_request_context( | 32 image_fetcher_->set_request_context( |
| 32 ProfileManager::GetDefaultProfile()->GetRequestContext()); | 33 ProfileManager::GetDefaultProfile()->GetRequestContext()); |
| 33 if (!auth_token.empty()) { | 34 if (!auth_token.empty()) { |
| 34 image_fetcher_->set_extra_request_headers( | 35 image_fetcher_->set_extra_request_headers( |
| 35 base::StringPrintf(kAuthorizationHeader, auth_token.c_str())); | 36 base::StringPrintf(kAuthorizationHeader, auth_token.c_str())); |
| 36 } | 37 } |
| 37 image_fetcher_->Start(); | 38 image_fetcher_->Start(); |
| 38 } | 39 } |
| 39 | 40 |
| 40 ImageDownloader::~ImageDownloader() {} | 41 ImageDownloader::~ImageDownloader() {} |
| 41 | 42 |
| 42 void ImageDownloader::OnURLFetchComplete(const URLFetcher* source, | 43 void ImageDownloader::OnURLFetchComplete(const URLFetcher* source) { |
| 43 const GURL& url, | |
| 44 const net::URLRequestStatus& status, | |
| 45 int response_code, | |
| 46 const net::ResponseCookies& cookies, | |
| 47 const std::string& data) { | |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 49 if (response_code != 200) { | 45 std::string data; |
| 50 LOG(ERROR) << "Response code is " << response_code; | 46 source->GetResponseAsString(&data); |
| 51 LOG(ERROR) << "Url is " << url.spec(); | 47 if (source->response_code() != 200) { |
| 48 LOG(ERROR) << "Response code is " << source->response_code(); |
| 49 LOG(ERROR) << "Url is " << source->url().spec(); |
| 52 LOG(ERROR) << "Data is " << data; | 50 LOG(ERROR) << "Data is " << data; |
| 53 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 51 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 54 return; | 52 return; |
| 55 } | 53 } |
| 56 | 54 |
| 57 VLOG(1) << "Decoding the image..."; | 55 VLOG(1) << "Decoding the image..."; |
| 58 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder(delegate_, data); | 56 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder(delegate_, data); |
| 59 image_decoder->Start(); | 57 image_decoder->Start(); |
| 60 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 58 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 61 } | 59 } |
| 62 | 60 |
| 63 } // namespace chromeos | 61 } // namespace chromeos |
| OLD | NEW |