| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/profile_avatar_icon_util.h" | 5 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 | 507 |
| 508 bool GetImageURLWithThumbnailSize( | 508 bool GetImageURLWithThumbnailSize( |
| 509 const GURL& old_url, int size, GURL* new_url) { | 509 const GURL& old_url, int size, GURL* new_url) { |
| 510 DCHECK(new_url); | 510 DCHECK(new_url); |
| 511 std::vector<std::string> components = base::SplitString( | 511 std::vector<std::string> components = base::SplitString( |
| 512 old_url.path(), std::string(1, kURLPathSeparator), | 512 old_url.path(), std::string(1, kURLPathSeparator), |
| 513 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 513 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 514 if (components.empty()) | 514 if (components.empty()) |
| 515 return false; | 515 return false; |
| 516 | 516 |
| 517 const std::string& old_path = old_url.path(); | 517 const base::StringPiece& old_path = old_url.path(); |
| 518 std::string default_size_component( | 518 std::string default_size_component( |
| 519 base::StringPrintf(kThumbnailSizeFormat, kDefaultThumbnailSize)); | 519 base::StringPrintf(kThumbnailSizeFormat, kDefaultThumbnailSize)); |
| 520 std::string new_size_component( | 520 std::string new_size_component( |
| 521 base::StringPrintf(kThumbnailSizeFormat, size)); | 521 base::StringPrintf(kThumbnailSizeFormat, size)); |
| 522 | 522 |
| 523 size_t pos = old_path.find(default_size_component); | 523 size_t pos = old_path.find(default_size_component); |
| 524 size_t end = std::string::npos; | 524 size_t end = std::string::npos; |
| 525 if (pos != std::string::npos) { | 525 if (pos != std::string::npos) { |
| 526 // The default size is already specified in the URL so it needs to be | 526 // The default size is already specified in the URL so it needs to be |
| 527 // replaced with the new size. | 527 // replaced with the new size. |
| 528 end = pos + default_size_component.size(); | 528 end = pos + default_size_component.size(); |
| 529 } else { | 529 } else { |
| 530 // The default size is not in the URL so try to insert it before the last | 530 // The default size is not in the URL so try to insert it before the last |
| 531 // component. | 531 // component. |
| 532 const std::string& file_name = old_url.ExtractFileName(); | 532 const std::string& file_name = old_url.ExtractFileName(); |
| 533 if (!file_name.empty()) { | 533 if (!file_name.empty()) { |
| 534 pos = old_path.find(file_name); | 534 pos = old_path.find(file_name); |
| 535 end = pos - 1; | 535 end = pos - 1; |
| 536 } | 536 } |
| 537 } | 537 } |
| 538 | 538 |
| 539 if (pos != std::string::npos) { | 539 if (pos != std::string::npos) { |
| 540 std::string new_path = old_path.substr(0, pos) + new_size_component + | 540 std::string new_path = old_path.substr(0, pos).as_string() + |
| 541 old_path.substr(end); | 541 new_size_component + |
| 542 old_path.substr(end).as_string(); |
| 542 GURL::Replacements replacement; | 543 GURL::Replacements replacement; |
| 543 replacement.SetPathStr(new_path.c_str()); | 544 replacement.SetPathStr(new_path.c_str()); |
| 544 *new_url = old_url.ReplaceComponents(replacement); | 545 *new_url = old_url.ReplaceComponents(replacement); |
| 545 return new_url->is_valid(); | 546 return new_url->is_valid(); |
| 546 } | 547 } |
| 547 | 548 |
| 548 // We can't set the image size, just use the default size. | 549 // We can't set the image size, just use the default size. |
| 549 *new_url = old_url; | 550 *new_url = old_url; |
| 550 return true; | 551 return true; |
| 551 } | 552 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 563 avatar_info->SetString( | 564 avatar_info->SetString( |
| 564 "label", l10n_util::GetStringUTF16( | 565 "label", l10n_util::GetStringUTF16( |
| 565 profiles::GetDefaultAvatarLabelResourceIDAtIndex(i))); | 566 profiles::GetDefaultAvatarLabelResourceIDAtIndex(i))); |
| 566 | 567 |
| 567 avatars->Append(std::move(avatar_info)); | 568 avatars->Append(std::move(avatar_info)); |
| 568 } | 569 } |
| 569 return avatars; | 570 return avatars; |
| 570 } | 571 } |
| 571 | 572 |
| 572 } // namespace profiles | 573 } // namespace profiles |
| OLD | NEW |