Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1100)

Side by Side Diff: chrome/browser/chromeos/login/user_manager.cc

Issue 8510069: Make ProfileImageDownloader available to non-chromeos code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/user_manager.h" 5 #include "chrome/browser/chromeos/login/user_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 29 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
30 #include "chrome/browser/chromeos/login/default_user_images.h" 30 #include "chrome/browser/chromeos/login/default_user_images.h"
31 #include "chrome/browser/chromeos/login/helper.h" 31 #include "chrome/browser/chromeos/login/helper.h"
32 #include "chrome/browser/chromeos/login/login_display.h" 32 #include "chrome/browser/chromeos/login/login_display.h"
33 #include "chrome/browser/chromeos/login/ownership_service.h" 33 #include "chrome/browser/chromeos/login/ownership_service.h"
34 #include "chrome/browser/chromeos/system/runtime_environment.h" 34 #include "chrome/browser/chromeos/system/runtime_environment.h"
35 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 35 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
36 #include "chrome/browser/defaults.h" 36 #include "chrome/browser/defaults.h"
37 #include "chrome/browser/prefs/pref_service.h" 37 #include "chrome/browser/prefs/pref_service.h"
38 #include "chrome/browser/prefs/scoped_user_pref_update.h" 38 #include "chrome/browser/prefs/scoped_user_pref_update.h"
39 #include "chrome/browser/profiles/profile_downloader.h"
40 #include "chrome/browser/profiles/profile_manager.h"
39 #include "chrome/browser/ui/webui/web_ui_util.h" 41 #include "chrome/browser/ui/webui/web_ui_util.h"
40 #include "chrome/common/chrome_notification_types.h" 42 #include "chrome/common/chrome_notification_types.h"
41 #include "chrome/common/chrome_paths.h" 43 #include "chrome/common/chrome_paths.h"
42 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
43 #include "content/public/browser/browser_thread.h" 45 #include "content/public/browser/browser_thread.h"
44 #include "content/public/browser/notification_service.h" 46 #include "content/public/browser/notification_service.h"
45 #include "content/public/common/url_constants.h" 47 #include "content/public/common/url_constants.h"
46 #include "crypto/nss_util.h" 48 #include "crypto/nss_util.h"
47 #include "grit/theme_resources.h" 49 #include "grit/theme_resources.h"
48 #include "ui/base/resource/resource_bundle.h" 50 #include "ui/base/resource/resource_bundle.h"
(...skipping 29 matching lines...) Expand all
78 80
79 // Index of the default image used as stub while the real user image is loading 81 // Index of the default image used as stub while the real user image is loading
80 // from file and for the |kStubUser| user. 82 // from file and for the |kStubUser| user.
81 const int kStubDefaultImageIndex = 0; 83 const int kStubDefaultImageIndex = 0;
82 84
83 // Delay betweeen user login and attempt to update user's profile image. 85 // Delay betweeen user login and attempt to update user's profile image.
84 const long kProfileImageDownloadDelayMs = 10000; 86 const long kProfileImageDownloadDelayMs = 10000;
85 87
86 base::LazyInstance<UserManager> g_user_manager = LAZY_INSTANCE_INITIALIZER; 88 base::LazyInstance<UserManager> g_user_manager = LAZY_INSTANCE_INITIALIZER;
87 89
90 // Enum for reporting histograms about profile picture download.
91 enum ProfileDownloadResult {
92 kDownloadSuccessChanged,
93 kDownloadSuccess,
94 kDownloadFailure,
95 kDownloadDefault,
96
97 // Must be the last, convenient count.
98 kDownloadResultsCount
99 };
100
88 // Used to handle the asynchronous response of deleting a cryptohome directory. 101 // Used to handle the asynchronous response of deleting a cryptohome directory.
89 class RemoveAttempt : public CryptohomeLibrary::Delegate { 102 class RemoveAttempt : public CryptohomeLibrary::Delegate {
90 public: 103 public:
91 // Creates new remove attempt for the given user. Note, |delegate| can 104 // Creates new remove attempt for the given user. Note, |delegate| can
92 // be NULL. 105 // be NULL.
93 RemoveAttempt(const std::string& user_email, 106 RemoveAttempt(const std::string& user_email,
94 chromeos::RemoveUserDelegate* delegate) 107 chromeos::RemoveUserDelegate* delegate)
95 : user_email_(user_email), 108 : user_email_(user_email),
96 delegate_(delegate), 109 delegate_(delegate),
97 weak_factory_(this) { 110 weak_factory_(this) {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING)); 463 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING));
451 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); 464 SaveImageToLocalState(username, "", User::kProfileImageIndex, false);
452 } 465 }
453 } 466 }
454 467
455 void UserManager::DownloadProfileImage() { 468 void UserManager::DownloadProfileImage() {
456 if (profile_image_downloader_.get()) { 469 if (profile_image_downloader_.get()) {
457 // Another download is already in progress 470 // Another download is already in progress
458 return; 471 return;
459 } 472 }
460 profile_image_downloader_.reset(new ProfileImageDownloader(this)); 473
474 if (logged_in_user().email().empty()) {
475 // This is a guest login so there's profile image to download.
Ivan Korotkov 2011/11/17 08:37:12 ... there's no...
sail 2011/11/21 22:01:00 Done.
476 return;
477 }
478
479 profile_image_downloader_.reset(new ProfileDownloader(this));
461 profile_image_downloader_->Start(); 480 profile_image_downloader_->Start();
462 profile_image_load_start_time_ = base::Time::Now(); 481 profile_image_load_start_time_ = base::Time::Now();
463 } 482 }
464 483
465 void UserManager::Observe(int type, 484 void UserManager::Observe(int type,
466 const content::NotificationSource& source, 485 const content::NotificationSource& source,
467 const content::NotificationDetails& details) { 486 const content::NotificationDetails& details) {
468 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { 487 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) {
469 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 488 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
470 base::Bind(&UserManager::CheckOwnership, 489 base::Bind(&UserManager::CheckOwnership,
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 805
787 // UserManager should be accessed only on UI thread. 806 // UserManager should be accessed only on UI thread.
788 BrowserThread::PostTask( 807 BrowserThread::PostTask(
789 BrowserThread::UI, 808 BrowserThread::UI,
790 FROM_HERE, 809 FROM_HERE,
791 base::Bind(&UserManager::UpdateOwnership, 810 base::Bind(&UserManager::UpdateOwnership,
792 base::Unretained(this), 811 base::Unretained(this),
793 is_owner)); 812 is_owner));
794 } 813 }
795 814
796 void UserManager::OnDownloadSuccess(const SkBitmap& image) { 815 int UserManager::GetDesiredImageSize() {
797 VLOG(1) << "Downloaded profile image for logged-in user."; 816 return login::kUserImageSize;
817 }
818
819 Profile* UserManager::GetBrowserProfile() {
820 return ProfileManager::GetDefaultProfile();
821 }
822
823 void UserManager::OnDownloadComplete(ProfileDownloader* downloader,
824 bool success) {
825 ProfileDownloadResult result;
826 if (!success)
827 result = kDownloadFailure;
828 else if (downloader->GetProfilePicture().isNull())
829 result = kDownloadDefault;
830 else
831 result = kDownloadSuccess;
798 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", 832 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
Ivan Korotkov 2011/11/17 08:37:12 Can you please rename this to "UserImage.ProfileDo
sail 2011/11/21 22:01:00 Done.
799 ProfileImageDownloader::kDownloadSuccess, 833 result, kDownloadResultsCount);
800 ProfileImageDownloader::kDownloadResultsCount);
801 834
802 // Check if this image is not the same as already downloaded. 835 if (result == kDownloadSuccess) {
803 std::string new_image_data_url = web_ui_util::GetImageDataUrl(image); 836 // Check if this image is not the same as already downloaded.
804 if (!downloaded_profile_image_data_url_.empty() && 837 std::string new_image_data_url =
805 new_image_data_url == downloaded_profile_image_data_url_) 838 web_ui_util::GetImageDataUrl(downloader->GetProfilePicture());
806 return; 839 if (!downloaded_profile_image_data_url_.empty() &&
807 840 new_image_data_url == downloaded_profile_image_data_url_)
808 downloaded_profile_image_data_url_ = new_image_data_url;
809 downloaded_profile_image_ = image;
810
811 if (logged_in_user().image_index() == User::kProfileImageIndex) {
812 std::string current_image_data_url =
813 web_ui_util::GetImageDataUrl(logged_in_user().image());
814 if (current_image_data_url == new_image_data_url)
815 return; 841 return;
816 842
817 VLOG(1) << "Updating profile image for logged-in user"; 843 downloaded_profile_image_data_url_ = new_image_data_url;
818 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", 844 downloaded_profile_image_ = downloader->GetProfilePicture();
819 ProfileImageDownloader::kDownloadSuccessChanged,
820 ProfileImageDownloader::kDownloadResultsCount);
821 845
822 // This will persist |downloaded_profile_image_| to file. 846 if (logged_in_user().image_index() == User::kProfileImageIndex) {
823 SaveUserImageFromProfileImage(logged_in_user().email()); 847 std::string current_image_data_url =
848 web_ui_util::GetImageDataUrl(logged_in_user().image());
849 if (current_image_data_url == new_image_data_url)
850 return;
851
852 VLOG(1) << "Updating profile image for logged-in user";
853 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
854 kDownloadSuccessChanged,
855 kDownloadResultsCount);
856
857 // This will persist |downloaded_profile_image_| to file.
858 SaveUserImageFromProfileImage(logged_in_user().email());
859 }
824 } 860 }
825 861
862 chrome::NotificationType type = result == kDownloadSuccess ?
863 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED :
864 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED;
826 content::NotificationService::current()->Notify( 865 content::NotificationService::current()->Notify(
827 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, 866 type, content::Source<UserManager>(this),
828 content::Source<UserManager>(this), 867 content::NotificationService::NoDetails());
Ivan Korotkov 2011/11/17 08:37:12 For NOTIFICATION_PROFILE_IMAGE_UPDATED, details sh
sail 2011/11/21 22:01:00 Done.
829 content::Details<const SkBitmap>(&image));
830 868
831 profile_image_downloader_.reset(); 869 profile_image_downloader_.reset();
832 } 870 }
833 871
834 void UserManager::OnDownloadFailure() {
835 VLOG(1) << "Download of profile image for logged-in user failed.";
836 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
837 ProfileImageDownloader::kDownloadFailure,
838 ProfileImageDownloader::kDownloadResultsCount);
839 content::NotificationService::current()->Notify(
840 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
841 content::Source<UserManager>(this),
842 content::NotificationService::NoDetails());
843 profile_image_downloader_.reset();
844 }
845
846 void UserManager::OnDownloadDefaultImage() {
847 VLOG(1) << "Logged-in user still has the default profile image.";
848 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
849 ProfileImageDownloader::kDownloadDefault,
850 ProfileImageDownloader::kDownloadResultsCount);
851 content::NotificationService::current()->Notify(
852 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
853 content::Source<UserManager>(this),
854 content::NotificationService::NoDetails());
855 profile_image_downloader_.reset();
856 }
857
858 User* UserManager::CreateUser(const std::string& email) const { 872 User* UserManager::CreateUser(const std::string& email) const {
859 User* user = new User(email); 873 User* user = new User(email);
860 user->set_oauth_token_status(GetUserOAuthStatus(email)); 874 user->set_oauth_token_status(GetUserOAuthStatus(email));
861 // Used to determine whether user's display name is unique. 875 // Used to determine whether user's display name is unique.
862 ++display_name_count_[user->GetDisplayName()]; 876 ++display_name_count_[user->GetDisplayName()];
863 return user; 877 return user;
864 } 878 }
865 879
866 } // namespace chromeos 880 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698