| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "chrome/browser/chromeos/login/user.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/chromeos/login/default_user_images.h" | 8 #include "chrome/browser/chromeos/login/default_user_images.h" |
| 9 #include "chrome/browser/chromeos/login/user_manager.h" | 9 #include "chrome/browser/chromeos/login/user_manager.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 if (i == 0 || i == std::string::npos) { | 23 if (i == 0 || i == std::string::npos) { |
| 24 return email; | 24 return email; |
| 25 } | 25 } |
| 26 return email.substr(0, i); | 26 return email.substr(0, i); |
| 27 } | 27 } |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 User::User(const std::string& email, bool is_guest) | 31 User::User(const std::string& email, bool is_guest) |
| 32 : email_(email), | 32 : email_(email), |
| 33 image_(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 33 user_image_(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 34 kDefaultImageResources[0])), | 34 kDefaultImageResources[0])), |
| 35 oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), | 35 oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), |
| 36 image_index_(kInvalidImageIndex), | 36 image_index_(kInvalidImageIndex), |
| 37 image_is_stub_(false), | 37 image_is_stub_(false), |
| 38 is_guest_(is_guest) { | 38 is_guest_(is_guest) { |
| 39 // The email address of a demo user is for internal purposes only, | 39 // The email address of a demo user is for internal purposes only, |
| 40 // never meant for display. | 40 // never meant for display. |
| 41 if (email != kDemoUser) { | 41 if (email != kDemoUser) { |
| 42 display_email_ = email; | 42 display_email_ = email; |
| 43 is_demo_user_ = false; | 43 is_demo_user_ = false; |
| 44 } else { | 44 } else { |
| 45 is_demo_user_ = true; | 45 is_demo_user_ = true; |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 User::~User() {} | 49 User::~User() {} |
| 50 | 50 |
| 51 void User::SetImage(const gfx::ImageSkia& image, int image_index) { | 51 void User::SetImage(const UserImage& user_image, int image_index) { |
| 52 image_ = image; | 52 user_image_ = user_image; |
| 53 image_index_ = image_index; | 53 image_index_ = image_index; |
| 54 image_is_stub_ = false; | 54 image_is_stub_ = false; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void User::SetStubImage(int image_index) { | 57 void User::SetStubImage(int image_index) { |
| 58 image_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 58 user_image_.SetImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 59 kStubImageResourceID); | 59 kStubImageResourceID)); |
| 60 image_index_ = image_index; | 60 image_index_ = image_index; |
| 61 image_is_stub_ = true; | 61 image_is_stub_ = true; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void User::SetWallpaperThumbnail(const SkBitmap& wallpaper_thumbnail) { | 64 void User::SetWallpaperThumbnail(const SkBitmap& wallpaper_thumbnail) { |
| 65 wallpaper_thumbnail_ = wallpaper_thumbnail; | 65 wallpaper_thumbnail_ = wallpaper_thumbnail; |
| 66 } | 66 } |
| 67 | 67 |
| 68 std::string User::GetAccountName() const { | 68 std::string User::GetAccountName() const { |
| 69 return GetUserName(email_); | 69 return GetUserName(email_); |
| 70 } | 70 } |
| 71 | 71 |
| 72 std::string User::GetDisplayName() const { | 72 std::string User::GetDisplayName() const { |
| 73 return GetUserName(display_email_); | 73 return GetUserName(display_email_); |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool User::NeedsNameTooltip() const { | 76 bool User::NeedsNameTooltip() const { |
| 77 return !UserManager::Get()->IsDisplayNameUnique(GetDisplayName()); | 77 return !UserManager::Get()->IsDisplayNameUnique(GetDisplayName()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool User::GetAnimatedImage(UserImage::RawImage* raw_image) const { |
| 81 if (raw_image && has_animated_image()) { |
| 82 *raw_image = user_image_.raw_image(); |
| 83 return true; |
| 84 } |
| 85 return false; |
| 86 } |
| 87 |
| 80 std::string User::GetNameTooltip() const { | 88 std::string User::GetNameTooltip() const { |
| 81 const std::string& user_email = display_email_; | 89 const std::string& user_email = display_email_; |
| 82 size_t at_pos = user_email.rfind('@'); | 90 size_t at_pos = user_email.rfind('@'); |
| 83 if (at_pos == std::string::npos) { | 91 if (at_pos == std::string::npos) { |
| 84 NOTREACHED(); | 92 NOTREACHED(); |
| 85 return std::string(); | 93 return std::string(); |
| 86 } | 94 } |
| 87 size_t domain_start = at_pos + 1; | 95 size_t domain_start = at_pos + 1; |
| 88 std::string domain = user_email.substr(domain_start, | 96 std::string domain = user_email.substr(domain_start, |
| 89 user_email.length() - domain_start); | 97 user_email.length() - domain_start); |
| 90 return base::StringPrintf("%s (%s)", | 98 return base::StringPrintf("%s (%s)", |
| 91 GetDisplayName().c_str(), | 99 GetDisplayName().c_str(), |
| 92 domain.c_str()); | 100 domain.c_str()); |
| 93 } | 101 } |
| 94 | 102 |
| 95 } // namespace chromeos | 103 } // namespace chromeos |
| OLD | NEW |