Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/users/avatar/user_image_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 case user_manager::User::USER_IMAGE_EXTERNAL: | 141 case user_manager::User::USER_IMAGE_EXTERNAL: |
| 142 // TODO(ivankr): Distinguish this from selected from file. | 142 // TODO(ivankr): Distinguish this from selected from file. |
| 143 return default_user_image::kHistogramImageFromCamera; | 143 return default_user_image::kHistogramImageFromCamera; |
| 144 case user_manager::User::USER_IMAGE_PROFILE: | 144 case user_manager::User::USER_IMAGE_PROFILE: |
| 145 return default_user_image::kHistogramImageFromProfile; | 145 return default_user_image::kHistogramImageFromProfile; |
| 146 default: | 146 default: |
| 147 return image_index; | 147 return image_index; |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool SaveImage(const user_manager::UserImage& user_image, | 151 bool SaveImage(scoped_ptr<user_manager::UserImage::Bytes> image_bytes, |
| 152 const base::FilePath& image_path) { | 152 const base::FilePath& image_path) { |
| 153 // This should always be true, because of the following reasons: | 153 if (image_bytes->empty() || |
| 154 // | |
| 155 // 1) Profile image from Google account -> UserImage is created with | |
| 156 // CreateAndEncode() that generates safe bytes representation. | |
| 157 // 2) Profile image from user-specified image -> The bytes representation | |
| 158 // is regenerated after the original image is decoded and cropped. | |
| 159 // 3) Profile image from policy (via OnExternalDataFetched()) -> JPEG is | |
| 160 // only allowed and ROBUST_JPEG_CODEC is used. | |
| 161 // | |
| 162 // However, check the value just in case because an unsafe image should | |
| 163 // never be saved. | |
| 164 if (!user_image.is_safe_format()) { | |
| 165 LOG(ERROR) << "User image is not in safe format"; | |
| 166 return false; | |
| 167 } | |
| 168 | |
| 169 const user_manager::UserImage::Bytes& image_bytes = user_image.image_bytes(); | |
| 170 if (image_bytes.empty() || | |
| 171 base::WriteFile(image_path, | 154 base::WriteFile(image_path, |
| 172 reinterpret_cast<const char*>(image_bytes.data()), | 155 reinterpret_cast<const char*>(image_bytes->data()), |
| 173 image_bytes.size()) == -1) { | 156 image_bytes->size()) == -1) { |
| 174 LOG(ERROR) << "Failed to save image to file."; | 157 LOG(ERROR) << "Failed to save image to file."; |
| 175 return false; | 158 return false; |
| 176 } | 159 } |
| 177 | 160 |
| 178 return true; | 161 return true; |
| 179 } | 162 } |
| 180 | 163 |
| 181 } // namespace | 164 } // namespace |
| 182 | 165 |
| 183 const char UserImageManagerImpl::kUserImageProperties[] = "user_image_info"; | 166 const char UserImageManagerImpl::kUserImageProperties[] = "user_image_info"; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 211 const int image_index, | 194 const int image_index, |
| 212 const GURL& image_url); | 195 const GURL& image_url); |
| 213 | 196 |
| 214 // Sets the user image in local state to the default image indicated | 197 // Sets the user image in local state to the default image indicated |
| 215 // by |default_image_index|. Also updates the user object with the | 198 // by |default_image_index|. Also updates the user object with the |
| 216 // new image. | 199 // new image. |
| 217 void SetToDefaultImage(int default_image_index); | 200 void SetToDefaultImage(int default_image_index); |
| 218 | 201 |
| 219 // Saves the |user_image| to disk and sets the user image in local | 202 // Saves the |user_image| to disk and sets the user image in local |
| 220 // state to that image. Also updates the user with the new image. | 203 // state to that image. Also updates the user with the new image. |
| 221 void SetToImage(int image_index, const user_manager::UserImage& user_image); | 204 void SetToImage(int image_index, |
| 205 scoped_ptr<user_manager::UserImage> user_image); | |
| 222 | 206 |
| 223 // Decodes the JPEG image |data|, crops and resizes the image, saves | 207 // Decodes the JPEG image |data|, crops and resizes the image, saves |
| 224 // it to disk and sets the user image in local state to that image. | 208 // it to disk and sets the user image in local state to that image. |
| 225 // Also updates the user object with the new image. | 209 // Also updates the user object with the new image. |
| 226 void SetToImageData(scoped_ptr<std::string> data); | 210 void SetToImageData(scoped_ptr<std::string> data); |
| 227 | 211 |
| 228 // Loads the image at |path|, transcodes it to JPEG format, saves | 212 // Loads the image at |path|, transcodes it to JPEG format, saves |
| 229 // the image to disk and sets the user image in local state to that | 213 // the image to disk and sets the user image in local state to that |
| 230 // image. If |resize| is true, the image is cropped and resized | 214 // image. If |resize| is true, the image is cropped and resized |
| 231 // before transcoding. Also updates the user object with the new | 215 // before transcoding. Also updates the user object with the new |
| 232 // image. | 216 // image. |
| 233 void SetToPath(const base::FilePath& path, | 217 void SetToPath(const base::FilePath& path, |
| 234 int image_index, | 218 int image_index, |
| 235 const GURL& image_url, | 219 const GURL& image_url, |
| 236 bool resize); | 220 bool resize); |
| 237 | 221 |
| 238 private: | 222 private: |
| 239 // Called back after an image has been loaded from disk. | 223 // Called back after an image has been loaded from disk. |
| 240 void OnLoadImageDone(bool save, const user_manager::UserImage& user_image); | 224 void OnLoadImageDone(bool save, |
| 225 scoped_ptr<user_manager::UserImage> user_image); | |
| 241 | 226 |
| 242 // Updates the user object with |user_image|. | 227 // Updates the user object with |user_image|. |
| 243 void UpdateUser(const user_manager::UserImage& user_image); | 228 void UpdateUser(scoped_ptr<user_manager::UserImage> user_image); |
| 244 | 229 |
| 245 // Saves |user_image_| to disk in JPEG format. Local state will be updated | 230 // Saves |image_bytes| to disk in JPEG format if |
| 246 // when a callback indicates that the image has been saved. | 231 // |image_is_safe_format|. Local state will be updated when a callback |
| 247 void SaveImageAndUpdateLocalState(const user_manager::UserImage& user_image); | 232 // indicates that the image has been saved. |
| 233 void SaveImageAndUpdateLocalState( | |
| 234 bool image_is_safe_format, | |
| 235 scoped_ptr<user_manager::UserImage::Bytes> image_bytes); | |
| 248 | 236 |
| 249 // Called back after the user image has been saved to | 237 // Called back after the user image has been saved to |
| 250 // disk. Updates the user image information in local state. The | 238 // disk. Updates the user image information in local state. The |
| 251 // information is only updated if |success| is true (indicating that | 239 // information is only updated if |success| is true (indicating that |
| 252 // the image was saved successfully) or the user image is the | 240 // the image was saved successfully) or the user image is the |
| 253 // profile image (indicating that even if the image could not be | 241 // profile image (indicating that even if the image could not be |
| 254 // saved because it is not available right now, it will be | 242 // saved because it is not available right now, it will be |
| 255 // downloaded eventually). | 243 // downloaded eventually). |
| 256 void OnSaveImageDone(bool success); | 244 void OnSaveImageDone(bool success); |
| 257 | 245 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 DCHECK(!run_); | 282 DCHECK(!run_); |
| 295 run_ = true; | 283 run_ = true; |
| 296 | 284 |
| 297 image_index_ = image_index; | 285 image_index_ = image_index; |
| 298 image_url_ = image_url; | 286 image_url_ = image_url; |
| 299 image_path_ = image_path; | 287 image_path_ = image_path; |
| 300 | 288 |
| 301 if (image_index_ >= 0 && | 289 if (image_index_ >= 0 && |
| 302 image_index_ < default_user_image::kDefaultImagesCount) { | 290 image_index_ < default_user_image::kDefaultImagesCount) { |
| 303 // Load one of the default images. This happens synchronously. | 291 // Load one of the default images. This happens synchronously. |
| 304 const user_manager::UserImage user_image( | 292 scoped_ptr<user_manager::UserImage> user_image(new user_manager::UserImage( |
| 305 default_user_image::GetDefaultImage(image_index_)); | 293 default_user_image::GetDefaultImage(image_index_))); |
| 306 UpdateUser(user_image); | 294 UpdateUser(std::move(user_image)); |
| 307 NotifyJobDone(); | 295 NotifyJobDone(); |
| 308 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL || | 296 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL || |
| 309 image_index_ == user_manager::User::USER_IMAGE_PROFILE) { | 297 image_index_ == user_manager::User::USER_IMAGE_PROFILE) { |
| 310 // Load the user image from a file referenced by |image_path|. This happens | 298 // Load the user image from a file referenced by |image_path|. This happens |
| 311 // asynchronously. ROBUST_JPEG_CODEC can be used here because | 299 // asynchronously. ROBUST_JPEG_CODEC can be used here because |
| 312 // LoadImage() is called only for users whose user image has previously | 300 // LoadImage() is called only for users whose user image has previously |
| 313 // been set by one of the Set*() methods, which transcode to JPEG format. | 301 // been set by one of the Set*() methods, which transcode to JPEG format. |
| 314 DCHECK(!image_path_.empty()); | 302 DCHECK(!image_path_.empty()); |
| 315 user_image_loader::StartWithFilePath( | 303 user_image_loader::StartWithFilePath( |
| 316 parent_->background_task_runner_, image_path_, | 304 parent_->background_task_runner_, image_path_, |
| 317 ImageDecoder::ROBUST_JPEG_CODEC, | 305 ImageDecoder::ROBUST_JPEG_CODEC, |
| 318 0, // Do not crop. | 306 0, // Do not crop. |
| 319 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), false)); | 307 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), false)); |
| 320 } else { | 308 } else { |
| 321 NOTREACHED(); | 309 NOTREACHED(); |
| 322 NotifyJobDone(); | 310 NotifyJobDone(); |
| 323 } | 311 } |
| 324 } | 312 } |
| 325 | 313 |
| 326 void UserImageManagerImpl::Job::SetToDefaultImage(int default_image_index) { | 314 void UserImageManagerImpl::Job::SetToDefaultImage(int default_image_index) { |
| 327 DCHECK(!run_); | 315 DCHECK(!run_); |
| 328 run_ = true; | 316 run_ = true; |
| 329 | 317 |
| 330 DCHECK_LE(0, default_image_index); | 318 DCHECK_LE(0, default_image_index); |
| 331 DCHECK_GT(default_user_image::kDefaultImagesCount, default_image_index); | 319 DCHECK_GT(default_user_image::kDefaultImagesCount, default_image_index); |
| 332 | 320 |
| 333 image_index_ = default_image_index; | 321 image_index_ = default_image_index; |
| 334 const user_manager::UserImage user_image( | 322 scoped_ptr<user_manager::UserImage> user_image(new user_manager::UserImage( |
| 335 default_user_image::GetDefaultImage(image_index_)); | 323 default_user_image::GetDefaultImage(image_index_))); |
| 336 | 324 |
| 337 UpdateUser(user_image); | 325 UpdateUser(std::move(user_image)); |
| 338 UpdateLocalState(); | 326 UpdateLocalState(); |
| 339 NotifyJobDone(); | 327 NotifyJobDone(); |
| 340 } | 328 } |
| 341 | 329 |
| 342 void UserImageManagerImpl::Job::SetToImage( | 330 void UserImageManagerImpl::Job::SetToImage( |
| 343 int image_index, | 331 int image_index, |
| 344 const user_manager::UserImage& user_image) { | 332 scoped_ptr<user_manager::UserImage> user_image) { |
| 345 DCHECK(!run_); | 333 DCHECK(!run_); |
| 346 run_ = true; | 334 run_ = true; |
| 347 | 335 |
| 348 DCHECK(image_index == user_manager::User::USER_IMAGE_EXTERNAL || | 336 DCHECK(image_index == user_manager::User::USER_IMAGE_EXTERNAL || |
| 349 image_index == user_manager::User::USER_IMAGE_PROFILE); | 337 image_index == user_manager::User::USER_IMAGE_PROFILE); |
| 350 | 338 |
| 351 image_index_ = image_index; | 339 image_index_ = image_index; |
| 352 | 340 |
| 353 UpdateUser(user_image); | 341 // Copy the image bytes, before the user image is passed to |
| 354 SaveImageAndUpdateLocalState(user_image); | 342 // UpdateUser(). This is needed to safely save the data bytes to the disk |
| 343 // in the blocking pool. Copying is not desirable but the user image is | |
| 344 // JPEG data of 512x512 pixels (usually <100KB), thus it's OK. | |
|
hashimoto
2016/03/15 08:39:26
I don't want to call it OK to copy 100KB of data o
satorux1
2016/03/16 02:01:30
Good point. Let me revisit this in a separate patc
| |
| 345 const bool image_is_safe_format = user_image->is_safe_format(); | |
| 346 scoped_ptr<user_manager::UserImage::Bytes> copied_bytes; | |
| 347 if (image_is_safe_format) { | |
| 348 copied_bytes.reset( | |
| 349 new user_manager::UserImage::Bytes(user_image->image_bytes())); | |
| 350 } | |
| 351 | |
| 352 UpdateUser(std::move(user_image)); | |
| 353 | |
| 354 SaveImageAndUpdateLocalState(image_is_safe_format, std::move(copied_bytes)); | |
| 355 } | 355 } |
| 356 | 356 |
| 357 void UserImageManagerImpl::Job::SetToImageData(scoped_ptr<std::string> data) { | 357 void UserImageManagerImpl::Job::SetToImageData(scoped_ptr<std::string> data) { |
| 358 DCHECK(!run_); | 358 DCHECK(!run_); |
| 359 run_ = true; | 359 run_ = true; |
| 360 | 360 |
| 361 image_index_ = user_manager::User::USER_IMAGE_EXTERNAL; | 361 image_index_ = user_manager::User::USER_IMAGE_EXTERNAL; |
| 362 | 362 |
| 363 // This method uses ROBUST_JPEG_CODEC, not DEFAULT_CODEC: | 363 // This method uses ROBUST_JPEG_CODEC, not DEFAULT_CODEC: |
| 364 // * This is necessary because the method is used to update the user image | 364 // * This is necessary because the method is used to update the user image |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 388 | 388 |
| 389 DCHECK(!path.empty()); | 389 DCHECK(!path.empty()); |
| 390 user_image_loader::StartWithFilePath( | 390 user_image_loader::StartWithFilePath( |
| 391 parent_->background_task_runner_, path, ImageDecoder::DEFAULT_CODEC, | 391 parent_->background_task_runner_, path, ImageDecoder::DEFAULT_CODEC, |
| 392 resize ? login::kMaxUserImageSize : 0, | 392 resize ? login::kMaxUserImageSize : 0, |
| 393 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), true)); | 393 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), true)); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void UserImageManagerImpl::Job::OnLoadImageDone( | 396 void UserImageManagerImpl::Job::OnLoadImageDone( |
| 397 bool save, | 397 bool save, |
| 398 const user_manager::UserImage& user_image) { | 398 scoped_ptr<user_manager::UserImage> user_image) { |
| 399 UpdateUser(user_image); | 399 if (save) { |
| 400 if (save) | 400 // See the comment in SetToImageData() for why the copy is created. |
|
hashimoto
2016/03/15 08:39:26
This comment is not maintainable, as it's super ea
hashimoto
2016/03/17 06:06:51
ping?
satorux1
2016/03/17 06:56:22
oops. i missed this comment. introduced a function
| |
| 401 SaveImageAndUpdateLocalState(user_image); | 401 const bool image_is_safe_format = user_image->is_safe_format(); |
| 402 else | 402 scoped_ptr<user_manager::UserImage::Bytes> copied_bytes; |
| 403 if (image_is_safe_format) { | |
| 404 copied_bytes.reset( | |
| 405 new user_manager::UserImage::Bytes(user_image->image_bytes())); | |
| 406 } | |
| 407 | |
| 408 UpdateUser(std::move(user_image)); | |
| 409 | |
| 410 SaveImageAndUpdateLocalState(image_is_safe_format, std::move(copied_bytes)); | |
| 411 } else { | |
| 412 UpdateUser(std::move(user_image)); | |
| 403 NotifyJobDone(); | 413 NotifyJobDone(); |
| 414 } | |
| 404 } | 415 } |
| 405 | 416 |
| 406 void UserImageManagerImpl::Job::UpdateUser( | 417 void UserImageManagerImpl::Job::UpdateUser( |
| 407 const user_manager::UserImage& user_image) { | 418 scoped_ptr<user_manager::UserImage> user_image) { |
| 408 user_manager::User* user = parent_->GetUserAndModify(); | 419 user_manager::User* user = parent_->GetUserAndModify(); |
| 409 if (!user) | 420 if (!user) |
| 410 return; | 421 return; |
| 411 | 422 |
| 412 if (!user_image.image().isNull()) { | 423 if (!user_image->image().isNull()) { |
| 413 user->SetImage(user_image, image_index_); | 424 user->SetImage(std::move(user_image), image_index_); |
| 414 } else { | 425 } else { |
| 415 user->SetStubImage( | 426 user->SetStubImage( |
| 416 user_manager::UserImage( | 427 make_scoped_ptr(new user_manager::UserImage( |
| 417 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 428 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 418 IDR_PROFILE_PICTURE_LOADING)), | 429 IDR_PROFILE_PICTURE_LOADING))), |
| 419 image_index_, | 430 image_index_, false); |
| 420 false); | |
| 421 } | 431 } |
| 422 user->SetImageURL(image_url_); | 432 user->SetImageURL(image_url_); |
| 423 | 433 |
| 424 parent_->OnJobChangedUserImage(); | 434 parent_->OnJobChangedUserImage(); |
| 425 } | 435 } |
| 426 | 436 |
| 427 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState( | 437 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState( |
| 428 const user_manager::UserImage& user_image) { | 438 bool image_is_safe_format, |
| 439 scoped_ptr<user_manager::UserImage::Bytes> image_bytes) { | |
| 429 base::FilePath user_data_dir; | 440 base::FilePath user_data_dir; |
| 430 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 441 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 431 image_path_ = user_data_dir.Append(user_id() + kSafeImagePathExtension); | 442 image_path_ = user_data_dir.Append(user_id() + kSafeImagePathExtension); |
| 432 | 443 |
| 444 // This should always be true, because of the following reasons: | |
| 445 // | |
| 446 // 1) Profile image from Google account -> UserImage is created with | |
| 447 // CreateAndEncode() that generates safe bytes representation. | |
| 448 // 2) Profile image from user-specified image -> The bytes representation | |
| 449 // is regenerated after the original image is decoded and cropped. | |
| 450 // 3) Profile image from policy (via OnExternalDataFetched()) -> JPEG is | |
| 451 // only allowed and ROBUST_JPEG_CODEC is used. | |
| 452 // | |
| 453 // However, check the value just in case because an unsafe image should | |
| 454 // never be saved. | |
| 455 if (!image_is_safe_format) { | |
| 456 LOG(ERROR) << "User image is not in safe format"; | |
| 457 OnSaveImageDone(false); | |
| 458 return; | |
| 459 } | |
| 460 | |
| 433 base::PostTaskAndReplyWithResult( | 461 base::PostTaskAndReplyWithResult( |
| 434 parent_->background_task_runner_.get(), FROM_HERE, | 462 parent_->background_task_runner_.get(), FROM_HERE, |
| 435 base::Bind(&SaveImage, user_image, image_path_), | 463 base::Bind(&SaveImage, |
| 464 base::Passed(std::move(image_bytes)), image_path_), | |
| 436 base::Bind(&Job::OnSaveImageDone, weak_factory_.GetWeakPtr())); | 465 base::Bind(&Job::OnSaveImageDone, weak_factory_.GetWeakPtr())); |
| 437 } | 466 } |
| 438 | 467 |
| 439 void UserImageManagerImpl::Job::OnSaveImageDone(bool success) { | 468 void UserImageManagerImpl::Job::OnSaveImageDone(bool success) { |
| 440 if (success || image_index_ == user_manager::User::USER_IMAGE_PROFILE) | 469 if (success || image_index_ == user_manager::User::USER_IMAGE_PROFILE) |
| 441 UpdateLocalState(); | 470 UpdateLocalState(); |
| 442 NotifyJobDone(); | 471 NotifyJobDone(); |
| 443 } | 472 } |
| 444 | 473 |
| 445 void UserImageManagerImpl::Job::UpdateLocalState() { | 474 void UserImageManagerImpl::Job::UpdateLocalState() { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 | 532 |
| 504 if (!image_properties) { | 533 if (!image_properties) { |
| 505 SetInitialUserImage(); | 534 SetInitialUserImage(); |
| 506 return; | 535 return; |
| 507 } | 536 } |
| 508 | 537 |
| 509 int image_index = user_manager::User::USER_IMAGE_INVALID; | 538 int image_index = user_manager::User::USER_IMAGE_INVALID; |
| 510 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 539 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
| 511 if (image_index >= 0 && | 540 if (image_index >= 0 && |
| 512 image_index < default_user_image::kDefaultImagesCount) { | 541 image_index < default_user_image::kDefaultImagesCount) { |
| 513 user->SetImage(user_manager::UserImage( | 542 user->SetImage(make_scoped_ptr(new user_manager::UserImage( |
| 514 default_user_image::GetDefaultImage(image_index)), | 543 default_user_image::GetDefaultImage(image_index))), |
| 515 image_index); | 544 image_index); |
| 516 return; | 545 return; |
| 517 } | 546 } |
| 518 | 547 |
| 519 if (image_index != user_manager::User::USER_IMAGE_EXTERNAL && | 548 if (image_index != user_manager::User::USER_IMAGE_EXTERNAL && |
| 520 image_index != user_manager::User::USER_IMAGE_PROFILE) { | 549 image_index != user_manager::User::USER_IMAGE_PROFILE) { |
| 521 NOTREACHED(); | 550 NOTREACHED(); |
| 522 return; | 551 return; |
| 523 } | 552 } |
| 524 | 553 |
| 525 std::string image_url_string; | 554 std::string image_url_string; |
| 526 image_properties->GetString(kImageURLNodeName, &image_url_string); | 555 image_properties->GetString(kImageURLNodeName, &image_url_string); |
| 527 GURL image_url(image_url_string); | 556 GURL image_url(image_url_string); |
| 528 std::string image_path; | 557 std::string image_path; |
| 529 image_properties->GetString(kImagePathNodeName, &image_path); | 558 image_properties->GetString(kImagePathNodeName, &image_path); |
| 530 | 559 |
| 531 user->SetImageURL(image_url); | 560 user->SetImageURL(image_url); |
| 532 user->SetStubImage(user_manager::UserImage( | 561 user->SetStubImage(make_scoped_ptr(new user_manager::UserImage( |
| 533 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 562 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 534 IDR_PROFILE_PICTURE_LOADING)), | 563 IDR_PROFILE_PICTURE_LOADING))), |
| 535 image_index, | 564 image_index, true); |
| 536 true); | |
| 537 DCHECK(!image_path.empty() || | 565 DCHECK(!image_path.empty() || |
| 538 image_index == user_manager::User::USER_IMAGE_PROFILE); | 566 image_index == user_manager::User::USER_IMAGE_PROFILE); |
| 539 if (image_path.empty()) { | 567 if (image_path.empty()) { |
| 540 // Return if the profile image is to be used but has not been downloaded | 568 // Return if the profile image is to be used but has not been downloaded |
| 541 // yet. The profile image will be downloaded after login. | 569 // yet. The profile image will be downloaded after login. |
| 542 return; | 570 return; |
| 543 } | 571 } |
| 544 | 572 |
| 545 job_.reset(new Job(this)); | 573 job_.reset(new Job(this)); |
| 546 job_->LoadImage(base::FilePath(image_path), image_index, image_url); | 574 job_->LoadImage(base::FilePath(image_path), image_index, image_url); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 } | 623 } |
| 596 | 624 |
| 597 void UserImageManagerImpl::SaveUserDefaultImageIndex(int default_image_index) { | 625 void UserImageManagerImpl::SaveUserDefaultImageIndex(int default_image_index) { |
| 598 if (IsUserImageManaged()) | 626 if (IsUserImageManaged()) |
| 599 return; | 627 return; |
| 600 job_.reset(new Job(this)); | 628 job_.reset(new Job(this)); |
| 601 job_->SetToDefaultImage(default_image_index); | 629 job_->SetToDefaultImage(default_image_index); |
| 602 } | 630 } |
| 603 | 631 |
| 604 void UserImageManagerImpl::SaveUserImage( | 632 void UserImageManagerImpl::SaveUserImage( |
| 605 const user_manager::UserImage& user_image) { | 633 scoped_ptr<user_manager::UserImage> user_image) { |
| 606 if (IsUserImageManaged()) | 634 if (IsUserImageManaged()) |
| 607 return; | 635 return; |
| 608 job_.reset(new Job(this)); | 636 job_.reset(new Job(this)); |
| 609 job_->SetToImage(user_manager::User::USER_IMAGE_EXTERNAL, user_image); | 637 job_->SetToImage(user_manager::User::USER_IMAGE_EXTERNAL, |
| 638 std::move(user_image)); | |
| 610 } | 639 } |
| 611 | 640 |
| 612 void UserImageManagerImpl::SaveUserImageFromFile(const base::FilePath& path) { | 641 void UserImageManagerImpl::SaveUserImageFromFile(const base::FilePath& path) { |
| 613 if (IsUserImageManaged()) | 642 if (IsUserImageManaged()) |
| 614 return; | 643 return; |
| 615 job_.reset(new Job(this)); | 644 job_.reset(new Job(this)); |
| 616 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true); | 645 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true); |
| 617 } | 646 } |
| 618 | 647 |
| 619 void UserImageManagerImpl::SaveUserImageFromProfileImage() { | 648 void UserImageManagerImpl::SaveUserImageFromProfileImage() { |
| 620 if (IsUserImageManaged()) | 649 if (IsUserImageManaged()) |
| 621 return; | 650 return; |
| 622 // Use the profile image if it has been downloaded already. Otherwise, use a | 651 // Use the profile image if it has been downloaded already. Otherwise, use a |
| 623 // stub image (gray avatar). | 652 // stub image (gray avatar). |
| 624 job_.reset(new Job(this)); | 653 job_.reset(new Job(this)); |
| 625 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE, | 654 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE, |
| 626 downloaded_profile_image_.isNull() | 655 downloaded_profile_image_.isNull() |
| 627 ? user_manager::UserImage() | 656 ? make_scoped_ptr(new user_manager::UserImage) |
| 628 : user_manager::UserImage::CreateAndEncode( | 657 : user_manager::UserImage::CreateAndEncode( |
| 629 downloaded_profile_image_)); | 658 downloaded_profile_image_)); |
| 630 // If no profile image has been downloaded yet, ensure that a download is | 659 // If no profile image has been downloaded yet, ensure that a download is |
| 631 // started. | 660 // started. |
| 632 if (downloaded_profile_image_.isNull()) | 661 if (downloaded_profile_image_.isNull()) |
| 633 DownloadProfileData(kProfileDownloadReasonProfileImageChosen); | 662 DownloadProfileData(kProfileDownloadReasonProfileImageChosen); |
| 634 } | 663 } |
| 635 | 664 |
| 636 void UserImageManagerImpl::DeleteUserImage() { | 665 void UserImageManagerImpl::DeleteUserImage() { |
| 637 job_.reset(); | 666 job_.reset(); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 930 } | 959 } |
| 931 | 960 |
| 932 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { | 961 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { |
| 933 const user_manager::User* user = GetUser(); | 962 const user_manager::User* user = GetUser(); |
| 934 if (!user) | 963 if (!user) |
| 935 return false; | 964 return false; |
| 936 return user->is_logged_in() && user->HasGaiaAccount(); | 965 return user->is_logged_in() && user->HasGaiaAccount(); |
| 937 } | 966 } |
| 938 | 967 |
| 939 } // namespace chromeos | 968 } // namespace chromeos |
| OLD | NEW |