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/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
11 #include "components/signin/core/account_id/account_id.h" | 11 #include "components/signin/core/account_id/account_id.h" |
12 #include "components/user_manager/user_image/default_user_images.h" | 12 #include "components/user_manager/user_image/default_user_images.h" |
13 #include "components/user_manager/user_manager.h" | 13 #include "components/user_manager/user_manager.h" |
14 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
15 #include "grit/ui_chromeos_resources.h" | 15 #include "grit/ui_chromeos_resources.h" |
16 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
19 #include "url/third_party/mozilla/url_parse.h" | 19 #include "url/third_party/mozilla/url_parse.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Parses the user image URL, which looks like | 23 // Parses the user image URL, which looks like |
24 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n", | 24 // "chrome://userimage/serialized-user-id?key1=value1&...&key_n=value_n", |
25 // to user email. | 25 // to user email. |
26 void ParseRequest(const GURL& url, | 26 void ParseRequest(const GURL& url, |
27 std::string* email) { | 27 std::string* email) { |
28 DCHECK(url.is_valid()); | 28 DCHECK(url.is_valid()); |
29 *email = net::UnescapeURLComponent(url.path().substr(1), | 29 const std::string serialized_account_id = net::UnescapeURLComponent( |
30 (net::UnescapeRule::URL_SPECIAL_CHARS | | 30 url.path().substr(1), |
31 net::UnescapeRule::SPACES)); | 31 (net::UnescapeRule::URL_SPECIAL_CHARS | net::UnescapeRule::SPACES)); |
| 32 AccountId account_id(EmptyAccountId()); |
| 33 const bool status = |
| 34 AccountId::Deserialize(serialized_account_id, &account_id); |
| 35 // TODO(alemate): DCHECK(status) - should happen after options page is |
| 36 // migrated. |
| 37 if (!status) { |
| 38 LOG(WARNING) << "Failed to deserialize '" << serialized_account_id << "'"; |
| 39 account_id = AccountId::FromUserEmail(serialized_account_id); |
| 40 } |
| 41 *email = account_id.GetUserEmail(); |
32 } | 42 } |
33 | 43 |
34 } // namespace | 44 } // namespace |
35 | 45 |
36 namespace chromeos { | 46 namespace chromeos { |
37 namespace options { | 47 namespace options { |
38 | 48 |
39 // Static. | 49 // Static. |
40 base::RefCountedMemory* UserImageSource::GetUserImage( | 50 base::RefCountedMemory* UserImageSource::GetUserImage( |
41 const AccountId& account_id, | 51 const AccountId& account_id, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 94 } |
85 | 95 |
86 std::string UserImageSource::GetMimeType(const std::string& path) const { | 96 std::string UserImageSource::GetMimeType(const std::string& path) const { |
87 // We need to explicitly return a mime type, otherwise if the user tries to | 97 // We need to explicitly return a mime type, otherwise if the user tries to |
88 // drag the image they get no extension. | 98 // drag the image they get no extension. |
89 return "image/png"; | 99 return "image/png"; |
90 } | 100 } |
91 | 101 |
92 } // namespace options | 102 } // namespace options |
93 } // namespace chromeos | 103 } // namespace chromeos |
OLD | NEW |