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

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 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
« no previous file with comments | « chrome/browser/chromeos/login/user_manager.h ('k') | chrome/browser/image_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING)); 460 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING));
448 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); 461 SaveImageToLocalState(username, "", User::kProfileImageIndex, false);
449 } 462 }
450 } 463 }
451 464
452 void UserManager::DownloadProfileImage() { 465 void UserManager::DownloadProfileImage() {
453 if (profile_image_downloader_.get()) { 466 if (profile_image_downloader_.get()) {
454 // Another download is already in progress 467 // Another download is already in progress
455 return; 468 return;
456 } 469 }
457 profile_image_downloader_.reset(new ProfileImageDownloader(this)); 470
471 if (logged_in_user().email().empty()) {
472 // This is a guest login so there's no profile image to download.
473 return;
474 }
475
476 profile_image_downloader_.reset(new ProfileDownloader(this));
458 profile_image_downloader_->Start(); 477 profile_image_downloader_->Start();
459 profile_image_load_start_time_ = base::Time::Now(); 478 profile_image_load_start_time_ = base::Time::Now();
460 } 479 }
461 480
462 void UserManager::Observe(int type, 481 void UserManager::Observe(int type,
463 const content::NotificationSource& source, 482 const content::NotificationSource& source,
464 const content::NotificationDetails& details) { 483 const content::NotificationDetails& details) {
465 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { 484 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) {
466 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 485 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
467 base::Bind(&UserManager::CheckOwnership, 486 base::Bind(&UserManager::CheckOwnership,
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 801
783 // UserManager should be accessed only on UI thread. 802 // UserManager should be accessed only on UI thread.
784 BrowserThread::PostTask( 803 BrowserThread::PostTask(
785 BrowserThread::UI, 804 BrowserThread::UI,
786 FROM_HERE, 805 FROM_HERE,
787 base::Bind(&UserManager::UpdateOwnership, 806 base::Bind(&UserManager::UpdateOwnership,
788 base::Unretained(this), 807 base::Unretained(this),
789 is_owner)); 808 is_owner));
790 } 809 }
791 810
792 void UserManager::OnDownloadSuccess(const SkBitmap& image) { 811 int UserManager::GetDesiredImageSideLength() {
793 VLOG(1) << "Downloaded profile image for logged-in user."; 812 return login::kUserImageSize;
794 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", 813 }
795 ProfileImageDownloader::kDownloadSuccess,
796 ProfileImageDownloader::kDownloadResultsCount);
797 814
798 // Check if this image is not the same as already downloaded. 815 Profile* UserManager::GetBrowserProfile() {
799 std::string new_image_data_url = web_ui_util::GetImageDataUrl(image); 816 return ProfileManager::GetDefaultProfile();
800 if (!downloaded_profile_image_data_url_.empty() && 817 }
801 new_image_data_url == downloaded_profile_image_data_url_)
802 return;
803 818
804 downloaded_profile_image_data_url_ = new_image_data_url; 819 void UserManager::OnDownloadComplete(ProfileDownloader* downloader,
805 downloaded_profile_image_ = image; 820 bool success) {
821 ProfileDownloadResult result;
822 if (!success)
823 result = kDownloadFailure;
824 else if (downloader->GetProfilePicture().isNull())
825 result = kDownloadDefault;
826 else
827 result = kDownloadSuccess;
828 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult",
829 result, kDownloadResultsCount);
806 830
807 if (logged_in_user().image_index() == User::kProfileImageIndex) { 831 if (result == kDownloadSuccess) {
808 std::string current_image_data_url = 832 // Check if this image is not the same as already downloaded.
809 web_ui_util::GetImageDataUrl(logged_in_user().image()); 833 std::string new_image_data_url =
810 if (current_image_data_url == new_image_data_url) 834 web_ui_util::GetImageDataUrl(downloader->GetProfilePicture());
835 if (!downloaded_profile_image_data_url_.empty() &&
836 new_image_data_url == downloaded_profile_image_data_url_)
811 return; 837 return;
812 838
813 VLOG(1) << "Updating profile image for logged-in user"; 839 downloaded_profile_image_data_url_ = new_image_data_url;
814 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", 840 downloaded_profile_image_ = downloader->GetProfilePicture();
815 ProfileImageDownloader::kDownloadSuccessChanged,
816 ProfileImageDownloader::kDownloadResultsCount);
817 841
818 // This will persist |downloaded_profile_image_| to file. 842 if (logged_in_user().image_index() == User::kProfileImageIndex) {
819 SaveUserImageFromProfileImage(logged_in_user().email()); 843 std::string current_image_data_url =
844 web_ui_util::GetImageDataUrl(logged_in_user().image());
845 if (current_image_data_url == new_image_data_url)
846 return;
847
848 VLOG(1) << "Updating profile image for logged-in user";
849 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult",
850 kDownloadSuccessChanged,
851 kDownloadResultsCount);
852
853 // This will persist |downloaded_profile_image_| to file.
854 SaveUserImageFromProfileImage(logged_in_user().email());
855 }
820 } 856 }
821 857
822 content::NotificationService::current()->Notify( 858 if (result == kDownloadSuccess) {
823 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, 859 content::NotificationService::current()->Notify(
824 content::Source<UserManager>(this), 860 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED,
825 content::Details<const SkBitmap>(&image)); 861 content::Source<UserManager>(this),
862 content::Details<const SkBitmap>(&downloader->GetProfilePicture()));
863 } else {
864 content::NotificationService::current()->Notify(
865 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
866 content::Source<UserManager>(this),
867 content::NotificationService::NoDetails());
868 }
826 869
827 profile_image_downloader_.reset(); 870 profile_image_downloader_.reset();
828 } 871 }
829 872
830 void UserManager::OnDownloadFailure() {
831 VLOG(1) << "Download of profile image for logged-in user failed.";
832 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
833 ProfileImageDownloader::kDownloadFailure,
834 ProfileImageDownloader::kDownloadResultsCount);
835 content::NotificationService::current()->Notify(
836 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
837 content::Source<UserManager>(this),
838 content::NotificationService::NoDetails());
839 profile_image_downloader_.reset();
840 }
841
842 void UserManager::OnDownloadDefaultImage() {
843 VLOG(1) << "Logged-in user still has the default profile image.";
844 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
845 ProfileImageDownloader::kDownloadDefault,
846 ProfileImageDownloader::kDownloadResultsCount);
847 content::NotificationService::current()->Notify(
848 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
849 content::Source<UserManager>(this),
850 content::NotificationService::NoDetails());
851 profile_image_downloader_.reset();
852 }
853
854 User* UserManager::CreateUser(const std::string& email) const { 873 User* UserManager::CreateUser(const std::string& email) const {
855 User* user = new User(email); 874 User* user = new User(email);
856 user->set_oauth_token_status(GetUserOAuthStatus(email)); 875 user->set_oauth_token_status(GetUserOAuthStatus(email));
857 // Used to determine whether user's display name is unique. 876 // Used to determine whether user's display name is unique.
858 ++display_name_count_[user->GetDisplayName()]; 877 ++display_name_count_[user->GetDisplayName()];
859 return user; 878 return user;
860 } 879 }
861 880
862 } // namespace chromeos 881 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager.h ('k') | chrome/browser/image_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698