OLD | NEW |
---|---|
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 16 matching lines...) Expand all Loading... | |
27 #include "chrome/browser/chromeos/cros/cros_library.h" | 27 #include "chrome/browser/chromeos/cros/cros_library.h" |
28 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 28 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
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/gaia_userinfo/profile_downloader.h" | |
37 #include "chrome/browser/prefs/pref_service.h" | 38 #include "chrome/browser/prefs/pref_service.h" |
38 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 39 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
39 #include "chrome/browser/ui/webui/web_ui_util.h" | 40 #include "chrome/browser/ui/webui/web_ui_util.h" |
40 #include "chrome/common/chrome_notification_types.h" | 41 #include "chrome/common/chrome_notification_types.h" |
41 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
42 #include "chrome/common/chrome_switches.h" | 43 #include "chrome/common/chrome_switches.h" |
43 #include "content/public/browser/browser_thread.h" | 44 #include "content/public/browser/browser_thread.h" |
44 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
45 #include "content/public/common/url_constants.h" | 46 #include "content/public/common/url_constants.h" |
46 #include "crypto/nss_util.h" | 47 #include "crypto/nss_util.h" |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING)); | 451 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING)); |
451 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); | 452 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); |
452 } | 453 } |
453 } | 454 } |
454 | 455 |
455 void UserManager::DownloadProfileImage() { | 456 void UserManager::DownloadProfileImage() { |
456 if (profile_image_downloader_.get()) { | 457 if (profile_image_downloader_.get()) { |
457 // Another download is already in progress | 458 // Another download is already in progress |
458 return; | 459 return; |
459 } | 460 } |
460 profile_image_downloader_.reset(new ProfileImageDownloader(this)); | 461 profile_image_downloader_.reset(new ProfileDownloader(this)); |
461 profile_image_downloader_->Start(); | 462 profile_image_downloader_->Start(); |
462 profile_image_load_start_time_ = base::Time::Now(); | 463 profile_image_load_start_time_ = base::Time::Now(); |
463 } | 464 } |
464 | 465 |
465 void UserManager::Observe(int type, | 466 void UserManager::Observe(int type, |
466 const content::NotificationSource& source, | 467 const content::NotificationSource& source, |
467 const content::NotificationDetails& details) { | 468 const content::NotificationDetails& details) { |
468 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { | 469 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { |
469 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 470 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
470 base::Bind(&UserManager::CheckOwnership, | 471 base::Bind(&UserManager::CheckOwnership, |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 | 787 |
787 // UserManager should be accessed only on UI thread. | 788 // UserManager should be accessed only on UI thread. |
788 BrowserThread::PostTask( | 789 BrowserThread::PostTask( |
789 BrowserThread::UI, | 790 BrowserThread::UI, |
790 FROM_HERE, | 791 FROM_HERE, |
791 base::Bind(&UserManager::UpdateOwnership, | 792 base::Bind(&UserManager::UpdateOwnership, |
792 base::Unretained(this), | 793 base::Unretained(this), |
793 is_owner)); | 794 is_owner)); |
794 } | 795 } |
795 | 796 |
796 void UserManager::OnDownloadSuccess(const SkBitmap& image) { | 797 int UserManager::GetDesiredImageSize() { |
798 return login::kUserImageSize; | |
799 } | |
800 | |
801 std::string UserManager::GetProfileUserName() { | |
802 return logged_in_user().email(); | |
803 } | |
804 | |
805 Profile* UserManager::GetBrowserProfile() { | |
806 return ProfileManager::GetDefaultProfile(); | |
whywhat
2011/11/15 12:19:21
Guess you need to include profile_manager.h for th
sail
2011/11/15 20:17:22
Done.
| |
807 } | |
808 | |
809 void UserManager::OnDownloadSuccess(const string16& full_name, | |
whywhat
2011/11/15 12:19:21
We should at least DCHECK that full_name is the sa
sail
2011/11/15 20:17:22
Actually the full_name here is the first and last
| |
810 const SkBitmap& image) { | |
797 VLOG(1) << "Downloaded profile image for logged-in user."; | 811 VLOG(1) << "Downloaded profile image for logged-in user."; |
798 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", | 812 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", |
799 ProfileImageDownloader::kDownloadSuccess, | 813 ProfileDownloader::kDownloadSuccess, |
800 ProfileImageDownloader::kDownloadResultsCount); | 814 ProfileDownloader::kDownloadResultsCount); |
801 | 815 |
802 // Check if this image is not the same as already downloaded. | 816 // Check if this image is not the same as already downloaded. |
803 std::string new_image_data_url = web_ui_util::GetImageDataUrl(image); | 817 std::string new_image_data_url = web_ui_util::GetImageDataUrl(image); |
804 if (!downloaded_profile_image_data_url_.empty() && | 818 if (!downloaded_profile_image_data_url_.empty() && |
805 new_image_data_url == downloaded_profile_image_data_url_) | 819 new_image_data_url == downloaded_profile_image_data_url_) |
806 return; | 820 return; |
807 | 821 |
808 downloaded_profile_image_data_url_ = new_image_data_url; | 822 downloaded_profile_image_data_url_ = new_image_data_url; |
809 downloaded_profile_image_ = image; | 823 downloaded_profile_image_ = image; |
810 | 824 |
811 if (logged_in_user().image_index() == User::kProfileImageIndex) { | 825 if (logged_in_user().image_index() == User::kProfileImageIndex) { |
812 std::string current_image_data_url = | 826 std::string current_image_data_url = |
813 web_ui_util::GetImageDataUrl(logged_in_user().image()); | 827 web_ui_util::GetImageDataUrl(logged_in_user().image()); |
814 if (current_image_data_url == new_image_data_url) | 828 if (current_image_data_url == new_image_data_url) |
815 return; | 829 return; |
816 | 830 |
817 VLOG(1) << "Updating profile image for logged-in user"; | 831 VLOG(1) << "Updating profile image for logged-in user"; |
818 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", | 832 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", |
819 ProfileImageDownloader::kDownloadSuccessChanged, | 833 ProfileDownloader::kDownloadSuccessChanged, |
820 ProfileImageDownloader::kDownloadResultsCount); | 834 ProfileDownloader::kDownloadResultsCount); |
821 | 835 |
822 // This will persist |downloaded_profile_image_| to file. | 836 // This will persist |downloaded_profile_image_| to file. |
823 SaveUserImageFromProfileImage(logged_in_user().email()); | 837 SaveUserImageFromProfileImage(logged_in_user().email()); |
824 } | 838 } |
825 | 839 |
826 content::NotificationService::current()->Notify( | 840 content::NotificationService::current()->Notify( |
827 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | 841 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, |
828 content::Source<UserManager>(this), | 842 content::Source<UserManager>(this), |
829 content::Details<const SkBitmap>(&image)); | 843 content::Details<const SkBitmap>(&image)); |
830 | 844 |
831 profile_image_downloader_.reset(); | 845 profile_image_downloader_.reset(); |
832 } | 846 } |
833 | 847 |
834 void UserManager::OnDownloadFailure() { | 848 void UserManager::OnDownloadFailure() { |
835 VLOG(1) << "Download of profile image for logged-in user failed."; | 849 VLOG(1) << "Download of profile image for logged-in user failed."; |
836 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", | 850 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", |
837 ProfileImageDownloader::kDownloadFailure, | 851 ProfileDownloader::kDownloadFailure, |
838 ProfileImageDownloader::kDownloadResultsCount); | 852 ProfileDownloader::kDownloadResultsCount); |
839 content::NotificationService::current()->Notify( | 853 content::NotificationService::current()->Notify( |
840 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | 854 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, |
841 content::Source<UserManager>(this), | 855 content::Source<UserManager>(this), |
842 content::NotificationService::NoDetails()); | 856 content::NotificationService::NoDetails()); |
843 profile_image_downloader_.reset(); | 857 profile_image_downloader_.reset(); |
844 } | 858 } |
845 | 859 |
846 void UserManager::OnDownloadDefaultImage() { | 860 void UserManager::OnDownloadDefaultImage(const string16& full_name) { |
847 VLOG(1) << "Logged-in user still has the default profile image."; | 861 VLOG(1) << "Logged-in user still has the default profile image."; |
848 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", | 862 UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn", |
849 ProfileImageDownloader::kDownloadDefault, | 863 ProfileDownloader::kDownloadDefault, |
850 ProfileImageDownloader::kDownloadResultsCount); | 864 ProfileDownloader::kDownloadResultsCount); |
851 content::NotificationService::current()->Notify( | 865 content::NotificationService::current()->Notify( |
852 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | 866 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, |
853 content::Source<UserManager>(this), | 867 content::Source<UserManager>(this), |
854 content::NotificationService::NoDetails()); | 868 content::NotificationService::NoDetails()); |
855 profile_image_downloader_.reset(); | 869 profile_image_downloader_.reset(); |
856 } | 870 } |
857 | 871 |
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 |
OLD | NEW |