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" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void ProfileImageDownloader::StartFetchingImage() { | 139 void ProfileImageDownloader::StartFetchingImage() { |
140 std::string email = UserManager::Get()->logged_in_user().email(); | 140 std::string email = UserManager::Get()->logged_in_user().email(); |
141 if (email.empty()) | 141 if (email.empty()) |
142 return; | 142 return; |
143 VLOG(1) << "Fetching user entry with token: " << auth_token_; | 143 VLOG(1) << "Fetching user entry with token: " << auth_token_; |
144 user_entry_fetcher_.reset( | 144 user_entry_fetcher_.reset( |
145 new URLFetcher(GURL(kUserEntryURL), URLFetcher::GET, this)); | 145 new URLFetcher(GURL(kUserEntryURL), URLFetcher::GET, this)); |
146 user_entry_fetcher_->set_request_context( | 146 user_entry_fetcher_->SetRequestContext( |
147 ProfileManager::GetDefaultProfile()->GetRequestContext()); | 147 ProfileManager::GetDefaultProfile()->GetRequestContext()); |
148 if (!auth_token_.empty()) { | 148 if (!auth_token_.empty()) { |
149 user_entry_fetcher_->set_extra_request_headers( | 149 user_entry_fetcher_->SetExtraRequestHeaders( |
150 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 150 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
151 } | 151 } |
152 user_entry_fetcher_->Start(); | 152 user_entry_fetcher_->Start(); |
153 } | 153 } |
154 | 154 |
155 ProfileImageDownloader::~ProfileImageDownloader() {} | 155 ProfileImageDownloader::~ProfileImageDownloader() {} |
156 | 156 |
157 void ProfileImageDownloader::OnURLFetchComplete(const URLFetcher* source) { | 157 void ProfileImageDownloader::OnURLFetchComplete( |
| 158 const content::URLFetcher* source) { |
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
159 std::string data; | 160 std::string data; |
160 source->GetResponseAsString(&data); | 161 source->GetResponseAsString(&data); |
161 if (source->response_code() != 200) { | 162 if (source->GetResponseCode() != 200) { |
162 LOG(ERROR) << "Response code is " << source->response_code(); | 163 LOG(ERROR) << "Response code is " << source->GetResponseCode(); |
163 LOG(ERROR) << "Url is " << source->url().spec(); | 164 LOG(ERROR) << "Url is " << source->GetUrl().spec(); |
164 LOG(ERROR) << "Data is " << data; | 165 LOG(ERROR) << "Data is " << data; |
165 if (delegate_) | 166 if (delegate_) |
166 delegate_->OnDownloadFailure(); | 167 delegate_->OnDownloadFailure(); |
167 return; | 168 return; |
168 } | 169 } |
169 | 170 |
170 if (source == user_entry_fetcher_.get()) { | 171 if (source == user_entry_fetcher_.get()) { |
171 std::string image_url = GetProfileImageURL(data); | 172 std::string image_url = GetProfileImageURL(data); |
172 if (image_url.empty()) { | 173 if (image_url.empty()) { |
173 if (delegate_) | 174 if (delegate_) |
174 delegate_->OnDownloadFailure(); | 175 delegate_->OnDownloadFailure(); |
175 return; | 176 return; |
176 } | 177 } |
177 VLOG(1) << "Fetching profile image from " << image_url; | 178 VLOG(1) << "Fetching profile image from " << image_url; |
178 profile_image_fetcher_.reset( | 179 profile_image_fetcher_.reset( |
179 new URLFetcher(GURL(image_url), URLFetcher::GET, this)); | 180 new URLFetcher(GURL(image_url), URLFetcher::GET, this)); |
180 profile_image_fetcher_->set_request_context( | 181 profile_image_fetcher_->SetRequestContext( |
181 ProfileManager::GetDefaultProfile()->GetRequestContext()); | 182 ProfileManager::GetDefaultProfile()->GetRequestContext()); |
182 if (!auth_token_.empty()) { | 183 if (!auth_token_.empty()) { |
183 profile_image_fetcher_->set_extra_request_headers( | 184 profile_image_fetcher_->SetExtraRequestHeaders( |
184 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 185 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
185 } | 186 } |
186 profile_image_fetcher_->Start(); | 187 profile_image_fetcher_->Start(); |
187 } else if (source == profile_image_fetcher_.get()) { | 188 } else if (source == profile_image_fetcher_.get()) { |
188 VLOG(1) << "Decoding the image..."; | 189 VLOG(1) << "Decoding the image..."; |
189 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( | 190 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( |
190 this, data); | 191 this, data); |
191 image_decoder->Start(); | 192 image_decoder->Start(); |
192 } | 193 } |
193 } | 194 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 } else { | 229 } else { |
229 if (token_details->service() == GaiaConstants::kPicasaService) { | 230 if (token_details->service() == GaiaConstants::kPicasaService) { |
230 LOG(WARNING) << "ProfileImageDownloader: token request failed"; | 231 LOG(WARNING) << "ProfileImageDownloader: token request failed"; |
231 if (delegate_) | 232 if (delegate_) |
232 delegate_->OnDownloadFailure(); | 233 delegate_->OnDownloadFailure(); |
233 } | 234 } |
234 } | 235 } |
235 } | 236 } |
236 | 237 |
237 } // namespace chromeos | 238 } // namespace chromeos |
OLD | NEW |