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

Side by Side Diff: chrome/browser/profiles/profile_avatar_icon_util.cc

Issue 222313005: [Profiles] Download high-res avatars using the --new-profile-management flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: msw comments part 2 Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/file_util.h"
7 #include "base/format_macros.h" 8 #include "base/format_macros.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h"
9 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "chrome/common/chrome_paths.h"
11 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
12 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
13 #include "third_party/skia/include/core/SkPaint.h" 16 #include "third_party/skia/include/core/SkPaint.h"
14 #include "third_party/skia/include/core/SkPath.h" 17 #include "third_party/skia/include/core/SkPath.h"
15 #include "third_party/skia/include/core/SkScalar.h" 18 #include "third_party/skia/include/core/SkScalar.h"
16 #include "third_party/skia/include/core/SkXfermode.h" 19 #include "third_party/skia/include/core/SkXfermode.h"
17 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/image/canvas_image_source.h" 22 #include "ui/gfx/image/canvas_image_source.h"
23 #include "ui/gfx/image/image.h"
20 #include "ui/gfx/image/image_skia_operations.h" 24 #include "ui/gfx/image/image_skia_operations.h"
21 25
22 // Helper methods for transforming and drawing avatar icons. 26 // Helper methods for transforming and drawing avatar icons.
23 namespace { 27 namespace {
24 28
25 // Determine what the scaled height of the avatar icon should be for a 29 // Determine what the scaled height of the avatar icon should be for a
26 // specified width, to preserve the aspect ratio. 30 // specified width, to preserve the aspect ratio.
27 int GetScaledAvatarHeightForWidth(int width, const gfx::ImageSkia& avatar) { 31 int GetScaledAvatarHeightForWidth(int width, const gfx::ImageSkia& avatar) {
28
29 // Multiply the width by the inverted aspect ratio (height over 32 // Multiply the width by the inverted aspect ratio (height over
30 // width), and then add 0.5 to ensure the int truncation rounds nicely. 33 // width), and then add 0.5 to ensure the int truncation rounds nicely.
31 int scaled_height = width * 34 int scaled_height = width *
32 ((float) avatar.height() / (float) avatar.width()) + 0.5f; 35 ((float) avatar.height() / (float) avatar.width()) + 0.5f;
33 return scaled_height; 36 return scaled_height;
34 } 37 }
35 38
36 // A CanvasImageSource that draws a sized and positioned avatar with an 39 // A CanvasImageSource that draws a sized and positioned avatar with an
37 // optional border independently of the scale factor. 40 // optional border independently of the scale factor.
38 class AvatarImageSource : public gfx::CanvasImageSource { 41 class AvatarImageSource : public gfx::CanvasImageSource {
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 324
322 const char* GetDefaultAvatarIconFileNameAtIndex(size_t index) { 325 const char* GetDefaultAvatarIconFileNameAtIndex(size_t index) {
323 DCHECK(index < kDefaultAvatarIconsCount); 326 DCHECK(index < kDefaultAvatarIconsCount);
324 return GetDefaultAvatarIconResourceInfo(index)->filename; 327 return GetDefaultAvatarIconResourceInfo(index)->filename;
325 } 328 }
326 329
327 const char* GetNoHighResAvatarFileName() { 330 const char* GetNoHighResAvatarFileName() {
328 return kNoHighResAvatar; 331 return kNoHighResAvatar;
329 } 332 }
330 333
334 base::FilePath GetPathOfHighResAvatarAtIndex(size_t index) {
335 std::string file_name = GetDefaultAvatarIconResourceInfo(index)->filename;
336 base::FilePath user_data_dir;
337 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
338 return user_data_dir.AppendASCII(
339 kHighResAvatarFolderName).AppendASCII(file_name);
340 }
341
331 std::string GetDefaultAvatarIconUrl(size_t index) { 342 std::string GetDefaultAvatarIconUrl(size_t index) {
332 DCHECK(IsDefaultAvatarIconIndex(index)); 343 DCHECK(IsDefaultAvatarIconIndex(index));
333 return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index); 344 return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index);
334 } 345 }
335 346
336 bool IsDefaultAvatarIconIndex(size_t index) { 347 bool IsDefaultAvatarIconIndex(size_t index) {
337 return index < kDefaultAvatarIconsCount; 348 return index < kDefaultAvatarIconsCount;
338 } 349 }
339 350
340 bool IsDefaultAvatarIconUrl(const std::string& url, 351 bool IsDefaultAvatarIconUrl(const std::string& url, size_t* icon_index) {
341 size_t* icon_index) {
342 DCHECK(icon_index); 352 DCHECK(icon_index);
343 if (url.find(kDefaultUrlPrefix) != 0) 353 if (url.find(kDefaultUrlPrefix) != 0)
344 return false; 354 return false;
345 355
346 int int_value = -1; 356 int int_value = -1;
347 if (base::StringToInt(base::StringPiece(url.begin() + 357 if (base::StringToInt(base::StringPiece(url.begin() +
348 strlen(kDefaultUrlPrefix), 358 strlen(kDefaultUrlPrefix),
349 url.end()), 359 url.end()),
350 &int_value)) { 360 &int_value)) {
351 if (int_value < 0 || 361 if (int_value < 0 ||
352 int_value >= static_cast<int>(kDefaultAvatarIconsCount)) 362 int_value >= static_cast<int>(kDefaultAvatarIconsCount))
353 return false; 363 return false;
354 *icon_index = int_value; 364 *icon_index = int_value;
355 return true; 365 return true;
356 } 366 }
357 367
358 return false; 368 return false;
359 } 369 }
360 370
361 } // namespace profiles 371 } // namespace profiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698