| 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/serialized-user-id?key1=value1&...&key_n=value_n", | 24 // "chrome://userimage/user@host?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 const std::string serialized_account_id = net::UnescapeURLComponent( | 29 *email = net::UnescapeURLComponent(url.path().substr(1), |
| 30 url.path().substr(1), | 30 (net::UnescapeRule::URL_SPECIAL_CHARS | |
| 31 (net::UnescapeRule::URL_SPECIAL_CHARS | net::UnescapeRule::SPACES)); | 31 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(); | |
| 42 } | 32 } |
| 43 | 33 |
| 44 } // namespace | 34 } // namespace |
| 45 | 35 |
| 46 namespace chromeos { | 36 namespace chromeos { |
| 47 namespace options { | 37 namespace options { |
| 48 | 38 |
| 49 // Static. | 39 // Static. |
| 50 base::RefCountedMemory* UserImageSource::GetUserImage( | 40 base::RefCountedMemory* UserImageSource::GetUserImage( |
| 51 const AccountId& account_id, | 41 const AccountId& account_id, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 84 } |
| 95 | 85 |
| 96 std::string UserImageSource::GetMimeType(const std::string& path) const { | 86 std::string UserImageSource::GetMimeType(const std::string& path) const { |
| 97 // We need to explicitly return a mime type, otherwise if the user tries to | 87 // We need to explicitly return a mime type, otherwise if the user tries to |
| 98 // drag the image they get no extension. | 88 // drag the image they get no extension. |
| 99 return "image/png"; | 89 return "image/png"; |
| 100 } | 90 } |
| 101 | 91 |
| 102 } // namespace options | 92 } // namespace options |
| 103 } // namespace chromeos | 93 } // namespace chromeos |
| OLD | NEW |