OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_downloader_delegate.h" | 19 #include "chrome/browser/profiles/profile_downloader_delegate.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 22 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 23 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
21 #include "chrome/browser/signin/signin_manager_factory.h" | 24 #include "chrome/browser/signin/signin_manager_factory.h" |
22 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 25 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 26 #include "components/signin/core/browser/signin_client.h" |
23 #include "components/signin/core/browser/signin_manager.h" | 27 #include "components/signin/core/browser/signin_manager.h" |
24 #include "components/signin/core/common/profile_management_switches.h" | 28 #include "components/signin/core/common/profile_management_switches.h" |
25 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
26 #include "google_apis/gaia/gaia_constants.h" | 30 #include "google_apis/gaia/gaia_constants.h" |
27 #include "google_apis/gaia/gaia_urls.h" | |
28 #include "net/base/load_flags.h" | 31 #include "net/base/load_flags.h" |
29 #include "net/url_request/url_fetcher.h" | 32 #include "net/url_request/url_fetcher.h" |
30 #include "net/url_request/url_request_status.h" | 33 #include "net/url_request/url_request_status.h" |
31 #include "skia/ext/image_operations.h" | 34 #include "skia/ext/image_operations.h" |
32 #include "url/gurl.h" | 35 #include "url/gurl.h" |
33 | 36 |
34 using content::BrowserThread; | 37 using content::BrowserThread; |
35 | 38 |
36 namespace { | 39 namespace { |
37 | 40 |
38 // Template for optional authorization header when using an OAuth access token. | 41 // Template for optional authorization header when using an OAuth access token. |
39 const char kAuthorizationHeader[] = | 42 const char kAuthorizationHeader[] = |
40 "Authorization: Bearer %s"; | 43 "Authorization: Bearer %s"; |
41 | 44 |
42 // Path in JSON dictionary to user's photo thumbnail URL. | |
43 const char kPhotoThumbnailURLPath[] = "picture"; | |
44 | |
45 // Path in JSON dictionary to user's hosted domain. | |
46 const char kHostedDomainPath[] = "hd"; | |
47 | |
48 // From the user info API, this field corresponds to the full name of the user. | |
49 const char kFullNamePath[] = "name"; | |
50 | |
51 const char kGivenNamePath[] = "given_name"; | |
52 | |
53 // Path in JSON dictionary to user's preferred locale. | |
54 const char kLocalePath[] = "locale"; | |
55 | |
56 // Path format for specifying thumbnail's size. | 45 // Path format for specifying thumbnail's size. |
57 const char kThumbnailSizeFormat[] = "s%d-c"; | 46 const char kThumbnailSizeFormat[] = "s%d-c"; |
58 // Default thumbnail size. | 47 // Default thumbnail size. |
59 const int kDefaultThumbnailSize = 64; | 48 const int kDefaultThumbnailSize = 64; |
60 | 49 |
61 // Separator of URL path components. | 50 // Separator of URL path components. |
62 const char kURLPathSeparator = '/'; | 51 const char kURLPathSeparator = '/'; |
63 | 52 |
64 // Photo ID of the Picasa Web Albums profile picture (base64 of 0). | 53 // Photo ID of the Picasa Web Albums profile picture (base64 of 0). |
65 const char kPicasaPhotoId[] = "AAAAAAAAAAA"; | 54 const char kPicasaPhotoId[] = "AAAAAAAAAAA"; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 return new_url->is_valid(); | 108 return new_url->is_valid(); |
120 } | 109 } |
121 | 110 |
122 // We can't set the image size, just use the default size. | 111 // We can't set the image size, just use the default size. |
123 *new_url = old_url; | 112 *new_url = old_url; |
124 return true; | 113 return true; |
125 } | 114 } |
126 | 115 |
127 } // namespace | 116 } // namespace |
128 | 117 |
129 // Parses the entry response and gets the name and profile image URL. | |
130 // |data| should be the JSON formatted data return by the response. | |
131 // Returns false to indicate a parsing error. | |
132 bool ProfileDownloader::ParseProfileJSON(base::DictionaryValue* root_dictionary, | |
133 base::string16* full_name, | |
134 base::string16* given_name, | |
135 std::string* url, | |
136 int image_size, | |
137 std::string* profile_locale, | |
138 base::string16* hosted_domain) { | |
139 DCHECK(full_name); | |
140 DCHECK(given_name); | |
141 DCHECK(url); | |
142 DCHECK(profile_locale); | |
143 DCHECK(hosted_domain); | |
144 | |
145 *full_name = base::string16(); | |
146 *given_name = base::string16(); | |
147 *url = std::string(); | |
148 *profile_locale = std::string(); | |
149 *hosted_domain = base::string16(); | |
150 | |
151 root_dictionary->GetString(kFullNamePath, full_name); | |
152 root_dictionary->GetString(kGivenNamePath, given_name); | |
153 root_dictionary->GetString(kLocalePath, profile_locale); | |
154 root_dictionary->GetString(kHostedDomainPath, hosted_domain); | |
155 | |
156 std::string url_string; | |
157 if (root_dictionary->GetString(kPhotoThumbnailURLPath, &url_string)) { | |
158 GURL new_url; | |
159 if (!GetImageURLWithSize(GURL(url_string), image_size, &new_url)) { | |
160 LOG(ERROR) << "GetImageURLWithSize failed for url: " << url_string; | |
161 return false; | |
162 } | |
163 *url = new_url.spec(); | |
164 } | |
165 | |
166 // The profile data is considered valid as long as it has a name or a picture. | |
167 return !full_name->empty() || !url->empty(); | |
168 } | |
169 | |
170 // static | 118 // static |
171 bool ProfileDownloader::IsDefaultProfileImageURL(const std::string& url) { | 119 bool ProfileDownloader::IsDefaultProfileImageURL(const std::string& url) { |
172 if (url.empty()) | 120 if (url.empty()) |
173 return true; | 121 return true; |
174 | 122 |
175 GURL image_url_object(url); | 123 GURL image_url_object(url); |
176 DCHECK(image_url_object.is_valid()); | 124 DCHECK(image_url_object.is_valid()); |
177 VLOG(1) << "URL to check for default image: " << image_url_object.spec(); | 125 VLOG(1) << "URL to check for default image: " << image_url_object.spec(); |
178 std::vector<std::string> path_components; | 126 std::vector<std::string> path_components; |
179 base::SplitString(image_url_object.path(), | 127 base::SplitString(image_url_object.path(), |
180 kURLPathSeparator, | 128 kURLPathSeparator, |
181 &path_components); | 129 &path_components); |
182 | 130 |
183 if (path_components.size() < kProfileImageURLPathComponentsCount) | 131 if (path_components.size() < kProfileImageURLPathComponentsCount) |
184 return false; | 132 return false; |
185 | 133 |
186 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; | 134 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; |
187 const std::string& photo_version = | 135 const std::string& photo_version = |
188 path_components[kPhotoVersionPathComponentIndex]; | 136 path_components[kPhotoVersionPathComponentIndex]; |
189 | 137 |
190 // Check that the ID and version match the default Picasa profile photo. | 138 // Check that the ID and version match the default Picasa profile photo. |
191 return photo_id == kPicasaPhotoId && | 139 return photo_id == kPicasaPhotoId && |
192 photo_version == kDefaultPicasaPhotoVersion; | 140 photo_version == kDefaultPicasaPhotoVersion; |
193 } | 141 } |
194 | 142 |
195 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) | 143 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) |
196 : OAuth2TokenService::Consumer("profile_downloader"), | 144 : OAuth2TokenService::Consumer("profile_downloader"), |
197 delegate_(delegate), | 145 delegate_(delegate), |
198 picture_status_(PICTURE_FAILED) { | 146 picture_status_(PICTURE_FAILED), |
| 147 account_tracker_service_( |
| 148 AccountTrackerServiceFactory::GetForProfile( |
| 149 delegate_->GetBrowserProfile())), |
| 150 waiting_for_account_info_(false) { |
199 DCHECK(delegate_); | 151 DCHECK(delegate_); |
| 152 account_tracker_service_->AddObserver(this); |
200 } | 153 } |
201 | 154 |
202 void ProfileDownloader::Start() { | 155 void ProfileDownloader::Start() { |
203 StartForAccount(std::string()); | 156 StartForAccount(std::string()); |
204 } | 157 } |
205 | 158 |
206 void ProfileDownloader::StartForAccount(const std::string& account_id) { | 159 void ProfileDownloader::StartForAccount(const std::string& account_id) { |
207 VLOG(1) << "Starting profile downloader..."; | 160 VLOG(1) << "Starting profile downloader..."; |
208 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 161 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
209 | 162 |
210 ProfileOAuth2TokenService* service = | 163 ProfileOAuth2TokenService* service = |
211 ProfileOAuth2TokenServiceFactory::GetForProfile( | 164 ProfileOAuth2TokenServiceFactory::GetForProfile( |
212 delegate_->GetBrowserProfile()); | 165 delegate_->GetBrowserProfile()); |
213 if (!service) { | 166 if (!service) { |
214 // This can happen in some test paths. | 167 // This can happen in some test paths. |
215 LOG(WARNING) << "User has no token service"; | 168 LOG(WARNING) << "User has no token service"; |
216 delegate_->OnProfileDownloadFailure( | 169 delegate_->OnProfileDownloadFailure( |
217 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 170 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
218 return; | 171 return; |
219 } | 172 } |
220 | 173 |
221 SigninManagerBase* signin_manager = | 174 SigninManagerBase* signin_manager = |
222 SigninManagerFactory::GetForProfile(delegate_->GetBrowserProfile()); | 175 SigninManagerFactory::GetForProfile(delegate_->GetBrowserProfile()); |
223 account_id_ = | 176 account_id_ = |
224 account_id.empty() ? | 177 account_id.empty() ? |
225 signin_manager->GetAuthenticatedAccountId() : account_id; | 178 signin_manager->GetAuthenticatedAccountId() : account_id; |
226 if (service->RefreshTokenIsAvailable(account_id_)) { | 179 if (service->RefreshTokenIsAvailable(account_id_)) |
227 StartFetchingOAuth2AccessToken(); | 180 StartFetchingOAuth2AccessToken(); |
228 } else { | 181 else |
229 service->AddObserver(this); | 182 service->AddObserver(this); |
230 } | |
231 } | 183 } |
232 | 184 |
233 base::string16 ProfileDownloader::GetProfileHostedDomain() const { | 185 base::string16 ProfileDownloader::GetProfileHostedDomain() const { |
234 return profile_hosted_domain_; | 186 return base::UTF8ToUTF16(account_info_.hosted_domain); |
235 } | 187 } |
236 | 188 |
237 base::string16 ProfileDownloader::GetProfileFullName() const { | 189 base::string16 ProfileDownloader::GetProfileFullName() const { |
238 return profile_full_name_; | 190 return base::UTF8ToUTF16(account_info_.full_name); |
239 } | 191 } |
240 | 192 |
241 base::string16 ProfileDownloader::GetProfileGivenName() const { | 193 base::string16 ProfileDownloader::GetProfileGivenName() const { |
242 return profile_given_name_; | 194 return base::UTF8ToUTF16(account_info_.given_name); |
243 } | 195 } |
244 | 196 |
245 std::string ProfileDownloader::GetProfileLocale() const { | 197 std::string ProfileDownloader::GetProfileLocale() const { |
246 return profile_locale_; | 198 return account_info_.locale; |
247 } | 199 } |
248 | 200 |
249 SkBitmap ProfileDownloader::GetProfilePicture() const { | 201 SkBitmap ProfileDownloader::GetProfilePicture() const { |
250 return profile_picture_; | 202 return profile_picture_; |
251 } | 203 } |
252 | 204 |
253 ProfileDownloader::PictureStatus ProfileDownloader::GetProfilePictureStatus() | 205 ProfileDownloader::PictureStatus ProfileDownloader::GetProfilePictureStatus() |
254 const { | 206 const { |
255 return picture_status_; | 207 return picture_status_; |
256 } | 208 } |
257 | 209 |
258 std::string ProfileDownloader::GetProfilePictureURL() const { | 210 std::string ProfileDownloader::GetProfilePictureURL() const { |
259 return picture_url_; | 211 GURL url; |
| 212 if (GetImageURLWithSize(GURL(account_info_.picture_url), |
| 213 delegate_->GetDesiredImageSideLength(), |
| 214 &url)) { |
| 215 return url.spec(); |
| 216 } |
| 217 return account_info_.picture_url; |
260 } | 218 } |
261 | 219 |
262 void ProfileDownloader::StartFetchingImage() { | 220 void ProfileDownloader::StartFetchingImage() { |
263 VLOG(1) << "Fetching user entry with token: " << auth_token_; | 221 VLOG(1) << "Fetching user entry with token: " << auth_token_; |
264 gaia_client_.reset(new gaia::GaiaOAuthClient( | 222 account_info_ = account_tracker_service_->GetAccountInfo(account_id_); |
265 delegate_->GetBrowserProfile()->GetRequestContext())); | 223 |
266 gaia_client_->GetUserInfo(auth_token_, 0, this); | 224 if (account_info_.IsValid()) |
| 225 FetchImageData(); |
| 226 else |
| 227 waiting_for_account_info_ = true; |
267 } | 228 } |
268 | 229 |
269 void ProfileDownloader::StartFetchingOAuth2AccessToken() { | 230 void ProfileDownloader::StartFetchingOAuth2AccessToken() { |
270 Profile* profile = delegate_->GetBrowserProfile(); | 231 Profile* profile = delegate_->GetBrowserProfile(); |
271 OAuth2TokenService::ScopeSet scopes; | 232 OAuth2TokenService::ScopeSet scopes; |
272 scopes.insert(GaiaConstants::kGoogleUserInfoProfile); | 233 scopes.insert(GaiaConstants::kGoogleUserInfoProfile); |
273 // Increase scope to get hd attribute to determine if lock should be enabled. | 234 // Increase scope to get hd attribute to determine if lock should be enabled. |
274 if (switches::IsNewProfileManagement()) | 235 if (switches::IsNewProfileManagement()) |
275 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); | 236 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); |
276 ProfileOAuth2TokenService* token_service = | 237 ProfileOAuth2TokenService* token_service = |
277 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 238 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
278 oauth2_access_token_request_ = token_service->StartRequest( | 239 oauth2_access_token_request_ = token_service->StartRequest( |
279 account_id_, scopes, this); | 240 account_id_, scopes, this); |
280 } | 241 } |
281 | 242 |
282 ProfileDownloader::~ProfileDownloader() { | 243 ProfileDownloader::~ProfileDownloader() { |
283 // Ensures PO2TS observation is cleared when ProfileDownloader is destructed | 244 // Ensures PO2TS observation is cleared when ProfileDownloader is destructed |
284 // before refresh token is available. | 245 // before refresh token is available. |
285 ProfileOAuth2TokenService* service = | 246 ProfileOAuth2TokenService* service = |
286 ProfileOAuth2TokenServiceFactory::GetForProfile( | 247 ProfileOAuth2TokenServiceFactory::GetForProfile( |
287 delegate_->GetBrowserProfile()); | 248 delegate_->GetBrowserProfile()); |
288 if (service) | 249 if (service) |
289 service->RemoveObserver(this); | 250 service->RemoveObserver(this); |
| 251 |
| 252 account_tracker_service_->RemoveObserver(this); |
290 } | 253 } |
291 | 254 |
292 void ProfileDownloader::OnGetUserInfoResponse( | 255 void ProfileDownloader::FetchImageData() { |
293 scoped_ptr<base::DictionaryValue> user_info) { | 256 DCHECK(account_info_.IsValid()); |
294 std::string image_url; | 257 std::string image_url_with_size = GetProfilePictureURL(); |
295 if (!ParseProfileJSON(user_info.get(), | 258 |
296 &profile_full_name_, | |
297 &profile_given_name_, | |
298 &image_url, | |
299 delegate_->GetDesiredImageSideLength(), | |
300 &profile_locale_, | |
301 &profile_hosted_domain_)) { | |
302 delegate_->OnProfileDownloadFailure( | |
303 this, ProfileDownloaderDelegate::SERVICE_ERROR); | |
304 return; | |
305 } | |
306 if (!delegate_->NeedsProfilePicture()) { | 259 if (!delegate_->NeedsProfilePicture()) { |
307 VLOG(1) << "Skipping profile picture download"; | 260 VLOG(1) << "Skipping profile picture download"; |
308 delegate_->OnProfileDownloadSuccess(this); | 261 delegate_->OnProfileDownloadSuccess(this); |
309 return; | 262 return; |
310 } | 263 } |
311 if (IsDefaultProfileImageURL(image_url)) { | 264 if (IsDefaultProfileImageURL(image_url_with_size)) { |
312 VLOG(1) << "User has default profile picture"; | 265 VLOG(1) << "User has default profile picture"; |
313 picture_status_ = PICTURE_DEFAULT; | 266 picture_status_ = PICTURE_DEFAULT; |
314 delegate_->OnProfileDownloadSuccess(this); | 267 delegate_->OnProfileDownloadSuccess(this); |
315 return; | 268 return; |
316 } | 269 } |
317 if (!image_url.empty() && image_url == delegate_->GetCachedPictureURL()) { | 270 if (!image_url_with_size.empty() && |
| 271 image_url_with_size == delegate_->GetCachedPictureURL()) { |
318 VLOG(1) << "Picture URL matches cached picture URL"; | 272 VLOG(1) << "Picture URL matches cached picture URL"; |
319 picture_status_ = PICTURE_CACHED; | 273 picture_status_ = PICTURE_CACHED; |
320 delegate_->OnProfileDownloadSuccess(this); | 274 delegate_->OnProfileDownloadSuccess(this); |
321 return; | 275 return; |
322 } | 276 } |
323 VLOG(1) << "Fetching profile image from " << image_url; | 277 |
324 picture_url_ = image_url; | 278 VLOG(1) << "Fetching profile image from " << image_url_with_size; |
325 profile_image_fetcher_ = | 279 profile_image_fetcher_ = net::URLFetcher::Create( |
326 net::URLFetcher::Create(GURL(image_url), net::URLFetcher::GET, this); | 280 GURL(image_url_with_size), net::URLFetcher::GET, this); |
327 profile_image_fetcher_->SetRequestContext( | 281 profile_image_fetcher_->SetRequestContext( |
328 delegate_->GetBrowserProfile()->GetRequestContext()); | 282 delegate_->GetBrowserProfile()->GetRequestContext()); |
329 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 283 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
330 net::LOAD_DO_NOT_SAVE_COOKIES); | 284 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 285 |
331 if (!auth_token_.empty()) { | 286 if (!auth_token_.empty()) { |
332 profile_image_fetcher_->SetExtraRequestHeaders( | 287 profile_image_fetcher_->SetExtraRequestHeaders( |
333 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 288 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
334 } | 289 } |
| 290 |
335 profile_image_fetcher_->Start(); | 291 profile_image_fetcher_->Start(); |
336 } | 292 } |
337 | 293 |
338 void ProfileDownloader::OnOAuthError() { | |
339 LOG(WARNING) << "OnOAuthError: Fetching profile data failed"; | |
340 delegate_->OnProfileDownloadFailure( | |
341 this, ProfileDownloaderDelegate::SERVICE_ERROR); | |
342 } | |
343 | |
344 void ProfileDownloader::OnNetworkError(int response_code) { | |
345 LOG(WARNING) << "OnNetworkError: Fetching profile data failed"; | |
346 DVLOG(1) << " Response code: " << response_code; | |
347 delegate_->OnProfileDownloadFailure( | |
348 this, ProfileDownloaderDelegate::NETWORK_ERROR); | |
349 } | |
350 | |
351 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { | 294 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
352 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 295 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
353 std::string data; | 296 std::string data; |
354 source->GetResponseAsString(&data); | 297 source->GetResponseAsString(&data); |
355 bool network_error = | 298 bool network_error = |
356 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; | 299 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; |
357 if (network_error || source->GetResponseCode() != 200) { | 300 if (network_error || source->GetResponseCode() != 200) { |
358 LOG(WARNING) << "Fetching profile data failed"; | 301 LOG(WARNING) << "Fetching profile data failed"; |
359 DVLOG(1) << " Status: " << source->GetStatus().status(); | 302 DVLOG(1) << " Status: " << source->GetStatus().status(); |
360 DVLOG(1) << " Error: " << source->GetStatus().error(); | 303 DVLOG(1) << " Error: " << source->GetStatus().error(); |
361 DVLOG(1) << " Response code: " << source->GetResponseCode(); | 304 DVLOG(1) << " Response code: " << source->GetResponseCode(); |
362 DVLOG(1) << " Url: " << source->GetURL().spec(); | 305 DVLOG(1) << " Url: " << source->GetURL().spec(); |
| 306 profile_image_fetcher_.reset(); |
363 delegate_->OnProfileDownloadFailure(this, network_error ? | 307 delegate_->OnProfileDownloadFailure(this, network_error ? |
364 ProfileDownloaderDelegate::NETWORK_ERROR : | 308 ProfileDownloaderDelegate::NETWORK_ERROR : |
365 ProfileDownloaderDelegate::SERVICE_ERROR); | 309 ProfileDownloaderDelegate::SERVICE_ERROR); |
366 return; | 310 } else { |
| 311 profile_image_fetcher_.reset(); |
| 312 VLOG(1) << "Decoding the image..."; |
| 313 ImageDecoder::Start(this, data); |
367 } | 314 } |
368 | |
369 VLOG(1) << "Decoding the image..."; | |
370 ImageDecoder::Start(this, data); | |
371 } | 315 } |
372 | 316 |
373 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { | 317 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { |
374 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 318 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
375 int image_size = delegate_->GetDesiredImageSideLength(); | 319 int image_size = delegate_->GetDesiredImageSideLength(); |
376 profile_picture_ = skia::ImageOperations::Resize( | 320 profile_picture_ = skia::ImageOperations::Resize( |
377 decoded_image, | 321 decoded_image, |
378 skia::ImageOperations::RESIZE_BEST, | 322 skia::ImageOperations::RESIZE_BEST, |
379 image_size, | 323 image_size, |
380 image_size); | 324 image_size); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 void ProfileDownloader::OnGetTokenFailure( | 359 void ProfileDownloader::OnGetTokenFailure( |
416 const OAuth2TokenService::Request* request, | 360 const OAuth2TokenService::Request* request, |
417 const GoogleServiceAuthError& error) { | 361 const GoogleServiceAuthError& error) { |
418 DCHECK_EQ(request, oauth2_access_token_request_.get()); | 362 DCHECK_EQ(request, oauth2_access_token_request_.get()); |
419 oauth2_access_token_request_.reset(); | 363 oauth2_access_token_request_.reset(); |
420 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:" | 364 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:" |
421 << error.ToString(); | 365 << error.ToString(); |
422 delegate_->OnProfileDownloadFailure( | 366 delegate_->OnProfileDownloadFailure( |
423 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 367 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
424 } | 368 } |
| 369 |
| 370 void ProfileDownloader::OnAccountUpdated( |
| 371 const AccountTrackerService::AccountInfo& info) { |
| 372 if (info.account_id == account_id_ && info.IsValid()) { |
| 373 account_info_ = info; |
| 374 |
| 375 // If the StartFetchingImage was called before we had valid info, the |
| 376 // downloader has been waiting so we need to fetch the image data now. |
| 377 if (waiting_for_account_info_) { |
| 378 FetchImageData(); |
| 379 waiting_for_account_info_ = false; |
| 380 } |
| 381 } |
| 382 } |
OLD | NEW |