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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/user_image_source.cc

Issue 2517053004: Use base::RefCountedBytes in user_manager::UserImage (Closed)
Patch Set: remove unnecessary base::move Created 4 years 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
« no previous file with comments | « chrome/browser/ui/webui/chromeos/image_source.cc ('k') | components/user_manager/user.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ui/webui/options/chromeos/user_image_source.h" 5 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h"
6 6
7 #include "base/memory/ref_counted_memory.h" 7 #include "base/memory/ref_counted_memory.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "chrome/browser/chromeos/login/users/default_user_image/default_user_im ages.h" 10 #include "chrome/browser/chromeos/login/users/default_user_image/default_user_im ages.h"
(...skipping 25 matching lines...) Expand all
36 // TODO(alemate): DCHECK(status) - should happen after options page is 36 // TODO(alemate): DCHECK(status) - should happen after options page is
37 // migrated. 37 // migrated.
38 if (!status) { 38 if (!status) {
39 LOG(WARNING) << "Failed to deserialize account_id."; 39 LOG(WARNING) << "Failed to deserialize account_id.";
40 account_id = user_manager::known_user::GetAccountId( 40 account_id = user_manager::known_user::GetAccountId(
41 serialized_account_id, std::string() /* gaia_id */); 41 serialized_account_id, std::string() /* gaia_id */);
42 } 42 }
43 *email = account_id.GetUserEmail(); 43 *email = account_id.GetUserEmail();
44 } 44 }
45 45
46 base::RefCountedMemory* GetUserImageInternal(const AccountId& account_id) { 46 scoped_refptr<base::RefCountedMemory> GetUserImageInternal(
47 const AccountId& account_id) {
47 const user_manager::User* user = 48 const user_manager::User* user =
48 user_manager::UserManager::Get()->FindUser(account_id); 49 user_manager::UserManager::Get()->FindUser(account_id);
49 50
50 // Always use the 100% scaling. These source images are 256x256, and are 51 // Always use the 100% scaling. These source images are 256x256, and are
51 // downscaled to ~64x64 for use in WebUI pages. Therefore, they are big enough 52 // downscaled to ~64x64 for use in WebUI pages. Therefore, they are big enough
52 // for device scale factors up to 4. We do not use SCALE_FACTOR_NONE, as we 53 // for device scale factors up to 4. We do not use SCALE_FACTOR_NONE, as we
53 // specifically want 100% scale images to not transmit more data than needed. 54 // specifically want 100% scale images to not transmit more data than needed.
54 if (user) { 55 if (user) {
55 if (user->has_image_bytes()) 56 if (user->has_image_bytes())
56 return new base::RefCountedBytes(user->image_bytes()); 57 return user->image_bytes();
57 if (user->image_is_stub()) { 58 if (user->image_is_stub()) {
58 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 59 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
59 IDR_PROFILE_PICTURE_LOADING, ui::SCALE_FACTOR_100P); 60 IDR_PROFILE_PICTURE_LOADING, ui::SCALE_FACTOR_100P);
60 } 61 }
61 if (user->HasDefaultImage()) { 62 if (user->HasDefaultImage()) {
62 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 63 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
63 chromeos::default_user_image::kDefaultImageResourceIDs 64 chromeos::default_user_image::kDefaultImageResourceIDs
64 [user->image_index()], 65 [user->image_index()],
65 ui::SCALE_FACTOR_100P); 66 ui::SCALE_FACTOR_100P);
66 } 67 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 103 }
103 104
104 std::string UserImageSource::GetMimeType(const std::string& path) const { 105 std::string UserImageSource::GetMimeType(const std::string& path) const {
105 // We need to explicitly return a mime type, otherwise if the user tries to 106 // We need to explicitly return a mime type, otherwise if the user tries to
106 // drag the image they get no extension. 107 // drag the image they get no extension.
107 return "image/png"; 108 return "image/png";
108 } 109 }
109 110
110 } // namespace options 111 } // namespace options
111 } // namespace chromeos 112 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chromeos/image_source.cc ('k') | components/user_manager/user.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698