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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "chrome/browser/chromeos/login/users/user_manager.h" | 28 #include "chrome/browser/chromeos/login/users/user_manager.h" |
29 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 29 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
30 #include "chrome/browser/profiles/profile_downloader.h" | 30 #include "chrome/browser/profiles/profile_downloader.h" |
31 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
32 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
33 #include "components/user_manager/user_image/default_user_images.h" | 33 #include "components/user_manager/user_image/default_user_images.h" |
34 #include "components/user_manager/user_image/user_image.h" | 34 #include "components/user_manager/user_image/user_image.h" |
35 #include "components/user_manager/user_type.h" | 35 #include "components/user_manager/user_type.h" |
36 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
37 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 38 #include "grit/theme_resources.h" |
38 #include "policy/policy_constants.h" | 39 #include "policy/policy_constants.h" |
| 40 #include "ui/base/resource/resource_bundle.h" |
39 #include "ui/gfx/image/image_skia.h" | 41 #include "ui/gfx/image/image_skia.h" |
40 | 42 |
41 namespace chromeos { | 43 namespace chromeos { |
42 | 44 |
43 namespace { | 45 namespace { |
44 | 46 |
45 // A dictionary that maps user_ids to old user image data with images stored in | 47 // A dictionary that maps user_ids to old user image data with images stored in |
46 // PNG format. Deprecated. | 48 // PNG format. Deprecated. |
47 // TODO(ivankr): remove this const char after migration is gone. | 49 // TODO(ivankr): remove this const char after migration is gone. |
48 const char kUserImages[] = "UserImages"; | 50 const char kUserImages[] = "UserImages"; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 histogram_name, min_time, max_time, bucket_count, | 140 histogram_name, min_time, max_time, bucket_count, |
139 base::HistogramBase::kUmaTargetedHistogramFlag); | 141 base::HistogramBase::kUmaTargetedHistogramFlag); |
140 counter->AddTime(time_delta); | 142 counter->AddTime(time_delta); |
141 | 143 |
142 DVLOG(1) << "Profile image download time: " << time_delta.InSecondsF(); | 144 DVLOG(1) << "Profile image download time: " << time_delta.InSecondsF(); |
143 } | 145 } |
144 | 146 |
145 // Converts |image_index| to UMA histogram value. | 147 // Converts |image_index| to UMA histogram value. |
146 int ImageIndexToHistogramIndex(int image_index) { | 148 int ImageIndexToHistogramIndex(int image_index) { |
147 switch (image_index) { | 149 switch (image_index) { |
148 case User::kExternalImageIndex: | 150 case user_manager::User::USER_IMAGE_EXTERNAL: |
149 // TODO(ivankr): Distinguish this from selected from file. | 151 // TODO(ivankr): Distinguish this from selected from file. |
150 return user_manager::kHistogramImageFromCamera; | 152 return user_manager::kHistogramImageFromCamera; |
151 case User::kProfileImageIndex: | 153 case user_manager::User::USER_IMAGE_PROFILE: |
152 return user_manager::kHistogramImageFromProfile; | 154 return user_manager::kHistogramImageFromProfile; |
153 default: | 155 default: |
154 return image_index; | 156 return image_index; |
155 } | 157 } |
156 } | 158 } |
157 | 159 |
158 bool SaveImage(const user_manager::UserImage& user_image, | 160 bool SaveImage(const user_manager::UserImage& user_image, |
159 const base::FilePath& image_path) { | 161 const base::FilePath& image_path) { |
160 user_manager::UserImage safe_image; | 162 user_manager::UserImage safe_image; |
161 const user_manager::UserImage::RawImage* encoded_image = NULL; | 163 const user_manager::UserImage::RawImage* encoded_image = NULL; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 image_index_ = image_index; | 300 image_index_ = image_index; |
299 image_url_ = image_url; | 301 image_url_ = image_url; |
300 image_path_ = image_path; | 302 image_path_ = image_path; |
301 | 303 |
302 if (image_index_ >= 0 && image_index_ < user_manager::kDefaultImagesCount) { | 304 if (image_index_ >= 0 && image_index_ < user_manager::kDefaultImagesCount) { |
303 // Load one of the default images. This happens synchronously. | 305 // Load one of the default images. This happens synchronously. |
304 user_image_ = | 306 user_image_ = |
305 user_manager::UserImage(user_manager::GetDefaultImage(image_index_)); | 307 user_manager::UserImage(user_manager::GetDefaultImage(image_index_)); |
306 UpdateUser(); | 308 UpdateUser(); |
307 NotifyJobDone(); | 309 NotifyJobDone(); |
308 } else if (image_index_ == User::kExternalImageIndex || | 310 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL || |
309 image_index_ == User::kProfileImageIndex) { | 311 image_index_ == user_manager::User::USER_IMAGE_PROFILE) { |
310 // Load the user image from a file referenced by |image_path|. This happens | 312 // Load the user image from a file referenced by |image_path|. This happens |
311 // asynchronously. The JPEG image loader can be used here because | 313 // asynchronously. The JPEG image loader can be used here because |
312 // LoadImage() is called only for users whose user image has previously | 314 // 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. | 315 // been set by one of the Set*() methods, which transcode to JPEG format. |
314 DCHECK(!image_path_.empty()); | 316 DCHECK(!image_path_.empty()); |
315 parent_->image_loader_->Start(image_path_.value(), | 317 parent_->image_loader_->Start(image_path_.value(), |
316 0, | 318 0, |
317 base::Bind(&Job::OnLoadImageDone, | 319 base::Bind(&Job::OnLoadImageDone, |
318 weak_factory_.GetWeakPtr(), | 320 weak_factory_.GetWeakPtr(), |
319 false)); | 321 false)); |
(...skipping 18 matching lines...) Expand all Loading... |
338 UpdateLocalState(); | 340 UpdateLocalState(); |
339 NotifyJobDone(); | 341 NotifyJobDone(); |
340 } | 342 } |
341 | 343 |
342 void UserImageManagerImpl::Job::SetToImage( | 344 void UserImageManagerImpl::Job::SetToImage( |
343 int image_index, | 345 int image_index, |
344 const user_manager::UserImage& user_image) { | 346 const user_manager::UserImage& user_image) { |
345 DCHECK(!run_); | 347 DCHECK(!run_); |
346 run_ = true; | 348 run_ = true; |
347 | 349 |
348 DCHECK(image_index == User::kExternalImageIndex || | 350 DCHECK(image_index == user_manager::User::USER_IMAGE_EXTERNAL || |
349 image_index == User::kProfileImageIndex); | 351 image_index == user_manager::User::USER_IMAGE_PROFILE); |
350 | 352 |
351 image_index_ = image_index; | 353 image_index_ = image_index; |
352 user_image_ = user_image; | 354 user_image_ = user_image; |
353 | 355 |
354 UpdateUser(); | 356 UpdateUser(); |
355 SaveImageAndUpdateLocalState(); | 357 SaveImageAndUpdateLocalState(); |
356 } | 358 } |
357 | 359 |
358 void UserImageManagerImpl::Job::SetToImageData(scoped_ptr<std::string> data) { | 360 void UserImageManagerImpl::Job::SetToImageData(scoped_ptr<std::string> data) { |
359 DCHECK(!run_); | 361 DCHECK(!run_); |
360 run_ = true; | 362 run_ = true; |
361 | 363 |
362 image_index_ = User::kExternalImageIndex; | 364 image_index_ = user_manager::User::USER_IMAGE_EXTERNAL; |
363 | 365 |
364 // This method uses the image_loader_, not the unsafe_image_loader_: | 366 // This method uses the image_loader_, not the unsafe_image_loader_: |
365 // * This is necessary because the method is used to update the user image | 367 // * This is necessary because the method is used to update the user image |
366 // whenever the policy for a user is set. In the case of device-local | 368 // whenever the policy for a user is set. In the case of device-local |
367 // accounts, policy may change at any time, even if the user is not | 369 // accounts, policy may change at any time, even if the user is not |
368 // currently logged in (and thus, the unsafe_image_loader_ may not be used). | 370 // currently logged in (and thus, the unsafe_image_loader_ may not be used). |
369 // * This is possible because only JPEG |data| is accepted. No support for | 371 // * This is possible because only JPEG |data| is accepted. No support for |
370 // other image file formats is needed. | 372 // other image file formats is needed. |
371 // * This is safe because the image_loader_ employs a hardened JPEG decoder | 373 // * This is safe because the image_loader_ employs a hardened JPEG decoder |
372 // that protects against malicious invalid image data being used to attack | 374 // that protects against malicious invalid image data being used to attack |
(...skipping 28 matching lines...) Expand all Loading... |
401 const user_manager::UserImage& user_image) { | 403 const user_manager::UserImage& user_image) { |
402 user_image_ = user_image; | 404 user_image_ = user_image; |
403 UpdateUser(); | 405 UpdateUser(); |
404 if (save) | 406 if (save) |
405 SaveImageAndUpdateLocalState(); | 407 SaveImageAndUpdateLocalState(); |
406 else | 408 else |
407 NotifyJobDone(); | 409 NotifyJobDone(); |
408 } | 410 } |
409 | 411 |
410 void UserImageManagerImpl::Job::UpdateUser() { | 412 void UserImageManagerImpl::Job::UpdateUser() { |
411 User* user = parent_->user_manager_->FindUserAndModify(user_id()); | 413 user_manager::User* user = |
| 414 parent_->user_manager_->FindUserAndModify(user_id()); |
412 if (!user) | 415 if (!user) |
413 return; | 416 return; |
414 | 417 |
415 if (!user_image_.image().isNull()) | 418 if (!user_image_.image().isNull()) { |
416 user->SetImage(user_image_, image_index_); | 419 user->SetImage(user_image_, image_index_); |
417 else | 420 } else { |
418 user->SetStubImage(image_index_, false); | 421 user->SetStubImage( |
| 422 user_manager::UserImage( |
| 423 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 424 IDR_PROFILE_PICTURE_LOADING)), |
| 425 image_index_, |
| 426 false); |
| 427 } |
419 user->SetImageURL(image_url_); | 428 user->SetImageURL(image_url_); |
420 | 429 |
421 parent_->OnJobChangedUserImage(); | 430 parent_->OnJobChangedUserImage(); |
422 } | 431 } |
423 | 432 |
424 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState() { | 433 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState() { |
425 base::FilePath user_data_dir; | 434 base::FilePath user_data_dir; |
426 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 435 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
427 image_path_ = user_data_dir.Append(user_id() + kSafeImagePathExtension); | 436 image_path_ = user_data_dir.Append(user_id() + kSafeImagePathExtension); |
428 | 437 |
429 base::PostTaskAndReplyWithResult( | 438 base::PostTaskAndReplyWithResult( |
430 parent_->background_task_runner_, | 439 parent_->background_task_runner_, |
431 FROM_HERE, | 440 FROM_HERE, |
432 base::Bind(&SaveImage, user_image_, image_path_), | 441 base::Bind(&SaveImage, user_image_, image_path_), |
433 base::Bind(&Job::OnSaveImageDone, weak_factory_.GetWeakPtr())); | 442 base::Bind(&Job::OnSaveImageDone, weak_factory_.GetWeakPtr())); |
434 } | 443 } |
435 | 444 |
436 void UserImageManagerImpl::Job::OnSaveImageDone(bool success) { | 445 void UserImageManagerImpl::Job::OnSaveImageDone(bool success) { |
437 if (success || image_index_ == User::kProfileImageIndex) | 446 if (success || image_index_ == user_manager::User::USER_IMAGE_PROFILE) |
438 UpdateLocalState(); | 447 UpdateLocalState(); |
439 NotifyJobDone(); | 448 NotifyJobDone(); |
440 } | 449 } |
441 | 450 |
442 void UserImageManagerImpl::Job::UpdateLocalState() { | 451 void UserImageManagerImpl::Job::UpdateLocalState() { |
443 // Ignore if data stored or cached outside the user's cryptohome is to be | 452 // Ignore if data stored or cached outside the user's cryptohome is to be |
444 // treated as ephemeral. | 453 // treated as ephemeral. |
445 if (parent_->user_manager_->IsUserNonCryptohomeDataEphemeral(user_id())) | 454 if (parent_->user_manager_->IsUserNonCryptohomeDataEphemeral(user_id())) |
446 return; | 455 return; |
447 | 456 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 UserImageManagerImpl::~UserImageManagerImpl() {} | 494 UserImageManagerImpl::~UserImageManagerImpl() {} |
486 | 495 |
487 void UserImageManagerImpl::LoadUserImage() { | 496 void UserImageManagerImpl::LoadUserImage() { |
488 PrefService* local_state = g_browser_process->local_state(); | 497 PrefService* local_state = g_browser_process->local_state(); |
489 const base::DictionaryValue* prefs_images_unsafe = | 498 const base::DictionaryValue* prefs_images_unsafe = |
490 local_state->GetDictionary(kUserImages); | 499 local_state->GetDictionary(kUserImages); |
491 const base::DictionaryValue* prefs_images = | 500 const base::DictionaryValue* prefs_images = |
492 local_state->GetDictionary(kUserImageProperties); | 501 local_state->GetDictionary(kUserImageProperties); |
493 if (!prefs_images && !prefs_images_unsafe) | 502 if (!prefs_images && !prefs_images_unsafe) |
494 return; | 503 return; |
495 User* user = GetUserAndModify(); | 504 user_manager::User* user = GetUserAndModify(); |
496 bool needs_migration = false; | 505 bool needs_migration = false; |
497 | 506 |
498 // If entries are found in both |prefs_images_unsafe| and |prefs_images|, | 507 // If entries are found in both |prefs_images_unsafe| and |prefs_images|, |
499 // |prefs_images| is honored for now but |prefs_images_unsafe| will be | 508 // |prefs_images| is honored for now but |prefs_images_unsafe| will be |
500 // migrated, overwriting the |prefs_images| entry, when the user logs in. | 509 // migrated, overwriting the |prefs_images| entry, when the user logs in. |
501 const base::DictionaryValue* image_properties = NULL; | 510 const base::DictionaryValue* image_properties = NULL; |
502 if (prefs_images_unsafe) { | 511 if (prefs_images_unsafe) { |
503 needs_migration = prefs_images_unsafe->GetDictionaryWithoutPathExpansion( | 512 needs_migration = prefs_images_unsafe->GetDictionaryWithoutPathExpansion( |
504 user_id(), &image_properties); | 513 user_id(), &image_properties); |
505 if (needs_migration) | 514 if (needs_migration) |
506 user_needs_migration_ = true; | 515 user_needs_migration_ = true; |
507 } | 516 } |
508 if (prefs_images) { | 517 if (prefs_images) { |
509 prefs_images->GetDictionaryWithoutPathExpansion(user_id(), | 518 prefs_images->GetDictionaryWithoutPathExpansion(user_id(), |
510 &image_properties); | 519 &image_properties); |
511 } | 520 } |
512 | 521 |
513 // If the user image for |user_id| is managed by policy and the policy-set | 522 // If the user image for |user_id| is managed by policy and the policy-set |
514 // image is being loaded and persisted right now, let that job continue. It | 523 // image is being loaded and persisted right now, let that job continue. It |
515 // will update the user image when done. | 524 // will update the user image when done. |
516 if (IsUserImageManaged() && job_.get()) | 525 if (IsUserImageManaged() && job_.get()) |
517 return; | 526 return; |
518 | 527 |
519 if (!image_properties) { | 528 if (!image_properties) { |
520 SetInitialUserImage(); | 529 SetInitialUserImage(); |
521 return; | 530 return; |
522 } | 531 } |
523 | 532 |
524 int image_index = User::kInvalidImageIndex; | 533 int image_index = user_manager::User::USER_IMAGE_INVALID; |
525 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 534 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
526 if (image_index >= 0 && image_index < user_manager::kDefaultImagesCount) { | 535 if (image_index >= 0 && image_index < user_manager::kDefaultImagesCount) { |
527 user->SetImage( | 536 user->SetImage( |
528 user_manager::UserImage(user_manager::GetDefaultImage(image_index)), | 537 user_manager::UserImage(user_manager::GetDefaultImage(image_index)), |
529 image_index); | 538 image_index); |
530 return; | 539 return; |
531 } | 540 } |
532 | 541 |
533 if (image_index != User::kExternalImageIndex && | 542 if (image_index != user_manager::User::USER_IMAGE_EXTERNAL && |
534 image_index != User::kProfileImageIndex) { | 543 image_index != user_manager::User::USER_IMAGE_PROFILE) { |
535 NOTREACHED(); | 544 NOTREACHED(); |
536 return; | 545 return; |
537 } | 546 } |
538 | 547 |
539 std::string image_url_string; | 548 std::string image_url_string; |
540 image_properties->GetString(kImageURLNodeName, &image_url_string); | 549 image_properties->GetString(kImageURLNodeName, &image_url_string); |
541 GURL image_url(image_url_string); | 550 GURL image_url(image_url_string); |
542 std::string image_path; | 551 std::string image_path; |
543 image_properties->GetString(kImagePathNodeName, &image_path); | 552 image_properties->GetString(kImagePathNodeName, &image_path); |
544 | 553 |
545 user->SetImageURL(image_url); | 554 user->SetImageURL(image_url); |
546 user->SetStubImage(image_index, true); | 555 user->SetStubImage(user_manager::UserImage( |
547 DCHECK(!image_path.empty() || image_index == User::kProfileImageIndex); | 556 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 557 IDR_PROFILE_PICTURE_LOADING)), |
| 558 image_index, |
| 559 true); |
| 560 DCHECK(!image_path.empty() || |
| 561 image_index == user_manager::User::USER_IMAGE_PROFILE); |
548 if (image_path.empty() || needs_migration) { | 562 if (image_path.empty() || needs_migration) { |
549 // Return if either of the following is true: | 563 // Return if either of the following is true: |
550 // * The profile image is to be used but has not been downloaded yet. The | 564 // * The profile image is to be used but has not been downloaded yet. The |
551 // profile image will be downloaded after login. | 565 // profile image will be downloaded after login. |
552 // * The image needs migration. Migration will be performed after login. | 566 // * The image needs migration. Migration will be performed after login. |
553 return; | 567 return; |
554 } | 568 } |
555 | 569 |
556 job_.reset(new Job(this)); | 570 job_.reset(new Job(this)); |
557 job_->LoadImage(base::FilePath(image_path), image_index, image_url); | 571 job_->LoadImage(base::FilePath(image_path), image_index, image_url); |
558 } | 572 } |
559 | 573 |
560 void UserImageManagerImpl::UserLoggedIn(bool user_is_new, | 574 void UserImageManagerImpl::UserLoggedIn(bool user_is_new, |
561 bool user_is_local) { | 575 bool user_is_local) { |
562 const User* user = GetUser(); | 576 const user_manager::User* user = GetUser(); |
563 if (user_is_new) { | 577 if (user_is_new) { |
564 if (!user_is_local) | 578 if (!user_is_local) |
565 SetInitialUserImage(); | 579 SetInitialUserImage(); |
566 } else { | 580 } else { |
567 UMA_HISTOGRAM_ENUMERATION("UserImage.LoggedIn", | 581 UMA_HISTOGRAM_ENUMERATION("UserImage.LoggedIn", |
568 ImageIndexToHistogramIndex(user->image_index()), | 582 ImageIndexToHistogramIndex(user->image_index()), |
569 user_manager::kHistogramImagesCount); | 583 user_manager::kHistogramImagesCount); |
570 | 584 |
571 if (!IsUserImageManaged() && user_needs_migration_) { | 585 if (!IsUserImageManaged() && user_needs_migration_) { |
572 const base::DictionaryValue* prefs_images_unsafe = | 586 const base::DictionaryValue* prefs_images_unsafe = |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 return; | 643 return; |
630 job_.reset(new Job(this)); | 644 job_.reset(new Job(this)); |
631 job_->SetToDefaultImage(default_image_index); | 645 job_->SetToDefaultImage(default_image_index); |
632 } | 646 } |
633 | 647 |
634 void UserImageManagerImpl::SaveUserImage( | 648 void UserImageManagerImpl::SaveUserImage( |
635 const user_manager::UserImage& user_image) { | 649 const user_manager::UserImage& user_image) { |
636 if (IsUserImageManaged()) | 650 if (IsUserImageManaged()) |
637 return; | 651 return; |
638 job_.reset(new Job(this)); | 652 job_.reset(new Job(this)); |
639 job_->SetToImage(User::kExternalImageIndex, user_image); | 653 job_->SetToImage(user_manager::User::USER_IMAGE_EXTERNAL, user_image); |
640 } | 654 } |
641 | 655 |
642 void UserImageManagerImpl::SaveUserImageFromFile(const base::FilePath& path) { | 656 void UserImageManagerImpl::SaveUserImageFromFile(const base::FilePath& path) { |
643 if (IsUserImageManaged()) | 657 if (IsUserImageManaged()) |
644 return; | 658 return; |
645 job_.reset(new Job(this)); | 659 job_.reset(new Job(this)); |
646 job_->SetToPath(path, User::kExternalImageIndex, GURL(), true); | 660 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true); |
647 } | 661 } |
648 | 662 |
649 void UserImageManagerImpl::SaveUserImageFromProfileImage() { | 663 void UserImageManagerImpl::SaveUserImageFromProfileImage() { |
650 if (IsUserImageManaged()) | 664 if (IsUserImageManaged()) |
651 return; | 665 return; |
652 // Use the profile image if it has been downloaded already. Otherwise, use a | 666 // Use the profile image if it has been downloaded already. Otherwise, use a |
653 // stub image (gray avatar). | 667 // stub image (gray avatar). |
654 job_.reset(new Job(this)); | 668 job_.reset(new Job(this)); |
655 job_->SetToImage(User::kProfileImageIndex, | 669 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE, |
656 downloaded_profile_image_.isNull() | 670 downloaded_profile_image_.isNull() |
657 ? user_manager::UserImage() | 671 ? user_manager::UserImage() |
658 : user_manager::UserImage::CreateAndEncode( | 672 : user_manager::UserImage::CreateAndEncode( |
659 downloaded_profile_image_)); | 673 downloaded_profile_image_)); |
660 // If no profile image has been downloaded yet, ensure that a download is | 674 // If no profile image has been downloaded yet, ensure that a download is |
661 // started. | 675 // started. |
662 if (downloaded_profile_image_.isNull()) | 676 if (downloaded_profile_image_.isNull()) |
663 DownloadProfileData(kProfileDownloadReasonProfileImageChosen); | 677 DownloadProfileData(kProfileDownloadReasonProfileImageChosen); |
664 } | 678 } |
665 | 679 |
(...skipping 22 matching lines...) Expand all Loading... |
688 } | 702 } |
689 | 703 |
690 void UserImageManagerImpl::OnExternalDataSet(const std::string& policy) { | 704 void UserImageManagerImpl::OnExternalDataSet(const std::string& policy) { |
691 DCHECK_EQ(policy::key::kUserAvatarImage, policy); | 705 DCHECK_EQ(policy::key::kUserAvatarImage, policy); |
692 if (IsUserImageManaged()) | 706 if (IsUserImageManaged()) |
693 return; | 707 return; |
694 | 708 |
695 has_managed_image_ = true; | 709 has_managed_image_ = true; |
696 job_.reset(); | 710 job_.reset(); |
697 | 711 |
698 const User* user = GetUser(); | 712 const user_manager::User* user = GetUser(); |
699 // If the user image for the currently logged-in user became managed, stop the | 713 // If the user image for the currently logged-in user became managed, stop the |
700 // sync observer so that the policy-set image does not get synced out. | 714 // sync observer so that the policy-set image does not get synced out. |
701 if (user && user->is_logged_in()) | 715 if (user && user->is_logged_in()) |
702 user_image_sync_observer_.reset(); | 716 user_image_sync_observer_.reset(); |
703 } | 717 } |
704 | 718 |
705 void UserImageManagerImpl::OnExternalDataCleared(const std::string& policy) { | 719 void UserImageManagerImpl::OnExternalDataCleared(const std::string& policy) { |
706 DCHECK_EQ(policy::key::kUserAvatarImage, policy); | 720 DCHECK_EQ(policy::key::kUserAvatarImage, policy); |
707 has_managed_image_ = false; | 721 has_managed_image_ = false; |
708 SetInitialUserImage(); | 722 SetInitialUserImage(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 } | 807 } |
794 | 808 |
795 // Nothing to do if the picture is cached or is the default avatar. | 809 // Nothing to do if the picture is cached or is the default avatar. |
796 if (result != kDownloadSuccess) | 810 if (result != kDownloadSuccess) |
797 return; | 811 return; |
798 | 812 |
799 downloaded_profile_image_ = gfx::ImageSkia::CreateFrom1xBitmap( | 813 downloaded_profile_image_ = gfx::ImageSkia::CreateFrom1xBitmap( |
800 downloader->GetProfilePicture()); | 814 downloader->GetProfilePicture()); |
801 profile_image_url_ = GURL(downloader->GetProfilePictureURL()); | 815 profile_image_url_ = GURL(downloader->GetProfilePictureURL()); |
802 | 816 |
803 const User* user = GetUser(); | 817 const user_manager::User* user = GetUser(); |
804 if (user->image_index() == User::kProfileImageIndex) { | 818 if (user->image_index() == user_manager::User::USER_IMAGE_PROFILE) { |
805 VLOG(1) << "Updating profile image for logged-in user."; | 819 VLOG(1) << "Updating profile image for logged-in user."; |
806 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult", | 820 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult", |
807 kDownloadSuccessChanged, | 821 kDownloadSuccessChanged, |
808 kDownloadResultsCount); | 822 kDownloadResultsCount); |
809 // This will persist |downloaded_profile_image_| to disk. | 823 // This will persist |downloaded_profile_image_| to disk. |
810 SaveUserImageFromProfileImage(); | 824 SaveUserImageFromProfileImage(); |
811 } | 825 } |
812 | 826 |
813 content::NotificationService::current()->Notify( | 827 content::NotificationService::current()->Notify( |
814 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | 828 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 } | 868 } |
855 | 869 |
856 void UserImageManagerImpl::SetInitialUserImage() { | 870 void UserImageManagerImpl::SetInitialUserImage() { |
857 // Choose a random default image. | 871 // Choose a random default image. |
858 SaveUserDefaultImageIndex( | 872 SaveUserDefaultImageIndex( |
859 base::RandInt(user_manager::kFirstDefaultImageIndex, | 873 base::RandInt(user_manager::kFirstDefaultImageIndex, |
860 user_manager::kDefaultImagesCount - 1)); | 874 user_manager::kDefaultImagesCount - 1)); |
861 } | 875 } |
862 | 876 |
863 void UserImageManagerImpl::TryToInitDownloadedProfileImage() { | 877 void UserImageManagerImpl::TryToInitDownloadedProfileImage() { |
864 const User* user = GetUser(); | 878 const user_manager::User* user = GetUser(); |
865 if (user->image_index() == User::kProfileImageIndex && | 879 if (user->image_index() == user_manager::User::USER_IMAGE_PROFILE && |
866 downloaded_profile_image_.isNull() && | 880 downloaded_profile_image_.isNull() && !user->image_is_stub()) { |
867 !user->image_is_stub()) { | |
868 // Initialize the |downloaded_profile_image_| for the currently logged-in | 881 // Initialize the |downloaded_profile_image_| for the currently logged-in |
869 // user if it has not been initialized already, the user image is the | 882 // user if it has not been initialized already, the user image is the |
870 // profile image and the user image has been loaded successfully. | 883 // profile image and the user image has been loaded successfully. |
871 VLOG(1) << "Profile image initialized from disk."; | 884 VLOG(1) << "Profile image initialized from disk."; |
872 downloaded_profile_image_ = user->GetImage(); | 885 downloaded_profile_image_ = user->GetImage(); |
873 profile_image_url_ = user->image_url(); | 886 profile_image_url_ = user->image_url(); |
874 } | 887 } |
875 } | 888 } |
876 | 889 |
877 bool UserImageManagerImpl::NeedProfileImage() const { | 890 bool UserImageManagerImpl::NeedProfileImage() const { |
878 const User* user = GetUser(); | 891 const user_manager::User* user = GetUser(); |
879 return IsUserLoggedInAndRegular() && | 892 return IsUserLoggedInAndRegular() && |
880 (user->image_index() == User::kProfileImageIndex || | 893 (user->image_index() == user_manager::User::USER_IMAGE_PROFILE || |
881 profile_image_requested_); | 894 profile_image_requested_); |
882 } | 895 } |
883 | 896 |
884 void UserImageManagerImpl::DownloadProfileData(const std::string& reason) { | 897 void UserImageManagerImpl::DownloadProfileData(const std::string& reason) { |
885 // GAIA profiles exist for regular users only. | 898 // GAIA profiles exist for regular users only. |
886 if (!IsUserLoggedInAndRegular()) | 899 if (!IsUserLoggedInAndRegular()) |
887 return; | 900 return; |
888 | 901 |
889 // If a download is already in progress, allow it to continue, with one | 902 // If a download is already in progress, allow it to continue, with one |
890 // exception: If the current download does not include the profile image but | 903 // exception: If the current download does not include the profile image but |
891 // the image has since become necessary, start a new download that includes | 904 // the image has since become necessary, start a new download that includes |
(...skipping 30 matching lines...) Expand all Loading... |
922 update->RemoveWithoutPathExpansion(user_id(), NULL); | 935 update->RemoveWithoutPathExpansion(user_id(), NULL); |
923 } | 936 } |
924 | 937 |
925 void UserImageManagerImpl::OnJobChangedUserImage() { | 938 void UserImageManagerImpl::OnJobChangedUserImage() { |
926 if (GetUser()->is_logged_in()) | 939 if (GetUser()->is_logged_in()) |
927 TryToInitDownloadedProfileImage(); | 940 TryToInitDownloadedProfileImage(); |
928 | 941 |
929 content::NotificationService::current()->Notify( | 942 content::NotificationService::current()->Notify( |
930 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 943 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
931 content::Source<UserImageManagerImpl>(this), | 944 content::Source<UserImageManagerImpl>(this), |
932 content::Details<const User>(GetUser())); | 945 content::Details<const user_manager::User>(GetUser())); |
933 } | 946 } |
934 | 947 |
935 void UserImageManagerImpl::OnJobDone() { | 948 void UserImageManagerImpl::OnJobDone() { |
936 if (job_.get()) | 949 if (job_.get()) |
937 base::MessageLoopProxy::current()->DeleteSoon(FROM_HERE, job_.release()); | 950 base::MessageLoopProxy::current()->DeleteSoon(FROM_HERE, job_.release()); |
938 else | 951 else |
939 NOTREACHED(); | 952 NOTREACHED(); |
940 | 953 |
941 if (!user_needs_migration_) | 954 if (!user_needs_migration_) |
942 return; | 955 return; |
943 // Migration completed for |user_id|. | 956 // Migration completed for |user_id|. |
944 user_needs_migration_ = false; | 957 user_needs_migration_ = false; |
945 | 958 |
946 const base::DictionaryValue* prefs_images_unsafe = | 959 const base::DictionaryValue* prefs_images_unsafe = |
947 g_browser_process->local_state()->GetDictionary(kUserImages); | 960 g_browser_process->local_state()->GetDictionary(kUserImages); |
948 const base::DictionaryValue* image_properties = NULL; | 961 const base::DictionaryValue* image_properties = NULL; |
949 if (!prefs_images_unsafe->GetDictionaryWithoutPathExpansion( | 962 if (!prefs_images_unsafe->GetDictionaryWithoutPathExpansion( |
950 user_id(), &image_properties)) { | 963 user_id(), &image_properties)) { |
951 NOTREACHED(); | 964 NOTREACHED(); |
952 return; | 965 return; |
953 } | 966 } |
954 | 967 |
955 int image_index = User::kInvalidImageIndex; | 968 int image_index = user_manager::User::USER_IMAGE_INVALID; |
956 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 969 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
957 UMA_HISTOGRAM_ENUMERATION("UserImage.Migration", | 970 UMA_HISTOGRAM_ENUMERATION("UserImage.Migration", |
958 ImageIndexToHistogramIndex(image_index), | 971 ImageIndexToHistogramIndex(image_index), |
959 user_manager::kHistogramImagesCount); | 972 user_manager::kHistogramImagesCount); |
960 | 973 |
961 std::string image_path; | 974 std::string image_path; |
962 image_properties->GetString(kImagePathNodeName, &image_path); | 975 image_properties->GetString(kImagePathNodeName, &image_path); |
963 if (!image_path.empty()) { | 976 if (!image_path.empty()) { |
964 // If an old image exists, delete it and remove |user_id| from the old prefs | 977 // If an old image exists, delete it and remove |user_id| from the old prefs |
965 // dictionary only after the deletion has completed. This ensures that no | 978 // dictionary only after the deletion has completed. This ensures that no |
(...skipping 13 matching lines...) Expand all Loading... |
979 } | 992 } |
980 } | 993 } |
981 | 994 |
982 void UserImageManagerImpl::UpdateLocalStateAfterMigration() { | 995 void UserImageManagerImpl::UpdateLocalStateAfterMigration() { |
983 DictionaryPrefUpdate update(g_browser_process->local_state(), | 996 DictionaryPrefUpdate update(g_browser_process->local_state(), |
984 kUserImages); | 997 kUserImages); |
985 update->RemoveWithoutPathExpansion(user_id(), NULL); | 998 update->RemoveWithoutPathExpansion(user_id(), NULL); |
986 } | 999 } |
987 | 1000 |
988 void UserImageManagerImpl::TryToCreateImageSyncObserver() { | 1001 void UserImageManagerImpl::TryToCreateImageSyncObserver() { |
989 const User* user = GetUser(); | 1002 const user_manager::User* user = GetUser(); |
990 // If the currently logged-in user's user image is managed, the sync observer | 1003 // If the currently logged-in user's user image is managed, the sync observer |
991 // must not be started so that the policy-set image does not get synced out. | 1004 // must not be started so that the policy-set image does not get synced out. |
992 if (!user_image_sync_observer_ && | 1005 if (!user_image_sync_observer_ && |
993 user && user->CanSyncImage() && | 1006 user && user->CanSyncImage() && |
994 !IsUserImageManaged()) { | 1007 !IsUserImageManaged()) { |
995 user_image_sync_observer_.reset(new UserImageSyncObserver(user)); | 1008 user_image_sync_observer_.reset(new UserImageSyncObserver(user)); |
996 } | 1009 } |
997 } | 1010 } |
998 | 1011 |
999 const User* UserImageManagerImpl::GetUser() const { | 1012 const user_manager::User* UserImageManagerImpl::GetUser() const { |
1000 return user_manager_->FindUser(user_id()); | 1013 return user_manager_->FindUser(user_id()); |
1001 } | 1014 } |
1002 | 1015 |
1003 User* UserImageManagerImpl::GetUserAndModify() const { | 1016 user_manager::User* UserImageManagerImpl::GetUserAndModify() const { |
1004 return user_manager_->FindUserAndModify(user_id()); | 1017 return user_manager_->FindUserAndModify(user_id()); |
1005 } | 1018 } |
1006 | 1019 |
1007 bool UserImageManagerImpl::IsUserLoggedInAndRegular() const { | 1020 bool UserImageManagerImpl::IsUserLoggedInAndRegular() const { |
1008 const User* user = GetUser(); | 1021 const user_manager::User* user = GetUser(); |
1009 if (!user) | 1022 if (!user) |
1010 return false; | 1023 return false; |
1011 return user->is_logged_in() && | 1024 return user->is_logged_in() && |
1012 user->GetType() == user_manager::USER_TYPE_REGULAR; | 1025 user->GetType() == user_manager::USER_TYPE_REGULAR; |
1013 } | 1026 } |
1014 | 1027 |
1015 } // namespace chromeos | 1028 } // namespace chromeos |
OLD | NEW |