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

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

Issue 10831064: [cros] Remove redundant PNG enconding in UserImage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months 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
OLDNEW
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"
11 #include "grit/theme_resources.h"
12 #include "ui/base/resource/resource_bundle.h"
13 11
14 namespace chromeos { 12 namespace chromeos {
15 13
16 namespace { 14 namespace {
17 15
18 // Resource ID of the image to use as stub image.
19 const int kStubImageResourceID = IDR_PROFILE_PICTURE_LOADING;
20
21 // Returns account name portion of an email. 16 // Returns account name portion of an email.
22 std::string GetUserName(const std::string& email) { 17 std::string GetUserName(const std::string& email) {
23 std::string::size_type i = email.find('@'); 18 std::string::size_type i = email.find('@');
24 if (i == 0 || i == std::string::npos) { 19 if (i == 0 || i == std::string::npos) {
25 return email; 20 return email;
26 } 21 }
27 return email.substr(0, i); 22 return email.substr(0, i);
28 } 23 }
29 24
30 } // namespace 25 } // namespace
31 26
32 // The demo user is represented by a domainless username. 27 // The demo user is represented by a domainless username.
33 const char kDemoUser[] = "demouser"; 28 const char kDemoUser[] = "demouser";
34 // Incognito user is represented by an empty string (since some code already 29 // Incognito user is represented by an empty string (since some code already
35 // depends on that and it's hard to figure out what). 30 // depends on that and it's hard to figure out what).
36 const char kGuestUser[] = ""; 31 const char kGuestUser[] = "";
37 32
38 User::User(const std::string& email) 33 User::User(const std::string& email)
39 : email_(email), 34 : email_(email),
40 user_image_(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
41 kDefaultImageResources[0])),
42 oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), 35 oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN),
43 image_index_(kInvalidImageIndex), 36 image_index_(kInvalidImageIndex),
44 image_is_stub_(false) { 37 image_is_stub_(false) {
45 // The email address of a demo user is for internal purposes only, 38 // The email address of a demo user is for internal purposes only,
46 // never meant for display. 39 // never meant for display.
47 if (!is_demo_user()) 40 if (!is_demo_user())
48 display_email_ = email; 41 display_email_ = email;
49 } 42 }
50 43
51 User::~User() {} 44 User::~User() {}
52 45
53 void User::SetImage(const UserImage& user_image, int image_index) { 46 void User::SetImage(const UserImage& user_image, int image_index) {
54 user_image_ = user_image; 47 user_image_ = user_image;
55 image_index_ = image_index; 48 image_index_ = image_index;
56 image_is_stub_ = false; 49 image_is_stub_ = false;
57 } 50 }
58 51
59 void User::SetImageURL(const GURL& image_url) { 52 void User::SetImageURL(const GURL& image_url) {
60 user_image_.set_url(image_url); 53 user_image_.set_url(image_url);
61 } 54 }
62 55
63 void User::SetStubImage(int image_index) { 56 void User::SetStubImage(int image_index) {
64 user_image_.SetImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 57 user_image_ = UserImage();
65 kStubImageResourceID));
66 image_index_ = image_index; 58 image_index_ = image_index;
67 image_is_stub_ = true; 59 image_is_stub_ = true;
68 } 60 }
69 61
70 void User::SetWallpaperThumbnail(const SkBitmap& wallpaper_thumbnail) { 62 void User::SetWallpaperThumbnail(const SkBitmap& wallpaper_thumbnail) {
71 wallpaper_thumbnail_ = wallpaper_thumbnail; 63 wallpaper_thumbnail_ = wallpaper_thumbnail;
72 } 64 }
73 65
74 std::string User::GetAccountName(bool use_display_email) const { 66 std::string User::GetAccountName(bool use_display_email) const {
75 if (use_display_email && !display_email_.empty()) 67 if (use_display_email && !display_email_.empty())
76 return GetUserName(display_email_); 68 return GetUserName(display_email_);
77 else 69 else
78 return GetUserName(email_); 70 return GetUserName(email_);
79 } 71 }
80 72
81 string16 User::GetDisplayName() const { 73 string16 User::GetDisplayName() const {
82 // Fallback to the email account name in case display name haven't been set. 74 // Fallback to the email account name in case display name haven't been set.
83 return display_name_.empty() ? 75 return display_name_.empty() ?
84 UTF8ToUTF16(GetAccountName(true)) : 76 UTF8ToUTF16(GetAccountName(true)) :
85 display_name_; 77 display_name_;
86 } 78 }
87 79
88 } // namespace chromeos 80 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698