| 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/profile_image_downloader.h" | 5 #include "chrome/browser/chromeos/login/profile_image_downloader.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "chrome/browser/chromeos/login/helper.h" | 14 #include "chrome/browser/chromeos/login/helper.h" |
| 15 #include "chrome/browser/chromeos/login/user_manager.h" | 15 #include "chrome/browser/chromeos/login/user_manager.h" |
| 16 #include "chrome/browser/net/gaia/token_service.h" | 16 #include "chrome/browser/net/gaia/token_service.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/net/gaia/gaia_constants.h" | 19 #include "chrome/common/net/gaia/gaia_constants.h" |
| 20 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
| 21 #include "content/common/net/url_fetcher.h" |
| 21 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| 25 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
| 26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 27 #include "skia/ext/image_operations.h" | 28 #include "skia/ext/image_operations.h" |
| 28 | 29 |
| 29 namespace chromeos { | 30 namespace chromeos { |
| 30 | 31 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 ProfileManager::GetDefaultProfile()->GetRequestContext()); | 147 ProfileManager::GetDefaultProfile()->GetRequestContext()); |
| 147 if (!auth_token_.empty()) { | 148 if (!auth_token_.empty()) { |
| 148 user_entry_fetcher_->set_extra_request_headers( | 149 user_entry_fetcher_->set_extra_request_headers( |
| 149 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 150 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| 150 } | 151 } |
| 151 user_entry_fetcher_->Start(); | 152 user_entry_fetcher_->Start(); |
| 152 } | 153 } |
| 153 | 154 |
| 154 ProfileImageDownloader::~ProfileImageDownloader() {} | 155 ProfileImageDownloader::~ProfileImageDownloader() {} |
| 155 | 156 |
| 156 void ProfileImageDownloader::OnURLFetchComplete( | 157 void ProfileImageDownloader::OnURLFetchComplete(const URLFetcher* source) { |
| 157 const URLFetcher* source, | |
| 158 const GURL& url, | |
| 159 const net::URLRequestStatus& status, | |
| 160 int response_code, | |
| 161 const net::ResponseCookies& cookies, | |
| 162 const std::string& data) { | |
| 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 164 if (response_code != 200) { | 159 std::string data; |
| 165 LOG(ERROR) << "Response code is " << response_code; | 160 source->GetResponseAsString(&data); |
| 166 LOG(ERROR) << "Url is " << url.spec(); | 161 if (source->response_code() != 200) { |
| 162 LOG(ERROR) << "Response code is " << source->response_code(); |
| 163 LOG(ERROR) << "Url is " << source->url().spec(); |
| 167 LOG(ERROR) << "Data is " << data; | 164 LOG(ERROR) << "Data is " << data; |
| 168 if (delegate_) | 165 if (delegate_) |
| 169 delegate_->OnDownloadFailure(); | 166 delegate_->OnDownloadFailure(); |
| 170 return; | 167 return; |
| 171 } | 168 } |
| 172 | 169 |
| 173 if (source == user_entry_fetcher_.get()) { | 170 if (source == user_entry_fetcher_.get()) { |
| 174 std::string image_url = GetProfileImageURL(data); | 171 std::string image_url = GetProfileImageURL(data); |
| 175 if (image_url.empty()) { | 172 if (image_url.empty()) { |
| 176 if (delegate_) | 173 if (delegate_) |
| 177 delegate_->OnDownloadFailure(); | 174 delegate_->OnDownloadFailure(); |
| 178 return; | 175 return; |
| 179 } | 176 } |
| 180 VLOG(1) << "Fetching profile image..."; | 177 VLOG(1) << "Fetching profile image..."; |
| 181 profile_image_fetcher_.reset( | 178 profile_image_fetcher_.reset( |
| 182 new URLFetcher(GURL(image_url), URLFetcher::GET, this)); | 179 new URLFetcher(GURL(image_url), URLFetcher::GET, this)); |
| 183 profile_image_fetcher_->set_request_context( | 180 profile_image_fetcher_->set_request_context( |
| 184 ProfileManager::GetDefaultProfile()->GetRequestContext()); | 181 ProfileManager::GetDefaultProfile()->GetRequestContext()); |
| 185 if (!auth_token_.empty()) { | 182 if (!auth_token_.empty()) { |
| 186 profile_image_fetcher_->set_extra_request_headers( | 183 profile_image_fetcher_->set_extra_request_headers( |
| 187 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 184 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| 188 } | 185 } |
| 189 profile_image_fetcher_->Start(); | 186 profile_image_fetcher_->Start(); |
| 190 } else if (source == profile_image_fetcher_.get()) { | 187 } else if (source == profile_image_fetcher_.get()) { |
| 191 VLOG(1) << "Decoding the image..."; | 188 VLOG(1) << "Decoding the image..."; |
| 192 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder(this, data); | 189 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( |
| 190 this, data); |
| 193 image_decoder->Start(); | 191 image_decoder->Start(); |
| 194 } | 192 } |
| 195 } | 193 } |
| 196 | 194 |
| 197 void ProfileImageDownloader::OnImageDecoded(const ImageDecoder* decoder, | 195 void ProfileImageDownloader::OnImageDecoded(const ImageDecoder* decoder, |
| 198 const SkBitmap& decoded_image) { | 196 const SkBitmap& decoded_image) { |
| 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 200 SkBitmap resized_image = skia::ImageOperations::Resize( | 198 SkBitmap resized_image = skia::ImageOperations::Resize( |
| 201 decoded_image, | 199 decoded_image, |
| 202 skia::ImageOperations::RESIZE_BEST, | 200 skia::ImageOperations::RESIZE_BEST, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 230 } else { | 228 } else { |
| 231 if (token_details->service() == GaiaConstants::kPicasaService) { | 229 if (token_details->service() == GaiaConstants::kPicasaService) { |
| 232 LOG(WARNING) << "ProfileImageDownloader: token request failed"; | 230 LOG(WARNING) << "ProfileImageDownloader: token request failed"; |
| 233 if (delegate_) | 231 if (delegate_) |
| 234 delegate_->OnDownloadFailure(); | 232 delegate_->OnDownloadFailure(); |
| 235 } | 233 } |
| 236 } | 234 } |
| 237 } | 235 } |
| 238 | 236 |
| 239 } // namespace chromeos | 237 } // namespace chromeos |
| OLD | NEW |