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/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/user_manager.h" | |
11 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
12 #include "components/user_manager/user_image/default_user_images.h" | 11 #include "components/user_manager/user_image/default_user_images.h" |
| 12 #include "components/user_manager/user_manager.h" |
13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
14 #include "grit/ui_chromeos_resources.h" | 14 #include "grit/ui_chromeos_resources.h" |
15 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/gfx/codec/png_codec.h" | 17 #include "ui/gfx/codec/png_codec.h" |
18 #include "url/url_parse.h" | 18 #include "url/url_parse.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Parses the user image URL, which looks like | 22 // Parses the user image URL, which looks like |
23 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n", | 23 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n", |
24 // to user email. | 24 // to user email. |
25 void ParseRequest(const GURL& url, | 25 void ParseRequest(const GURL& url, |
26 std::string* email) { | 26 std::string* email) { |
27 DCHECK(url.is_valid()); | 27 DCHECK(url.is_valid()); |
28 *email = net::UnescapeURLComponent(url.path().substr(1), | 28 *email = net::UnescapeURLComponent(url.path().substr(1), |
29 (net::UnescapeRule::URL_SPECIAL_CHARS | | 29 (net::UnescapeRule::URL_SPECIAL_CHARS | |
30 net::UnescapeRule::SPACES)); | 30 net::UnescapeRule::SPACES)); |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 namespace chromeos { | 35 namespace chromeos { |
36 namespace options { | 36 namespace options { |
37 | 37 |
38 base::RefCountedMemory* UserImageSource::GetUserImage( | 38 base::RefCountedMemory* UserImageSource::GetUserImage( |
39 const std::string& email, | 39 const std::string& email, |
40 ui::ScaleFactor scale_factor) const { | 40 ui::ScaleFactor scale_factor) const { |
41 const user_manager::User* user = | 41 const user_manager::User* user = |
42 chromeos::UserManager::Get()->FindUser(email); | 42 user_manager::UserManager::Get()->FindUser(email); |
43 if (user) { | 43 if (user) { |
44 if (user->has_raw_image()) { | 44 if (user->has_raw_image()) { |
45 return new base::RefCountedBytes(user->raw_image()); | 45 return new base::RefCountedBytes(user->raw_image()); |
46 } else if (user->image_is_stub()) { | 46 } else if (user->image_is_stub()) { |
47 return ResourceBundle::GetSharedInstance(). | 47 return ResourceBundle::GetSharedInstance(). |
48 LoadDataResourceBytesForScale(IDR_PROFILE_PICTURE_LOADING, | 48 LoadDataResourceBytesForScale(IDR_PROFILE_PICTURE_LOADING, |
49 scale_factor); | 49 scale_factor); |
50 } else if (user->HasDefaultImage()) { | 50 } else if (user->HasDefaultImage()) { |
51 return ResourceBundle::GetSharedInstance(). | 51 return ResourceBundle::GetSharedInstance(). |
52 LoadDataResourceBytesForScale( | 52 LoadDataResourceBytesForScale( |
(...skipping 28 matching lines...) Expand all Loading... |
81 } | 81 } |
82 | 82 |
83 std::string UserImageSource::GetMimeType(const std::string& path) const { | 83 std::string UserImageSource::GetMimeType(const std::string& path) const { |
84 // We need to explicitly return a mime type, otherwise if the user tries to | 84 // We need to explicitly return a mime type, otherwise if the user tries to |
85 // drag the image they get no extension. | 85 // drag the image they get no extension. |
86 return "image/png"; | 86 return "image/png"; |
87 } | 87 } |
88 | 88 |
89 } // namespace options | 89 } // namespace options |
90 } // namespace chromeos | 90 } // namespace chromeos |
OLD | NEW |