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

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

Issue 1425093004: Revert of This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Created 5 years, 1 month 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
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/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
11 #include "components/signin/core/account_id/account_id.h"
12 #include "components/user_manager/user_image/default_user_images.h" 11 #include "components/user_manager/user_image/default_user_images.h"
13 #include "components/user_manager/user_manager.h" 12 #include "components/user_manager/user_manager.h"
14 #include "grit/theme_resources.h" 13 #include "grit/theme_resources.h"
15 #include "grit/ui_chromeos_resources.h" 14 #include "grit/ui_chromeos_resources.h"
16 #include "net/base/escape.h" 15 #include "net/base/escape.h"
17 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/codec/png_codec.h" 17 #include "ui/gfx/codec/png_codec.h"
19 #include "url/third_party/mozilla/url_parse.h" 18 #include "url/third_party/mozilla/url_parse.h"
20 19
21 namespace { 20 namespace {
22 21
23 // Parses the user image URL, which looks like 22 // Parses the user image URL, which looks like
24 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n", 23 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n",
25 // to user email. 24 // to user email.
26 void ParseRequest(const GURL& url, 25 void ParseRequest(const GURL& url,
27 std::string* email) { 26 std::string* email) {
28 DCHECK(url.is_valid()); 27 DCHECK(url.is_valid());
29 *email = net::UnescapeURLComponent(url.path().substr(1), 28 *email = net::UnescapeURLComponent(url.path().substr(1),
30 (net::UnescapeRule::URL_SPECIAL_CHARS | 29 (net::UnescapeRule::URL_SPECIAL_CHARS |
31 net::UnescapeRule::SPACES)); 30 net::UnescapeRule::SPACES));
32 } 31 }
33 32
34 } // namespace 33 } // namespace
35 34
36 namespace chromeos { 35 namespace chromeos {
37 namespace options { 36 namespace options {
38 37
39 // Static. 38 // Static.
40 base::RefCountedMemory* UserImageSource::GetUserImage( 39 base::RefCountedMemory* UserImageSource::GetUserImage(
41 const AccountId& account_id, 40 const std::string& email,
42 ui::ScaleFactor scale_factor) { 41 ui::ScaleFactor scale_factor) {
43 const user_manager::User* user = 42 const user_manager::User* user =
44 user_manager::UserManager::Get()->FindUser(account_id); 43 user_manager::UserManager::Get()->FindUser(email);
45 if (user) { 44 if (user) {
46 if (user->has_raw_image()) { 45 if (user->has_raw_image()) {
47 return new base::RefCountedBytes(user->raw_image()); 46 return new base::RefCountedBytes(user->raw_image());
48 } else if (user->image_is_stub()) { 47 } else if (user->image_is_stub()) {
49 return ResourceBundle::GetSharedInstance(). 48 return ResourceBundle::GetSharedInstance().
50 LoadDataResourceBytesForScale(IDR_PROFILE_PICTURE_LOADING, 49 LoadDataResourceBytesForScale(IDR_PROFILE_PICTURE_LOADING,
51 scale_factor); 50 scale_factor);
52 } else if (user->HasDefaultImage()) { 51 } else if (user->HasDefaultImage()) {
53 return ResourceBundle::GetSharedInstance(). 52 return ResourceBundle::GetSharedInstance().
54 LoadDataResourceBytesForScale( 53 LoadDataResourceBytesForScale(
(...skipping 17 matching lines...) Expand all
72 } 71 }
73 72
74 void UserImageSource::StartDataRequest( 73 void UserImageSource::StartDataRequest(
75 const std::string& path, 74 const std::string& path,
76 int render_process_id, 75 int render_process_id,
77 int render_frame_id, 76 int render_frame_id,
78 const content::URLDataSource::GotDataCallback& callback) { 77 const content::URLDataSource::GotDataCallback& callback) {
79 std::string email; 78 std::string email;
80 GURL url(chrome::kChromeUIUserImageURL + path); 79 GURL url(chrome::kChromeUIUserImageURL + path);
81 ParseRequest(url, &email); 80 ParseRequest(url, &email);
82 const AccountId account_id(AccountId::FromUserEmail(email)); 81 callback.Run(GetUserImage(email, ui::SCALE_FACTOR_100P));
83 callback.Run(GetUserImage(account_id, ui::SCALE_FACTOR_100P));
84 } 82 }
85 83
86 std::string UserImageSource::GetMimeType(const std::string& path) const { 84 std::string UserImageSource::GetMimeType(const std::string& path) const {
87 // We need to explicitly return a mime type, otherwise if the user tries to 85 // We need to explicitly return a mime type, otherwise if the user tries to
88 // drag the image they get no extension. 86 // drag the image they get no extension.
89 return "image/png"; 87 return "image/png";
90 } 88 }
91 89
92 } // namespace options 90 } // namespace options
93 } // namespace chromeos 91 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/user_image_source.h ('k') | chromeos/login/auth/cryptohome_authenticator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698