Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1553)

Unified Diff: chrome/browser/profiles/profile_avatar_icon_util.cc

Issue 1487283005: Implement the new Sync Confirmation dialog on Linux and Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/profile_avatar_icon_util.cc
diff --git a/chrome/browser/profiles/profile_avatar_icon_util.cc b/chrome/browser/profiles/profile_avatar_icon_util.cc
index ccdcb59e3531da4e9871b06d5b7956d492081bd2..6f50842eee04ad065291d5587f54c2860540e409 100644
--- a/chrome/browser/profiles/profile_avatar_icon_util.cc
+++ b/chrome/browser/profiles/profile_avatar_icon_util.cc
@@ -10,6 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_info_cache.h"
@@ -28,10 +29,19 @@
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/skia_util.h"
+#include "url/gurl.h"
+#include "url/url_canon.h"
// Helper methods for transforming and drawing avatar icons.
namespace {
+// Path format for specifying thumbnail's size.
+const char kThumbnailSizeFormat[] = "s%d-c";
+// Default thumbnail size.
+const int kDefaultThumbnailSize = 64;
+// Separator of URL path components.
+const char kURLPathSeparator = '/';
+
// Determine what the scaled height of the avatar icon should be for a
// specified width, to preserve the aspect ratio.
int GetScaledAvatarHeightForWidth(int width, const gfx::ImageSkia& avatar) {
@@ -388,4 +398,49 @@ bool IsDefaultAvatarIconUrl(const std::string& url, size_t* icon_index) {
return false;
}
+bool GetImageURLWithThumbnailSize(
+ const GURL& old_url, int size, GURL* new_url) {
+ DCHECK(new_url);
+ std::vector<std::string> components = base::SplitString(
+ old_url.path(), std::string(1, kURLPathSeparator),
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ if (components.empty())
+ return false;
+
+ const std::string& old_path = old_url.path();
+ std::string default_size_component(
+ base::StringPrintf(kThumbnailSizeFormat, kDefaultThumbnailSize));
+ std::string new_size_component(
+ base::StringPrintf(kThumbnailSizeFormat, size));
+
+ size_t pos = old_path.find(default_size_component);
+ size_t end = std::string::npos;
+ if (pos != std::string::npos) {
+ // The default size is already specified in the URL so it needs to be
+ // replaced with the new size.
+ end = pos + default_size_component.size();
+ } else {
+ // The default size is not in the URL so try to insert it before the last
+ // component.
+ const std::string& file_name = old_url.ExtractFileName();
+ if (!file_name.empty()) {
+ pos = old_path.find(file_name);
+ end = pos - 1;
+ }
+ }
+
+ if (pos != std::string::npos) {
+ std::string new_path = old_path.substr(0, pos) + new_size_component +
+ old_path.substr(end);
+ GURL::Replacements replacement;
+ replacement.SetPathStr(new_path.c_str());
+ *new_url = old_url.ReplaceComponents(replacement);
+ return new_url->is_valid();
+ }
+
+ // We can't set the image size, just use the default size.
+ *new_url = old_url;
+ return true;
+}
+
} // namespace profiles

Powered by Google App Engine
This is Rietveld 408576698