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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(const URLFetcher* source) { | 157 void ProfileImageDownloader::OnURLFetchComplete(const URLFetcher* source) { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
158 | 159 std::string data; |
159 const std::string& data = source->GetResponseStringRef(); | 160 source->GetResponseAsString(&data); |
160 | |
161 if (source->response_code() != 200) { | 161 if (source->response_code() != 200) { |
162 LOG(ERROR) << "Response code is " << source->response_code(); | 162 LOG(ERROR) << "Response code is " << source->response_code(); |
163 LOG(ERROR) << "Url is " << source->url().spec(); | 163 LOG(ERROR) << "Url is " << source->url().spec(); |
164 LOG(ERROR) << "Data is " << data; | 164 LOG(ERROR) << "Data is " << data; |
165 if (delegate_) | 165 if (delegate_) |
166 delegate_->OnDownloadFailure(); | 166 delegate_->OnDownloadFailure(); |
167 return; | 167 return; |
168 } | 168 } |
169 | 169 |
170 if (source == user_entry_fetcher_.get()) { | 170 if (source == user_entry_fetcher_.get()) { |
171 std::string image_url = GetProfileImageURL(data); | 171 std::string image_url = GetProfileImageURL(data); |
172 if (image_url.empty()) { | 172 if (image_url.empty()) { |
173 if (delegate_) | 173 if (delegate_) |
174 delegate_->OnDownloadFailure(); | 174 delegate_->OnDownloadFailure(); |
175 return; | 175 return; |
176 } | 176 } |
177 VLOG(1) << "Fetching profile image from " << image_url; | 177 VLOG(1) << "Fetching profile image from " << image_url; |
178 profile_image_fetcher_.reset( | 178 profile_image_fetcher_.reset( |
179 new URLFetcher(GURL(image_url), URLFetcher::GET, this)); | 179 new URLFetcher(GURL(image_url), URLFetcher::GET, this)); |
180 profile_image_fetcher_->set_request_context( | 180 profile_image_fetcher_->set_request_context( |
181 ProfileManager::GetDefaultProfile()->GetRequestContext()); | 181 ProfileManager::GetDefaultProfile()->GetRequestContext()); |
182 if (!auth_token_.empty()) { | 182 if (!auth_token_.empty()) { |
183 profile_image_fetcher_->set_extra_request_headers( | 183 profile_image_fetcher_->set_extra_request_headers( |
184 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 184 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
185 } | 185 } |
186 profile_image_fetcher_->Start(); | 186 profile_image_fetcher_->Start(); |
187 } else if (source == profile_image_fetcher_.get()) { | 187 } else if (source == profile_image_fetcher_.get()) { |
188 VLOG(1) << "Decoding the image..."; | 188 VLOG(1) << "Decoding the image..."; |
189 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder(this, data); | 189 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( |
| 190 this, data); |
190 image_decoder->Start(); | 191 image_decoder->Start(); |
191 } | 192 } |
192 } | 193 } |
193 | 194 |
194 void ProfileImageDownloader::OnImageDecoded(const ImageDecoder* decoder, | 195 void ProfileImageDownloader::OnImageDecoded(const ImageDecoder* decoder, |
195 const SkBitmap& decoded_image) { | 196 const SkBitmap& decoded_image) { |
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
197 SkBitmap resized_image = skia::ImageOperations::Resize( | 198 SkBitmap resized_image = skia::ImageOperations::Resize( |
198 decoded_image, | 199 decoded_image, |
199 skia::ImageOperations::RESIZE_BEST, | 200 skia::ImageOperations::RESIZE_BEST, |
(...skipping 27 matching lines...) Expand all Loading... |
227 } else { | 228 } else { |
228 if (token_details->service() == GaiaConstants::kPicasaService) { | 229 if (token_details->service() == GaiaConstants::kPicasaService) { |
229 LOG(WARNING) << "ProfileImageDownloader: token request failed"; | 230 LOG(WARNING) << "ProfileImageDownloader: token request failed"; |
230 if (delegate_) | 231 if (delegate_) |
231 delegate_->OnDownloadFailure(); | 232 delegate_->OnDownloadFailure(); |
232 } | 233 } |
233 } | 234 } |
234 } | 235 } |
235 | 236 |
236 } // namespace chromeos | 237 } // namespace chromeos |
OLD | NEW |