| 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 11 matching lines...) Expand all Loading... |
| 22 std::string GetUserName(const std::string& email) { | 22 std::string GetUserName(const std::string& email) { |
| 23 std::string::size_type i = email.find('@'); | 23 std::string::size_type i = email.find('@'); |
| 24 if (i == 0 || i == std::string::npos) { | 24 if (i == 0 || i == std::string::npos) { |
| 25 return email; | 25 return email; |
| 26 } | 26 } |
| 27 return email.substr(0, i); | 27 return email.substr(0, i); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 User::User(const std::string& email, bool is_guest) | 32 // The demo user is represented by a domainless username. |
| 33 const char kDemoUser[] = "demouser"; |
| 34 // Incognito user is represented by an empty string (since some code already |
| 35 // depends on that and it's hard to figure out what). |
| 36 const char kGuestUser[] = ""; |
| 37 |
| 38 User::User(const std::string& email) |
| 33 : email_(email), | 39 : email_(email), |
| 34 user_image_(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 40 user_image_(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 35 kDefaultImageResources[0])), | 41 kDefaultImageResources[0])), |
| 36 oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), | 42 oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), |
| 37 image_index_(kInvalidImageIndex), | 43 image_index_(kInvalidImageIndex), |
| 38 image_is_stub_(false), | 44 image_is_stub_(false) { |
| 39 is_guest_(is_guest) { | |
| 40 // The email address of a demo user is for internal purposes only, | 45 // The email address of a demo user is for internal purposes only, |
| 41 // never meant for display. | 46 // never meant for display. |
| 42 if (email != kDemoUser) { | 47 if (!is_demo_user()) |
| 43 display_email_ = email; | 48 display_email_ = email; |
| 44 is_demo_user_ = false; | |
| 45 } else { | |
| 46 is_demo_user_ = true; | |
| 47 } | |
| 48 } | 49 } |
| 49 | 50 |
| 50 User::~User() {} | 51 User::~User() {} |
| 51 | 52 |
| 52 void User::SetImage(const UserImage& user_image, int image_index) { | 53 void User::SetImage(const UserImage& user_image, int image_index) { |
| 53 user_image_ = user_image; | 54 user_image_ = user_image; |
| 54 image_index_ = image_index; | 55 image_index_ = image_index; |
| 55 image_is_stub_ = false; | 56 image_is_stub_ = false; |
| 56 } | 57 } |
| 57 | 58 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 78 } | 79 } |
| 79 | 80 |
| 80 string16 User::GetDisplayName() const { | 81 string16 User::GetDisplayName() const { |
| 81 // Fallback to the email account name in case display name haven't been set. | 82 // Fallback to the email account name in case display name haven't been set. |
| 82 return display_name_.empty() ? | 83 return display_name_.empty() ? |
| 83 UTF8ToUTF16(GetAccountName(true)) : | 84 UTF8ToUTF16(GetAccountName(true)) : |
| 84 display_name_; | 85 display_name_; |
| 85 } | 86 } |
| 86 | 87 |
| 87 } // namespace chromeos | 88 } // namespace chromeos |
| OLD | NEW |