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

Side by Side Diff: content/child/notifications/pending_notification.cc

Issue 1715763002: Add histograms for notification icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NotificationIconScaling
Patch Set: Created 4 years, 10 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/child/notifications/pending_notification.h" 5 #include "content/child/notifications/pending_notification.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/metrics/histogram_macros.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "content/common/notification_constants.h" 15 #include "content/common/notification_constants.h"
15 #include "content/public/common/notification_resources.h" 16 #include "content/public/common/notification_resources.h"
16 #include "skia/ext/image_operations.h" 17 #include "skia/ext/image_operations.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 namespace { 22 namespace {
22 23
23 // Scales down |icon| to fit within |max_size_px| if its width or height is 24 // Scales down |icon| to fit within |max_size_px| if its width or height is
24 // larger than |max_size_px| and returns the result. Otherwise does nothing and 25 // larger than |max_size_px| and returns the result. Otherwise does nothing and
25 // returns |icon| unchanged. 26 // returns |icon| unchanged.
26 SkBitmap ScaleDownIfNeeded(const SkBitmap& icon, int max_size_px) { 27 SkBitmap ScaleDownIfNeeded(const SkBitmap& icon, int max_size_px) {
27 if (icon.width() > max_size_px || icon.height() > max_size_px) { 28 if (icon.width() > max_size_px || icon.height() > max_size_px) {
29 SCOPED_UMA_HISTOGRAM_TIMER("Notifications.Icon.ScaleDownTime");
28 return skia::ImageOperations::Resize(icon, 30 return skia::ImageOperations::Resize(icon,
29 skia::ImageOperations::RESIZE_BEST, 31 skia::ImageOperations::RESIZE_BEST,
30 std::min(icon.width(), max_size_px), 32 std::min(icon.width(), max_size_px),
31 std::min(icon.height(), max_size_px)); 33 std::min(icon.height(), max_size_px));
32 } 34 }
33 return icon; 35 return icon;
34 } 36 }
35 37
36 } // namespace 38 } // namespace
37 39
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void PendingNotification::DidFetchActionIcon(size_t action_index, 105 void PendingNotification::DidFetchActionIcon(size_t action_index,
104 const SkBitmap& icon) { 106 const SkBitmap& icon) {
105 DCHECK_LT(action_index, action_icons_.size()); 107 DCHECK_LT(action_index, action_icons_.size());
106 108
107 action_icons_[action_index] = 109 action_icons_[action_index] =
108 ScaleDownIfNeeded(icon, kPlatformNotificationMaxActionIconSizePx); 110 ScaleDownIfNeeded(icon, kPlatformNotificationMaxActionIconSizePx);
109 fetches_finished_barrier_closure_.Run(); 111 fetches_finished_barrier_closure_.Run();
110 } 112 }
111 113
112 } // namespace content 114 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698