| 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 // Updates the user object with |user_image|, and saves the image |
| 246 // when a callback indicates that the image has been saved. | 231 // bytes. Local state will be updated as needed. |
| 247 void SaveImageAndUpdateLocalState(const user_manager::UserImage& user_image); | 232 void UpdateUserAndSaveImage(scoped_ptr<user_manager::UserImage> user_image); |
| 233 |
| 234 // Saves |image_bytes| to disk in JPEG format if |
| 235 // |image_is_safe_format|. Local state will be updated as needed. |
| 236 void SaveImageAndUpdateLocalState( |
| 237 bool image_is_safe_format, |
| 238 scoped_ptr<user_manager::UserImage::Bytes> image_bytes); |
| 248 | 239 |
| 249 // Called back after the user image has been saved to | 240 // Called back after the user image has been saved to |
| 250 // disk. Updates the user image information in local state. The | 241 // disk. Updates the user image information in local state. The |
| 251 // information is only updated if |success| is true (indicating that | 242 // information is only updated if |success| is true (indicating that |
| 252 // the image was saved successfully) or the user image is the | 243 // the image was saved successfully) or the user image is the |
| 253 // profile image (indicating that even if the image could not be | 244 // profile image (indicating that even if the image could not be |
| 254 // saved because it is not available right now, it will be | 245 // saved because it is not available right now, it will be |
| 255 // downloaded eventually). | 246 // downloaded eventually). |
| 256 void OnSaveImageDone(bool success); | 247 void OnSaveImageDone(bool success); |
| 257 | 248 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 DCHECK(!run_); | 285 DCHECK(!run_); |
| 295 run_ = true; | 286 run_ = true; |
| 296 | 287 |
| 297 image_index_ = image_index; | 288 image_index_ = image_index; |
| 298 image_url_ = image_url; | 289 image_url_ = image_url; |
| 299 image_path_ = image_path; | 290 image_path_ = image_path; |
| 300 | 291 |
| 301 if (image_index_ >= 0 && | 292 if (image_index_ >= 0 && |
| 302 image_index_ < default_user_image::kDefaultImagesCount) { | 293 image_index_ < default_user_image::kDefaultImagesCount) { |
| 303 // Load one of the default images. This happens synchronously. | 294 // Load one of the default images. This happens synchronously. |
| 304 const user_manager::UserImage user_image( | 295 scoped_ptr<user_manager::UserImage> user_image(new user_manager::UserImage( |
| 305 default_user_image::GetDefaultImage(image_index_)); | 296 default_user_image::GetDefaultImage(image_index_))); |
| 306 UpdateUser(user_image); | 297 UpdateUser(std::move(user_image)); |
| 307 NotifyJobDone(); | 298 NotifyJobDone(); |
| 308 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL || | 299 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL || |
| 309 image_index_ == user_manager::User::USER_IMAGE_PROFILE) { | 300 image_index_ == user_manager::User::USER_IMAGE_PROFILE) { |
| 310 // Load the user image from a file referenced by |image_path|. This happens | 301 // Load the user image from a file referenced by |image_path|. This happens |
| 311 // asynchronously. ROBUST_JPEG_CODEC can be used here because | 302 // asynchronously. ROBUST_JPEG_CODEC can be used here because |
| 312 // LoadImage() is called only for users whose user image has previously | 303 // 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. | 304 // been set by one of the Set*() methods, which transcode to JPEG format. |
| 314 DCHECK(!image_path_.empty()); | 305 DCHECK(!image_path_.empty()); |
| 315 user_image_loader::StartWithFilePath( | 306 user_image_loader::StartWithFilePath( |
| 316 parent_->background_task_runner_, image_path_, | 307 parent_->background_task_runner_, image_path_, |
| 317 ImageDecoder::ROBUST_JPEG_CODEC, | 308 ImageDecoder::ROBUST_JPEG_CODEC, |
| 318 0, // Do not crop. | 309 0, // Do not crop. |
| 319 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), false)); | 310 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), false)); |
| 320 } else { | 311 } else { |
| 321 NOTREACHED(); | 312 NOTREACHED(); |
| 322 NotifyJobDone(); | 313 NotifyJobDone(); |
| 323 } | 314 } |
| 324 } | 315 } |
| 325 | 316 |
| 326 void UserImageManagerImpl::Job::SetToDefaultImage(int default_image_index) { | 317 void UserImageManagerImpl::Job::SetToDefaultImage(int default_image_index) { |
| 327 DCHECK(!run_); | 318 DCHECK(!run_); |
| 328 run_ = true; | 319 run_ = true; |
| 329 | 320 |
| 330 DCHECK_LE(0, default_image_index); | 321 DCHECK_LE(0, default_image_index); |
| 331 DCHECK_GT(default_user_image::kDefaultImagesCount, default_image_index); | 322 DCHECK_GT(default_user_image::kDefaultImagesCount, default_image_index); |
| 332 | 323 |
| 333 image_index_ = default_image_index; | 324 image_index_ = default_image_index; |
| 334 const user_manager::UserImage user_image( | 325 scoped_ptr<user_manager::UserImage> user_image(new user_manager::UserImage( |
| 335 default_user_image::GetDefaultImage(image_index_)); | 326 default_user_image::GetDefaultImage(image_index_))); |
| 336 | 327 |
| 337 UpdateUser(user_image); | 328 UpdateUser(std::move(user_image)); |
| 338 UpdateLocalState(); | 329 UpdateLocalState(); |
| 339 NotifyJobDone(); | 330 NotifyJobDone(); |
| 340 } | 331 } |
| 341 | 332 |
| 342 void UserImageManagerImpl::Job::SetToImage( | 333 void UserImageManagerImpl::Job::SetToImage( |
| 343 int image_index, | 334 int image_index, |
| 344 const user_manager::UserImage& user_image) { | 335 scoped_ptr<user_manager::UserImage> user_image) { |
| 345 DCHECK(!run_); | 336 DCHECK(!run_); |
| 346 run_ = true; | 337 run_ = true; |
| 347 | 338 |
| 348 DCHECK(image_index == user_manager::User::USER_IMAGE_EXTERNAL || | 339 DCHECK(image_index == user_manager::User::USER_IMAGE_EXTERNAL || |
| 349 image_index == user_manager::User::USER_IMAGE_PROFILE); | 340 image_index == user_manager::User::USER_IMAGE_PROFILE); |
| 350 | 341 |
| 351 image_index_ = image_index; | 342 image_index_ = image_index; |
| 352 | 343 |
| 353 UpdateUser(user_image); | 344 UpdateUserAndSaveImage(std::move(user_image)); |
| 354 SaveImageAndUpdateLocalState(user_image); | |
| 355 } | 345 } |
| 356 | 346 |
| 357 void UserImageManagerImpl::Job::SetToImageData(scoped_ptr<std::string> data) { | 347 void UserImageManagerImpl::Job::SetToImageData(scoped_ptr<std::string> data) { |
| 358 DCHECK(!run_); | 348 DCHECK(!run_); |
| 359 run_ = true; | 349 run_ = true; |
| 360 | 350 |
| 361 image_index_ = user_manager::User::USER_IMAGE_EXTERNAL; | 351 image_index_ = user_manager::User::USER_IMAGE_EXTERNAL; |
| 362 | 352 |
| 363 // This method uses ROBUST_JPEG_CODEC, not DEFAULT_CODEC: | 353 // This method uses ROBUST_JPEG_CODEC, not DEFAULT_CODEC: |
| 364 // * This is necessary because the method is used to update the user image | 354 // * This is necessary because the method is used to update the user image |
| (...skipping 23 matching lines...) Expand all Loading... |
| 388 | 378 |
| 389 DCHECK(!path.empty()); | 379 DCHECK(!path.empty()); |
| 390 user_image_loader::StartWithFilePath( | 380 user_image_loader::StartWithFilePath( |
| 391 parent_->background_task_runner_, path, ImageDecoder::DEFAULT_CODEC, | 381 parent_->background_task_runner_, path, ImageDecoder::DEFAULT_CODEC, |
| 392 resize ? login::kMaxUserImageSize : 0, | 382 resize ? login::kMaxUserImageSize : 0, |
| 393 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), true)); | 383 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), true)); |
| 394 } | 384 } |
| 395 | 385 |
| 396 void UserImageManagerImpl::Job::OnLoadImageDone( | 386 void UserImageManagerImpl::Job::OnLoadImageDone( |
| 397 bool save, | 387 bool save, |
| 398 const user_manager::UserImage& user_image) { | 388 scoped_ptr<user_manager::UserImage> user_image) { |
| 399 UpdateUser(user_image); | 389 if (save) { |
| 400 if (save) | 390 UpdateUserAndSaveImage(std::move(user_image)); |
| 401 SaveImageAndUpdateLocalState(user_image); | 391 } else { |
| 402 else | 392 UpdateUser(std::move(user_image)); |
| 403 NotifyJobDone(); | 393 NotifyJobDone(); |
| 394 } |
| 404 } | 395 } |
| 405 | 396 |
| 406 void UserImageManagerImpl::Job::UpdateUser( | 397 void UserImageManagerImpl::Job::UpdateUser( |
| 407 const user_manager::UserImage& user_image) { | 398 scoped_ptr<user_manager::UserImage> user_image) { |
| 408 user_manager::User* user = parent_->GetUserAndModify(); | 399 user_manager::User* user = parent_->GetUserAndModify(); |
| 409 if (!user) | 400 if (!user) |
| 410 return; | 401 return; |
| 411 | 402 |
| 412 if (!user_image.image().isNull()) { | 403 if (!user_image->image().isNull()) { |
| 413 user->SetImage(user_image, image_index_); | 404 user->SetImage(std::move(user_image), image_index_); |
| 414 } else { | 405 } else { |
| 415 user->SetStubImage( | 406 user->SetStubImage( |
| 416 user_manager::UserImage( | 407 make_scoped_ptr(new user_manager::UserImage( |
| 417 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 408 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 418 IDR_PROFILE_PICTURE_LOADING)), | 409 IDR_PROFILE_PICTURE_LOADING))), |
| 419 image_index_, | 410 image_index_, false); |
| 420 false); | |
| 421 } | 411 } |
| 422 user->SetImageURL(image_url_); | 412 user->SetImageURL(image_url_); |
| 423 | 413 |
| 424 parent_->OnJobChangedUserImage(); | 414 parent_->OnJobChangedUserImage(); |
| 425 } | 415 } |
| 426 | 416 |
| 417 void UserImageManagerImpl::Job::UpdateUserAndSaveImage( |
| 418 scoped_ptr<user_manager::UserImage> user_image) { |
| 419 // TODO(crbug.com/593251): Remove the data copy. |
| 420 // Copy the image bytes, before the user image is passed to |
| 421 // UpdateUser(). This is needed to safely save the data bytes to the disk |
| 422 // in the blocking pool. Copying is not desirable but the user image is |
| 423 // JPEG data of 512x512 pixels (usually <100KB) hence it's not enormous. |
| 424 const bool image_is_safe_format = user_image->is_safe_format(); |
| 425 scoped_ptr<user_manager::UserImage::Bytes> copied_bytes; |
| 426 if (image_is_safe_format) { |
| 427 copied_bytes.reset( |
| 428 new user_manager::UserImage::Bytes(user_image->image_bytes())); |
| 429 } |
| 430 |
| 431 UpdateUser(std::move(user_image)); |
| 432 |
| 433 SaveImageAndUpdateLocalState(image_is_safe_format, std::move(copied_bytes)); |
| 434 } |
| 435 |
| 427 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState( | 436 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState( |
| 428 const user_manager::UserImage& user_image) { | 437 bool image_is_safe_format, |
| 438 scoped_ptr<user_manager::UserImage::Bytes> image_bytes) { |
| 429 base::FilePath user_data_dir; | 439 base::FilePath user_data_dir; |
| 430 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 440 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 431 image_path_ = user_data_dir.Append(user_id() + kSafeImagePathExtension); | 441 image_path_ = user_data_dir.Append(user_id() + kSafeImagePathExtension); |
| 432 | 442 |
| 443 // This should always be true, because of the following reasons: |
| 444 // |
| 445 // 1) Profile image from Google account -> UserImage is created with |
| 446 // CreateAndEncode() that generates safe bytes representation. |
| 447 // 2) Profile image from user-specified image -> The bytes representation |
| 448 // is regenerated after the original image is decoded and cropped. |
| 449 // 3) Profile image from policy (via OnExternalDataFetched()) -> JPEG is |
| 450 // only allowed and ROBUST_JPEG_CODEC is used. |
| 451 // |
| 452 // However, check the value just in case because an unsafe image should |
| 453 // never be saved. |
| 454 if (!image_is_safe_format) { |
| 455 LOG(ERROR) << "User image is not in safe format"; |
| 456 OnSaveImageDone(false); |
| 457 return; |
| 458 } |
| 459 |
| 433 base::PostTaskAndReplyWithResult( | 460 base::PostTaskAndReplyWithResult( |
| 434 parent_->background_task_runner_.get(), FROM_HERE, | 461 parent_->background_task_runner_.get(), FROM_HERE, |
| 435 base::Bind(&SaveImage, user_image, image_path_), | 462 base::Bind(&SaveImage, base::Passed(std::move(image_bytes)), image_path_), |
| 436 base::Bind(&Job::OnSaveImageDone, weak_factory_.GetWeakPtr())); | 463 base::Bind(&Job::OnSaveImageDone, weak_factory_.GetWeakPtr())); |
| 437 } | 464 } |
| 438 | 465 |
| 439 void UserImageManagerImpl::Job::OnSaveImageDone(bool success) { | 466 void UserImageManagerImpl::Job::OnSaveImageDone(bool success) { |
| 440 if (success || image_index_ == user_manager::User::USER_IMAGE_PROFILE) | 467 if (success || image_index_ == user_manager::User::USER_IMAGE_PROFILE) |
| 441 UpdateLocalState(); | 468 UpdateLocalState(); |
| 442 NotifyJobDone(); | 469 NotifyJobDone(); |
| 443 } | 470 } |
| 444 | 471 |
| 445 void UserImageManagerImpl::Job::UpdateLocalState() { | 472 void UserImageManagerImpl::Job::UpdateLocalState() { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 530 |
| 504 if (!image_properties) { | 531 if (!image_properties) { |
| 505 SetInitialUserImage(); | 532 SetInitialUserImage(); |
| 506 return; | 533 return; |
| 507 } | 534 } |
| 508 | 535 |
| 509 int image_index = user_manager::User::USER_IMAGE_INVALID; | 536 int image_index = user_manager::User::USER_IMAGE_INVALID; |
| 510 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 537 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
| 511 if (image_index >= 0 && | 538 if (image_index >= 0 && |
| 512 image_index < default_user_image::kDefaultImagesCount) { | 539 image_index < default_user_image::kDefaultImagesCount) { |
| 513 user->SetImage(user_manager::UserImage( | 540 user->SetImage(make_scoped_ptr(new user_manager::UserImage( |
| 514 default_user_image::GetDefaultImage(image_index)), | 541 default_user_image::GetDefaultImage(image_index))), |
| 515 image_index); | 542 image_index); |
| 516 return; | 543 return; |
| 517 } | 544 } |
| 518 | 545 |
| 519 if (image_index != user_manager::User::USER_IMAGE_EXTERNAL && | 546 if (image_index != user_manager::User::USER_IMAGE_EXTERNAL && |
| 520 image_index != user_manager::User::USER_IMAGE_PROFILE) { | 547 image_index != user_manager::User::USER_IMAGE_PROFILE) { |
| 521 NOTREACHED(); | 548 NOTREACHED(); |
| 522 return; | 549 return; |
| 523 } | 550 } |
| 524 | 551 |
| 525 std::string image_url_string; | 552 std::string image_url_string; |
| 526 image_properties->GetString(kImageURLNodeName, &image_url_string); | 553 image_properties->GetString(kImageURLNodeName, &image_url_string); |
| 527 GURL image_url(image_url_string); | 554 GURL image_url(image_url_string); |
| 528 std::string image_path; | 555 std::string image_path; |
| 529 image_properties->GetString(kImagePathNodeName, &image_path); | 556 image_properties->GetString(kImagePathNodeName, &image_path); |
| 530 | 557 |
| 531 user->SetImageURL(image_url); | 558 user->SetImageURL(image_url); |
| 532 user->SetStubImage(user_manager::UserImage( | 559 user->SetStubImage(make_scoped_ptr(new user_manager::UserImage( |
| 533 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 560 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 534 IDR_PROFILE_PICTURE_LOADING)), | 561 IDR_PROFILE_PICTURE_LOADING))), |
| 535 image_index, | 562 image_index, true); |
| 536 true); | |
| 537 DCHECK(!image_path.empty() || | 563 DCHECK(!image_path.empty() || |
| 538 image_index == user_manager::User::USER_IMAGE_PROFILE); | 564 image_index == user_manager::User::USER_IMAGE_PROFILE); |
| 539 if (image_path.empty()) { | 565 if (image_path.empty()) { |
| 540 // Return if the profile image is to be used but has not been downloaded | 566 // Return if the profile image is to be used but has not been downloaded |
| 541 // yet. The profile image will be downloaded after login. | 567 // yet. The profile image will be downloaded after login. |
| 542 return; | 568 return; |
| 543 } | 569 } |
| 544 | 570 |
| 545 job_.reset(new Job(this)); | 571 job_.reset(new Job(this)); |
| 546 job_->LoadImage(base::FilePath(image_path), image_index, image_url); | 572 job_->LoadImage(base::FilePath(image_path), image_index, image_url); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 } | 621 } |
| 596 | 622 |
| 597 void UserImageManagerImpl::SaveUserDefaultImageIndex(int default_image_index) { | 623 void UserImageManagerImpl::SaveUserDefaultImageIndex(int default_image_index) { |
| 598 if (IsUserImageManaged()) | 624 if (IsUserImageManaged()) |
| 599 return; | 625 return; |
| 600 job_.reset(new Job(this)); | 626 job_.reset(new Job(this)); |
| 601 job_->SetToDefaultImage(default_image_index); | 627 job_->SetToDefaultImage(default_image_index); |
| 602 } | 628 } |
| 603 | 629 |
| 604 void UserImageManagerImpl::SaveUserImage( | 630 void UserImageManagerImpl::SaveUserImage( |
| 605 const user_manager::UserImage& user_image) { | 631 scoped_ptr<user_manager::UserImage> user_image) { |
| 606 if (IsUserImageManaged()) | 632 if (IsUserImageManaged()) |
| 607 return; | 633 return; |
| 608 job_.reset(new Job(this)); | 634 job_.reset(new Job(this)); |
| 609 job_->SetToImage(user_manager::User::USER_IMAGE_EXTERNAL, user_image); | 635 job_->SetToImage(user_manager::User::USER_IMAGE_EXTERNAL, |
| 636 std::move(user_image)); |
| 610 } | 637 } |
| 611 | 638 |
| 612 void UserImageManagerImpl::SaveUserImageFromFile(const base::FilePath& path) { | 639 void UserImageManagerImpl::SaveUserImageFromFile(const base::FilePath& path) { |
| 613 if (IsUserImageManaged()) | 640 if (IsUserImageManaged()) |
| 614 return; | 641 return; |
| 615 job_.reset(new Job(this)); | 642 job_.reset(new Job(this)); |
| 616 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true); | 643 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true); |
| 617 } | 644 } |
| 618 | 645 |
| 619 void UserImageManagerImpl::SaveUserImageFromProfileImage() { | 646 void UserImageManagerImpl::SaveUserImageFromProfileImage() { |
| 620 if (IsUserImageManaged()) | 647 if (IsUserImageManaged()) |
| 621 return; | 648 return; |
| 622 // Use the profile image if it has been downloaded already. Otherwise, use a | 649 // Use the profile image if it has been downloaded already. Otherwise, use a |
| 623 // stub image (gray avatar). | 650 // stub image (gray avatar). |
| 624 job_.reset(new Job(this)); | 651 job_.reset(new Job(this)); |
| 625 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE, | 652 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE, |
| 626 downloaded_profile_image_.isNull() | 653 downloaded_profile_image_.isNull() |
| 627 ? user_manager::UserImage() | 654 ? make_scoped_ptr(new user_manager::UserImage) |
| 628 : user_manager::UserImage::CreateAndEncode( | 655 : user_manager::UserImage::CreateAndEncode( |
| 629 downloaded_profile_image_)); | 656 downloaded_profile_image_)); |
| 630 // If no profile image has been downloaded yet, ensure that a download is | 657 // If no profile image has been downloaded yet, ensure that a download is |
| 631 // started. | 658 // started. |
| 632 if (downloaded_profile_image_.isNull()) | 659 if (downloaded_profile_image_.isNull()) |
| 633 DownloadProfileData(kProfileDownloadReasonProfileImageChosen); | 660 DownloadProfileData(kProfileDownloadReasonProfileImageChosen); |
| 634 } | 661 } |
| 635 | 662 |
| 636 void UserImageManagerImpl::DeleteUserImage() { | 663 void UserImageManagerImpl::DeleteUserImage() { |
| 637 job_.reset(); | 664 job_.reset(); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 } | 957 } |
| 931 | 958 |
| 932 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { | 959 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { |
| 933 const user_manager::User* user = GetUser(); | 960 const user_manager::User* user = GetUser(); |
| 934 if (!user) | 961 if (!user) |
| 935 return false; | 962 return false; |
| 936 return user->is_logged_in() && user->HasGaiaAccount(); | 963 return user->is_logged_in() && user->HasGaiaAccount(); |
| 937 } | 964 } |
| 938 | 965 |
| 939 } // namespace chromeos | 966 } // namespace chromeos |
| OLD | NEW |