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/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/user@host?key1=value1&...&key_n=value_n", |
|
dzhioev (left Google)
2015/11/12 00:46:24
Update the comment.
Alexander Alekseev
2015/11/12 06:53:04
Done.
| |
| 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 user_id = net::UnescapeURLComponent( |
|
stevenjb
2015/11/11 20:39:23
s/user_id/serialized_account_id/
Alexander Alekseev
2015/11/12 06:53:04
Done.
| |
| 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 = AccountId::Deserialize(user_id, &account_id); | |
| 34 // TODO(alemate): DCHECK(status) - should happen after options page is | |
| 35 // migrated. | |
| 36 if (!status) { | |
| 37 LOG(WARNING) << "Failed to deserialize '" << user_id << "'"; | |
|
dzhioev (left Google)
2015/11/12 00:46:24
I believe we shouldn't produce this warning, as lo
Alexander Alekseev
2015/11/12 06:53:04
I don't think we should support other ID formats f
| |
| 38 account_id = AccountId::FromUserEmail(user_id); | |
| 39 } | |
| 40 *email = account_id.GetUserEmail(); | |
| 32 } | 41 } |
| 33 | 42 |
| 34 } // namespace | 43 } // namespace |
| 35 | 44 |
| 36 namespace chromeos { | 45 namespace chromeos { |
| 37 namespace options { | 46 namespace options { |
| 38 | 47 |
| 39 // Static. | 48 // Static. |
| 40 base::RefCountedMemory* UserImageSource::GetUserImage( | 49 base::RefCountedMemory* UserImageSource::GetUserImage( |
| 41 const AccountId& account_id, | 50 const AccountId& account_id, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 } | 93 } |
| 85 | 94 |
| 86 std::string UserImageSource::GetMimeType(const std::string& path) const { | 95 std::string UserImageSource::GetMimeType(const std::string& path) const { |
| 87 // We need to explicitly return a mime type, otherwise if the user tries to | 96 // We need to explicitly return a mime type, otherwise if the user tries to |
| 88 // drag the image they get no extension. | 97 // drag the image they get no extension. |
| 89 return "image/png"; | 98 return "image/png"; |
| 90 } | 99 } |
| 91 | 100 |
| 92 } // namespace options | 101 } // namespace options |
| 93 } // namespace chromeos | 102 } // namespace chromeos |
| OLD | NEW |