| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "chrome/browser/profiles/profile_downloader.h" | 40 #include "chrome/browser/profiles/profile_downloader.h" |
| 41 #include "chrome/browser/profiles/profile_manager.h" | 41 #include "chrome/browser/profiles/profile_manager.h" |
| 42 #include "chrome/browser/ui/webui/web_ui_util.h" | 42 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 43 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
| 44 #include "chrome/common/chrome_paths.h" | 44 #include "chrome/common/chrome_paths.h" |
| 45 #include "chrome/common/chrome_switches.h" | 45 #include "chrome/common/chrome_switches.h" |
| 46 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 47 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
| 48 #include "content/public/common/url_constants.h" | 48 #include "content/public/common/url_constants.h" |
| 49 #include "crypto/nss_util.h" | 49 #include "crypto/nss_util.h" |
| 50 #include "grit/theme_resources.h" | |
| 51 #include "ui/base/resource/resource_bundle.h" | |
| 52 #include "ui/gfx/codec/png_codec.h" | 50 #include "ui/gfx/codec/png_codec.h" |
| 53 | 51 |
| 54 #if defined(TOOLKIT_USES_GTK) | 52 #if defined(TOOLKIT_USES_GTK) |
| 55 #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" | 53 #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" |
| 56 #endif | 54 #endif |
| 57 | 55 |
| 58 using content::BrowserThread; | 56 using content::BrowserThread; |
| 59 | 57 |
| 60 namespace chromeos { | 58 namespace chromeos { |
| 61 | 59 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 users_.insert(users_.begin(), logged_in_user_); | 275 users_.insert(users_.begin(), logged_in_user_); |
| 278 | 276 |
| 279 NotifyOnLogin(); | 277 NotifyOnLogin(); |
| 280 | 278 |
| 281 if (current_user_is_new_) { | 279 if (current_user_is_new_) { |
| 282 SetInitialUserImage(email); | 280 SetInitialUserImage(email); |
| 283 } else { | 281 } else { |
| 284 // Download profile image if it's user image and see if it has changed. | 282 // Download profile image if it's user image and see if it has changed. |
| 285 int image_index = logged_in_user_->image_index(); | 283 int image_index = logged_in_user_->image_index(); |
| 286 if (image_index == User::kProfileImageIndex) { | 284 if (image_index == User::kProfileImageIndex) { |
| 285 InitDownloadedProfileImage(); |
| 287 BrowserThread::PostDelayedTask( | 286 BrowserThread::PostDelayedTask( |
| 288 BrowserThread::UI, | 287 BrowserThread::UI, |
| 289 FROM_HERE, | 288 FROM_HERE, |
| 290 base::Bind(&UserManager::DownloadProfileImage, | 289 base::Bind(&UserManager::DownloadProfileImage, |
| 291 base::Unretained(this)), | 290 base::Unretained(this)), |
| 292 kProfileImageDownloadDelayMs); | 291 kProfileImageDownloadDelayMs); |
| 293 } | 292 } |
| 294 | 293 |
| 295 int histogram_index = image_index; | 294 int histogram_index = image_index; |
| 296 switch (image_index) { | 295 switch (image_index) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 base::Bind(&UserManager::SaveUserImage, | 485 base::Bind(&UserManager::SaveUserImage, |
| 487 base::Unretained(this), username)); | 486 base::Unretained(this), username)); |
| 488 } | 487 } |
| 489 | 488 |
| 490 void UserManager::SaveUserImageFromProfileImage(const std::string& username) { | 489 void UserManager::SaveUserImageFromProfileImage(const std::string& username) { |
| 491 if (!downloaded_profile_image_.empty()) { | 490 if (!downloaded_profile_image_.empty()) { |
| 492 // Profile image has already been downloaded, so save it to file right now. | 491 // Profile image has already been downloaded, so save it to file right now. |
| 493 SaveUserImageInternal(username, User::kProfileImageIndex, | 492 SaveUserImageInternal(username, User::kProfileImageIndex, |
| 494 downloaded_profile_image_); | 493 downloaded_profile_image_); |
| 495 } else { | 494 } else { |
| 496 // No profile image - use the default gray avatar. | 495 // No profile image - use the stub image (gray avatar). |
| 497 SetUserImage(username, User::kProfileImageIndex, | 496 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); |
| 498 *ResourceBundle::GetSharedInstance(). | |
| 499 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING)); | |
| 500 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); | 497 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); |
| 501 } | 498 } |
| 502 } | 499 } |
| 503 | 500 |
| 504 void UserManager::DownloadProfileImage() { | 501 void UserManager::DownloadProfileImage() { |
| 505 if (profile_image_downloader_.get()) { | 502 if (profile_image_downloader_.get()) { |
| 506 // Another download is already in progress | 503 // Another download is already in progress |
| 507 return; | 504 return; |
| 508 } | 505 } |
| 509 | 506 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 // TODO(avayvod): Reading image path as a string is here for | 607 // TODO(avayvod): Reading image path as a string is here for |
| 611 // backward compatibility. | 608 // backward compatibility. |
| 612 std::string image_path; | 609 std::string image_path; |
| 613 base::DictionaryValue* image_properties; | 610 base::DictionaryValue* image_properties; |
| 614 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { | 611 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { |
| 615 int image_id = User::kInvalidImageIndex; | 612 int image_id = User::kInvalidImageIndex; |
| 616 if (IsDefaultImagePath(image_path, &image_id)) { | 613 if (IsDefaultImagePath(image_path, &image_id)) { |
| 617 user->SetImage(GetDefaultImage(image_id), image_id); | 614 user->SetImage(GetDefaultImage(image_id), image_id); |
| 618 } else { | 615 } else { |
| 619 int image_index = User::kExternalImageIndex; | 616 int image_index = User::kExternalImageIndex; |
| 620 // Until image has been loaded, use a stub. | 617 // Until image has been loaded, use the stub image. |
| 621 user->SetImage(*ResourceBundle::GetSharedInstance(). | 618 user->SetStubImage(image_index); |
| 622 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING), | |
| 623 image_index); | |
| 624 DCHECK(!image_path.empty()); | 619 DCHECK(!image_path.empty()); |
| 625 // Load user image asynchronously. | 620 // Load user image asynchronously. |
| 626 image_loader_->Start( | 621 image_loader_->Start( |
| 627 image_path, 0, | 622 image_path, 0, |
| 628 base::Bind(&UserManager::SetUserImage, | 623 base::Bind(&UserManager::SetUserImage, |
| 629 base::Unretained(this), email, image_index)); | 624 base::Unretained(this), email, image_index)); |
| 630 } | 625 } |
| 631 } else if (prefs_images->GetDictionaryWithoutPathExpansion( | 626 } else if (prefs_images->GetDictionaryWithoutPathExpansion( |
| 632 email, &image_properties)) { | 627 email, &image_properties)) { |
| 633 int image_index = User::kInvalidImageIndex; | 628 int image_index = User::kInvalidImageIndex; |
| 634 image_properties->GetString(kImagePathNodeName, &image_path); | 629 image_properties->GetString(kImagePathNodeName, &image_path); |
| 635 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 630 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
| 636 if (image_index >= 0 && image_index < kDefaultImagesCount) { | 631 if (image_index >= 0 && image_index < kDefaultImagesCount) { |
| 637 user->SetImage(GetDefaultImage(image_index), image_index); | 632 user->SetImage(GetDefaultImage(image_index), image_index); |
| 638 } else if (image_index == User::kExternalImageIndex || | 633 } else if (image_index == User::kExternalImageIndex || |
| 639 image_index == User::kProfileImageIndex) { | 634 image_index == User::kProfileImageIndex) { |
| 640 // Path may be empty for profile images (meaning that the image | 635 // Path may be empty for profile images (meaning that the image |
| 641 // hasn't been downloaded for the first time yet, in which case a | 636 // hasn't been downloaded for the first time yet, in which case a |
| 642 // download will be scheduled for |kProfileImageDownloadDelayMs| | 637 // download will be scheduled for |kProfileImageDownloadDelayMs| |
| 643 // after user logs in). | 638 // after user logs in). |
| 644 DCHECK(!image_path.empty() || | 639 DCHECK(!image_path.empty() || |
| 645 image_index == User::kProfileImageIndex); | 640 image_index == User::kProfileImageIndex); |
| 646 // Until image has been loaded, use a gray avatar. | 641 // Until image has been loaded, use the stub image (gray avatar). |
| 647 user->SetImage(*ResourceBundle::GetSharedInstance(). | 642 user->SetStubImage(image_index); |
| 648 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING), | |
| 649 image_index); | |
| 650 if (!image_path.empty()) { | 643 if (!image_path.empty()) { |
| 651 // Load user image asynchronously. | 644 // Load user image asynchronously. |
| 652 image_loader_->Start( | 645 image_loader_->Start( |
| 653 image_path, 0, | 646 image_path, 0, |
| 654 base::Bind(&UserManager::SetUserImage, | 647 base::Bind(&UserManager::SetUserImage, |
| 655 base::Unretained(this), email, image_index)); | 648 base::Unretained(this), email, image_index)); |
| 656 } | 649 } |
| 657 } else { | 650 } else { |
| 658 NOTREACHED(); | 651 NOTREACHED(); |
| 659 } | 652 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 int image_index, | 717 int image_index, |
| 725 const SkBitmap& image) { | 718 const SkBitmap& image) { |
| 726 User* user = const_cast<User*>(FindUser(username)); | 719 User* user = const_cast<User*>(FindUser(username)); |
| 727 // User may have been removed by now. | 720 // User may have been removed by now. |
| 728 if (user) { | 721 if (user) { |
| 729 // For existing users, a valid image index should have been set upon loading | 722 // For existing users, a valid image index should have been set upon loading |
| 730 // them from Local State. | 723 // them from Local State. |
| 731 DCHECK(user->image_index() != User::kInvalidImageIndex || | 724 DCHECK(user->image_index() != User::kInvalidImageIndex || |
| 732 current_user_is_new_); | 725 current_user_is_new_); |
| 733 bool image_changed = user->image_index() != User::kInvalidImageIndex; | 726 bool image_changed = user->image_index() != User::kInvalidImageIndex; |
| 734 user->SetImage(image, image_index); | 727 if (!image.empty()) |
| 735 // If it is the profile image of the current user, save it to | 728 user->SetImage(image, image_index); |
| 736 // |downloaded_profile_image_| so that it can be reused if the started | 729 else |
| 737 // download attempt fails. | 730 user->SetStubImage(image_index); |
| 738 if (image_index == User::kProfileImageIndex && user == logged_in_user_) { | 731 // For the logged-in user with a profile picture, initialize |
| 739 downloaded_profile_image_ = image; | 732 // |downloaded_profile_picture_|. |
| 740 downloaded_profile_image_data_url_ = web_ui_util::GetImageDataUrl(image); | 733 if (user == logged_in_user_ && image_index == User::kProfileImageIndex) |
| 741 } | 734 InitDownloadedProfileImage(); |
| 742 if (image_changed) { | 735 if (image_changed) { |
| 743 // Unless this is first-time setting with |SetInitialUserImage|, | 736 // Unless this is first-time setting with |SetInitialUserImage|, |
| 744 // send a notification about image change. | 737 // send a notification about image change. |
| 745 content::NotificationService::current()->Notify( | 738 content::NotificationService::current()->Notify( |
| 746 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 739 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
| 747 content::Source<UserManager>(this), | 740 content::Source<UserManager>(this), |
| 748 content::Details<const User>(user)); | 741 content::Details<const User>(user)); |
| 749 } | 742 } |
| 750 } | 743 } |
| 751 } | 744 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 base::DictionaryValue* image_properties = new base::DictionaryValue(); | 812 base::DictionaryValue* image_properties = new base::DictionaryValue(); |
| 820 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); | 813 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); |
| 821 image_properties->Set(kImageIndexNodeName, | 814 image_properties->Set(kImageIndexNodeName, |
| 822 new base::FundamentalValue(image_index)); | 815 new base::FundamentalValue(image_index)); |
| 823 images_update->SetWithoutPathExpansion(username, image_properties); | 816 images_update->SetWithoutPathExpansion(username, image_properties); |
| 824 DVLOG(1) << "Saving path to user image in Local State."; | 817 DVLOG(1) << "Saving path to user image in Local State."; |
| 825 | 818 |
| 826 NotifyLocalStateChanged(); | 819 NotifyLocalStateChanged(); |
| 827 } | 820 } |
| 828 | 821 |
| 822 void UserManager::InitDownloadedProfileImage() { |
| 823 DCHECK(logged_in_user_); |
| 824 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { |
| 825 VLOG(1) << "Profile image initialized"; |
| 826 downloaded_profile_image_ = logged_in_user_->image(); |
| 827 downloaded_profile_image_data_url_ = |
| 828 web_ui_util::GetImageDataUrl(downloaded_profile_image_); |
| 829 } |
| 830 } |
| 831 |
| 829 void UserManager::DeleteUserImage(const FilePath& image_path) { | 832 void UserManager::DeleteUserImage(const FilePath& image_path) { |
| 830 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 831 if (!file_util::Delete(image_path, false)) { | 834 if (!file_util::Delete(image_path, false)) { |
| 832 LOG(ERROR) << "Failed to remove user image."; | 835 LOG(ERROR) << "Failed to remove user image."; |
| 833 return; | 836 return; |
| 834 } | 837 } |
| 835 } | 838 } |
| 836 | 839 |
| 837 void UserManager::UpdateOwnership(bool is_owner) { | 840 void UserManager::UpdateOwnership(bool is_owner) { |
| 838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 return ProfileManager::GetDefaultProfile(); | 877 return ProfileManager::GetDefaultProfile(); |
| 875 } | 878 } |
| 876 | 879 |
| 877 std::string UserManager::GetCachedPictureURL() const { | 880 std::string UserManager::GetCachedPictureURL() const { |
| 878 // Currently the profile picture URL is not cached on ChromeOS. | 881 // Currently the profile picture URL is not cached on ChromeOS. |
| 879 return std::string(); | 882 return std::string(); |
| 880 } | 883 } |
| 881 | 884 |
| 882 void UserManager::OnDownloadComplete(ProfileDownloader* downloader, | 885 void UserManager::OnDownloadComplete(ProfileDownloader* downloader, |
| 883 bool success) { | 886 bool success) { |
| 887 // Make sure that |ProfileDownloader| gets deleted after return. |
| 888 scoped_ptr<ProfileDownloader> profile_image_downloader( |
| 889 profile_image_downloader_.release()); |
| 890 DCHECK(profile_image_downloader.get() == downloader); |
| 891 |
| 884 ProfileDownloadResult result; | 892 ProfileDownloadResult result; |
| 885 std::string time_histogram_name; | 893 std::string time_histogram_name; |
| 886 if (!success) { | 894 if (!success) { |
| 887 result = kDownloadFailure; | 895 result = kDownloadFailure; |
| 888 time_histogram_name = kProfileDownloadFailureTime; | 896 time_histogram_name = kProfileDownloadFailureTime; |
| 889 } else if (downloader->GetProfilePicture().isNull()) { | 897 } else if (downloader->GetProfilePicture().isNull()) { |
| 890 result = kDownloadDefault; | 898 result = kDownloadDefault; |
| 891 time_histogram_name = kProfileDownloadDefaultTime; | 899 time_histogram_name = kProfileDownloadDefaultTime; |
| 892 } else { | 900 } else { |
| 893 result = kDownloadSuccess; | 901 result = kDownloadSuccess; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 content::NotificationService::current()->Notify( | 936 content::NotificationService::current()->Notify( |
| 929 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | 937 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, |
| 930 content::Source<UserManager>(this), | 938 content::Source<UserManager>(this), |
| 931 content::Details<const SkBitmap>(&downloaded_profile_image_)); | 939 content::Details<const SkBitmap>(&downloaded_profile_image_)); |
| 932 } else { | 940 } else { |
| 933 content::NotificationService::current()->Notify( | 941 content::NotificationService::current()->Notify( |
| 934 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | 942 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, |
| 935 content::Source<UserManager>(this), | 943 content::Source<UserManager>(this), |
| 936 content::NotificationService::NoDetails()); | 944 content::NotificationService::NoDetails()); |
| 937 } | 945 } |
| 938 | |
| 939 profile_image_downloader_.reset(); | |
| 940 } | 946 } |
| 941 | 947 |
| 942 User* UserManager::CreateUser(const std::string& email) const { | 948 User* UserManager::CreateUser(const std::string& email) const { |
| 943 User* user = new User(email); | 949 User* user = new User(email); |
| 944 user->set_oauth_token_status(LoadUserOAuthStatus(email)); | 950 user->set_oauth_token_status(LoadUserOAuthStatus(email)); |
| 945 // Used to determine whether user's display name is unique. | 951 // Used to determine whether user's display name is unique. |
| 946 ++display_name_count_[user->GetDisplayName()]; | 952 ++display_name_count_[user->GetDisplayName()]; |
| 947 return user; | 953 return user; |
| 948 } | 954 } |
| 949 | 955 |
| 950 } // namespace chromeos | 956 } // namespace chromeos |
| OLD | NEW |