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

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: typo 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 base::FilePath image_path = user_data_dir.AppendASCII(
339 kHighResAvatarFolderName).AppendASCII(file_name);
340 return image_path;
msw 2014/04/28 20:46:37 nit: inline the return value.
noms (inactive) 2014/04/29 19:12:27 Done.
341 }
342
331 std::string GetDefaultAvatarIconUrl(size_t index) { 343 std::string GetDefaultAvatarIconUrl(size_t index) {
332 DCHECK(IsDefaultAvatarIconIndex(index)); 344 DCHECK(IsDefaultAvatarIconIndex(index));
333 return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index); 345 return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index);
334 } 346 }
335 347
336 bool IsDefaultAvatarIconIndex(size_t index) { 348 bool IsDefaultAvatarIconIndex(size_t index) {
337 return index < kDefaultAvatarIconsCount; 349 return index < kDefaultAvatarIconsCount;
338 } 350 }
339 351
340 bool IsDefaultAvatarIconUrl(const std::string& url, 352 bool IsDefaultAvatarIconUrl(const std::string& url,
(...skipping 11 matching lines...) Expand all
352 int_value >= static_cast<int>(kDefaultAvatarIconsCount)) 364 int_value >= static_cast<int>(kDefaultAvatarIconsCount))
353 return false; 365 return false;
354 *icon_index = int_value; 366 *icon_index = int_value;
355 return true; 367 return true;
356 } 368 }
357 369
358 return false; 370 return false;
359 } 371 }
360 372
361 } // namespace profiles 373 } // namespace profiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698