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

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

Issue 8698002: [cros] Profile image loaded from file is re-used if subsequent download fails. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | « no previous file | no next file » | 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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 const SkBitmap& image) { 690 const SkBitmap& image) {
691 User* user = const_cast<User*>(FindUser(username)); 691 User* user = const_cast<User*>(FindUser(username));
692 // User may have been removed by now. 692 // User may have been removed by now.
693 if (user) { 693 if (user) {
694 // For existing users, a valid image index should have been set upon loading 694 // For existing users, a valid image index should have been set upon loading
695 // them from Local State. 695 // them from Local State.
696 DCHECK(user->image_index() != User::kInvalidImageIndex || 696 DCHECK(user->image_index() != User::kInvalidImageIndex ||
697 current_user_is_new_); 697 current_user_is_new_);
698 bool image_changed = user->image_index() != User::kInvalidImageIndex; 698 bool image_changed = user->image_index() != User::kInvalidImageIndex;
699 user->SetImage(image, image_index); 699 user->SetImage(image, image_index);
700 // If it is the profile image of the current user, save it to
701 // |downloaded_profile_image_| so that it can be reused if the started
702 // download attempt fails.
703 if (image_index == User::kProfileImageIndex && user == logged_in_user_) {
704 downloaded_profile_image_ = image;
705 downloaded_profile_image_data_url_ = web_ui_util::GetImageDataUrl(image);
706 }
700 if (image_changed) { 707 if (image_changed) {
701 // Unless this is first-time setting with |SetInitialUserImage|, 708 // Unless this is first-time setting with |SetInitialUserImage|,
702 // send a notification about image change. 709 // send a notification about image change.
703 content::NotificationService::current()->Notify( 710 content::NotificationService::current()->Notify(
704 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 711 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
705 content::Source<UserManager>(this), 712 content::Source<UserManager>(this),
706 content::Details<const User>(user)); 713 content::Details<const User>(user));
707 } 714 }
708 } 715 }
709 } 716 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 std::string new_image_data_url = 868 std::string new_image_data_url =
862 web_ui_util::GetImageDataUrl(downloader->GetProfilePicture()); 869 web_ui_util::GetImageDataUrl(downloader->GetProfilePicture());
863 if (!downloaded_profile_image_data_url_.empty() && 870 if (!downloaded_profile_image_data_url_.empty() &&
864 new_image_data_url == downloaded_profile_image_data_url_) 871 new_image_data_url == downloaded_profile_image_data_url_)
865 return; 872 return;
866 873
867 downloaded_profile_image_data_url_ = new_image_data_url; 874 downloaded_profile_image_data_url_ = new_image_data_url;
868 downloaded_profile_image_ = downloader->GetProfilePicture(); 875 downloaded_profile_image_ = downloader->GetProfilePicture();
869 876
870 if (logged_in_user().image_index() == User::kProfileImageIndex) { 877 if (logged_in_user().image_index() == User::kProfileImageIndex) {
871 std::string current_image_data_url =
872 web_ui_util::GetImageDataUrl(logged_in_user().image());
873 if (current_image_data_url == new_image_data_url)
874 return;
875
876 VLOG(1) << "Updating profile image for logged-in user"; 878 VLOG(1) << "Updating profile image for logged-in user";
877 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult", 879 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult",
878 kDownloadSuccessChanged, 880 kDownloadSuccessChanged,
879 kDownloadResultsCount); 881 kDownloadResultsCount);
880 882
881 // This will persist |downloaded_profile_image_| to file. 883 // This will persist |downloaded_profile_image_| to file.
882 SaveUserImageFromProfileImage(logged_in_user().email()); 884 SaveUserImageFromProfileImage(logged_in_user().email());
883 } 885 }
884 } 886 }
885 887
(...skipping 14 matching lines...) Expand all
900 902
901 User* UserManager::CreateUser(const std::string& email) const { 903 User* UserManager::CreateUser(const std::string& email) const {
902 User* user = new User(email); 904 User* user = new User(email);
903 user->set_oauth_token_status(GetUserOAuthStatus(email)); 905 user->set_oauth_token_status(GetUserOAuthStatus(email));
904 // Used to determine whether user's display name is unique. 906 // Used to determine whether user's display name is unique.
905 ++display_name_count_[user->GetDisplayName()]; 907 ++display_name_count_[user->GetDisplayName()];
906 return user; 908 return user;
907 } 909 }
908 910
909 } // namespace chromeos 911 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698