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 "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/chromeos/login/default_user_images.h" | 9 #include "chrome/browser/chromeos/login/default_user_images.h" |
10 #include "chrome/browser/chromeos/login/user_manager.h" | 10 #include "chrome/browser/chromeos/login/user_manager.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 if (!is_demo_user()) | 40 if (!is_demo_user()) |
41 display_email_ = email; | 41 display_email_ = email; |
42 } | 42 } |
43 | 43 |
44 User::~User() {} | 44 User::~User() {} |
45 | 45 |
46 void User::SetImage(const UserImage& user_image, int image_index) { | 46 void User::SetImage(const UserImage& user_image, int image_index) { |
47 user_image_ = user_image; | 47 user_image_ = user_image; |
48 image_index_ = image_index; | 48 image_index_ = image_index; |
49 image_is_stub_ = false; | 49 image_is_stub_ = false; |
| 50 DCHECK(HasDefaultImage() || user_image.has_raw_image()); |
50 } | 51 } |
51 | 52 |
52 void User::SetImageURL(const GURL& image_url) { | 53 void User::SetImageURL(const GURL& image_url) { |
53 user_image_.set_url(image_url); | 54 user_image_.set_url(image_url); |
54 } | 55 } |
55 | 56 |
56 void User::SetStubImage(int image_index) { | 57 void User::SetStubImage(int image_index) { |
57 user_image_ = UserImage(); | 58 user_image_ = UserImage(); |
58 image_index_ = image_index; | 59 image_index_ = image_index; |
59 image_is_stub_ = true; | 60 image_is_stub_ = true; |
60 } | 61 } |
61 | 62 |
62 void User::SetWallpaperThumbnail(const SkBitmap& wallpaper_thumbnail) { | 63 void User::SetWallpaperThumbnail(const SkBitmap& wallpaper_thumbnail) { |
63 wallpaper_thumbnail_ = wallpaper_thumbnail; | 64 wallpaper_thumbnail_ = wallpaper_thumbnail; |
64 } | 65 } |
65 | 66 |
66 std::string User::GetAccountName(bool use_display_email) const { | 67 std::string User::GetAccountName(bool use_display_email) const { |
67 if (use_display_email && !display_email_.empty()) | 68 if (use_display_email && !display_email_.empty()) |
68 return GetUserName(display_email_); | 69 return GetUserName(display_email_); |
69 else | 70 else |
70 return GetUserName(email_); | 71 return GetUserName(email_); |
71 } | 72 } |
72 | 73 |
| 74 bool User::HasDefaultImage() const { |
| 75 return image_index_ >= 0 && image_index_ < kDefaultImagesCount; |
| 76 } |
| 77 |
73 string16 User::GetDisplayName() const { | 78 string16 User::GetDisplayName() const { |
74 // Fallback to the email account name in case display name haven't been set. | 79 // Fallback to the email account name in case display name haven't been set. |
75 return display_name_.empty() ? | 80 return display_name_.empty() ? |
76 UTF8ToUTF16(GetAccountName(true)) : | 81 UTF8ToUTF16(GetAccountName(true)) : |
77 display_name_; | 82 display_name_; |
78 } | 83 } |
79 | 84 |
80 } // namespace chromeos | 85 } // namespace chromeos |
OLD | NEW |