Chromium Code Reviews| 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_image.h" | |
| 9 #include "chrome/browser/chromeos/login/user_manager.h" | 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| 10 #include "grit/theme_resources.h" | 11 #include "grit/theme_resources.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 12 | 13 |
| 13 namespace chromeos { | 14 namespace chromeos { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // Resource ID of the image to use as stub image. | 18 // Resource ID of the image to use as stub image. |
| 18 const int kStubImageResourceID = IDR_PROFILE_PICTURE_LOADING; | 19 const int kStubImageResourceID = IDR_PROFILE_PICTURE_LOADING; |
| 19 | 20 |
| 20 // Returns account name portion of an email. | 21 // Returns account name portion of an email. |
| 21 std::string GetUserName(const std::string& email) { | 22 std::string GetUserName(const std::string& email) { |
| 22 std::string::size_type i = email.find('@'); | 23 std::string::size_type i = email.find('@'); |
| 23 if (i == 0 || i == std::string::npos) { | 24 if (i == 0 || i == std::string::npos) { |
| 24 return email; | 25 return email; |
| 25 } | 26 } |
| 26 return email.substr(0, i); | 27 return email.substr(0, i); |
| 27 } | 28 } |
| 28 | 29 |
| 30 bool IsGIFImage(const std::vector<unsigned char>& data) { | |
|
Ivan Korotkov
2012/05/29 10:50:23
Feels like this should part of UserImage.
ygorshenin1
2012/05/30 12:17:34
Done.
| |
| 31 const char* kGIFStamp = "GIF"; | |
|
Ivan Korotkov
2012/05/29 10:50:23
Better: static const char kGIFStamp[] = "GIF";
the
ygorshenin1
2012/05/30 12:17:34
Done.
| |
| 32 const size_t gif_stamp_len = strlen(kGIFStamp); | |
| 33 | |
| 34 if (data.size() >= gif_stamp_len && | |
| 35 memcmp(&data[0], kGIFStamp, gif_stamp_len) == 0) { | |
| 36 return true; | |
| 37 } | |
| 38 return false; | |
| 39 } | |
| 40 | |
| 29 } // namespace | 41 } // namespace |
| 30 | 42 |
| 31 User::User(const std::string& email, bool is_guest) | 43 User::User(const std::string& email, bool is_guest) |
| 32 : email_(email), | 44 : email_(email), |
| 45 has_gif_image_(false), | |
| 33 oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), | 46 oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), |
| 34 image_index_(kInvalidImageIndex), | 47 image_index_(kInvalidImageIndex), |
| 35 image_is_stub_(false), | 48 image_is_stub_(false), |
| 36 is_guest_(is_guest) { | 49 is_guest_(is_guest) { |
| 37 // The email address of a demo user is for internal purposes only, | 50 // The email address of a demo user is for internal purposes only, |
| 38 // never meant for display. | 51 // never meant for display. |
| 39 if (email != kDemoUser) { | 52 if (email != kDemoUser) { |
| 40 display_email_ = email; | 53 display_email_ = email; |
| 41 is_demo_user_ = false; | 54 is_demo_user_ = false; |
| 42 } else { | 55 } else { |
| 43 is_demo_user_ = true; | 56 is_demo_user_ = true; |
| 44 } | 57 } |
| 45 image_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( | 58 image_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 46 kDefaultImageResources[0]); | 59 kDefaultImageResources[0]); |
| 47 } | 60 } |
| 48 | 61 |
| 49 User::~User() {} | 62 User::~User() {} |
| 50 | 63 |
| 51 void User::SetImage(const SkBitmap& image, int image_index) { | 64 void User::SetImage(const UserImage& user_image, int image_index) { |
| 52 image_ = image; | 65 image_ = user_image.image(); |
| 53 image_index_ = image_index; | 66 image_index_ = image_index; |
| 54 image_is_stub_ = false; | 67 image_is_stub_ = false; |
| 68 if (user_image.has_raw_image() && IsGIFImage(user_image.raw_image())) { | |
| 69 has_gif_image_ = true; | |
| 70 gif_image_ = user_image.raw_image(); | |
| 71 } else { | |
| 72 has_gif_image_ = false; | |
| 73 std::vector<unsigned char> tmp; | |
| 74 gif_image_.swap(tmp); | |
|
Ivan Korotkov
2012/05/29 10:50:23
Why not vector::clear?
ygorshenin1
2012/05/30 12:17:34
To release buffer allocated by vector. Usually, cl
| |
| 75 } | |
| 55 } | 76 } |
| 56 | 77 |
| 57 void User::SetStubImage(int image_index) { | 78 void User::SetStubImage(int image_index) { |
| 58 image_ = *ResourceBundle::GetSharedInstance(). | 79 image_ = *ResourceBundle::GetSharedInstance(). |
| 59 GetBitmapNamed(kStubImageResourceID); | 80 GetBitmapNamed(kStubImageResourceID); |
| 60 image_index_ = image_index; | 81 image_index_ = image_index; |
| 61 image_is_stub_ = true; | 82 image_is_stub_ = true; |
| 62 } | 83 } |
| 63 | 84 |
| 64 void User::SetWallpaperThumbnail(const SkBitmap& wallpaper_thumbnail) { | 85 void User::SetWallpaperThumbnail(const SkBitmap& wallpaper_thumbnail) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 86 } | 107 } |
| 87 size_t domain_start = at_pos + 1; | 108 size_t domain_start = at_pos + 1; |
| 88 std::string domain = user_email.substr(domain_start, | 109 std::string domain = user_email.substr(domain_start, |
| 89 user_email.length() - domain_start); | 110 user_email.length() - domain_start); |
| 90 return base::StringPrintf("%s (%s)", | 111 return base::StringPrintf("%s (%s)", |
| 91 GetDisplayName().c_str(), | 112 GetDisplayName().c_str(), |
| 92 domain.c_str()); | 113 domain.c_str()); |
| 93 } | 114 } |
| 94 | 115 |
| 95 } // namespace chromeos | 116 } // namespace chromeos |
| OLD | NEW |