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

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

Issue 660813002: [Win] Add a fast profile switcher to the Windows taskbar item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile Created 6 years, 1 month 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
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/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/profiles/profile_info_cache.h"
15 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
14 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
15 #include "skia/ext/image_operations.h" 18 #include "skia/ext/image_operations.h"
16 #include "third_party/skia/include/core/SkPaint.h" 19 #include "third_party/skia/include/core/SkPaint.h"
17 #include "third_party/skia/include/core/SkPath.h" 20 #include "third_party/skia/include/core/SkPath.h"
18 #include "third_party/skia/include/core/SkScalar.h" 21 #include "third_party/skia/include/core/SkScalar.h"
19 #include "third_party/skia/include/core/SkXfermode.h" 22 #include "third_party/skia/include/core/SkXfermode.h"
23 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/image/canvas_image_source.h" 25 #include "ui/gfx/image/canvas_image_source.h"
22 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
23 #include "ui/gfx/image/image_skia_operations.h" 27 #include "ui/gfx/image/image_skia_operations.h"
24 #include "ui/gfx/rect.h" 28 #include "ui/gfx/rect.h"
25 #include "ui/gfx/skia_util.h" 29 #include "ui/gfx/skia_util.h"
26 30
27 // Helper methods for transforming and drawing avatar icons. 31 // Helper methods for transforming and drawing avatar icons.
28 namespace { 32 namespace {
29 33
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 frame.Inset(scale_factor * 2, 0, scale_factor * 2, 0); 284 frame.Inset(scale_factor * 2, 0, scale_factor * 2, 0);
281 source_bitmap.extractSubset(&square_bitmap, gfx::RectToSkIRect(frame)); 285 source_bitmap.extractSubset(&square_bitmap, gfx::RectToSkIRect(frame));
282 } else { 286 } else {
283 // If not the avatar icon's aspect ratio, the image should be square. 287 // If not the avatar icon's aspect ratio, the image should be square.
284 DCHECK(source_bitmap.width() == source_bitmap.height()); 288 DCHECK(source_bitmap.width() == source_bitmap.height());
285 square_bitmap = source_bitmap; 289 square_bitmap = source_bitmap;
286 } 290 }
287 return square_bitmap; 291 return square_bitmap;
288 } 292 }
289 293
294 void GetTransparentBackgroundProfileAvatar(const base::FilePath& profile_path,
tapted 2014/11/03 23:57:06 nit: move to end of file? (to be consistent with d
noms (inactive) 2014/11/04 20:03:09 Turns out everything was in a whack order, so I re
295 gfx::Image* image,
296 bool* is_rectangle) {
297 const ProfileInfoCache& cache =
298 g_browser_process->profile_manager()->GetProfileInfoCache();
299 size_t index = cache.GetIndexOfProfileWithPath(profile_path);
300 if (index == std::string::npos) {
301 NOTREACHED();
302 return;
303 }
304
305 // If there is a Gaia image available, try to use that.
306 if (cache.IsUsingGAIAPictureOfProfileAtIndex(index)) {
307 const gfx::Image* gaia_image = cache.GetGAIAPictureOfProfileAtIndex(index);
308 if (gaia_image) {
309 *image = *gaia_image;
310 *is_rectangle = true;
311 return;
312 }
313 }
314
315 // Otherwise, use the default resource, not the downloaded high-res one.
316 const size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index);
317 const int resource_id =
318 profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index);
319 *image = ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
320 *is_rectangle = false;
321 }
322
290 // Helper methods for accessing, transforming and drawing avatar icons. 323 // Helper methods for accessing, transforming and drawing avatar icons.
291 size_t GetDefaultAvatarIconCount() { 324 size_t GetDefaultAvatarIconCount() {
292 return kDefaultAvatarIconsCount; 325 return kDefaultAvatarIconsCount;
293 } 326 }
294 327
295 size_t GetGenericAvatarIconCount() { 328 size_t GetGenericAvatarIconCount() {
296 return kGenericAvatarIconsCount; 329 return kGenericAvatarIconsCount;
297 } 330 }
298 331
299 int GetPlaceholderAvatarIndex() { 332 int GetPlaceholderAvatarIndex() {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 int_value >= static_cast<int>(kDefaultAvatarIconsCount)) 415 int_value >= static_cast<int>(kDefaultAvatarIconsCount))
383 return false; 416 return false;
384 *icon_index = int_value; 417 *icon_index = int_value;
385 return true; 418 return true;
386 } 419 }
387 420
388 return false; 421 return false;
389 } 422 }
390 423
391 } // namespace profiles 424 } // namespace profiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698