| OLD | NEW |
| 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 "modules/notifications/NotificationResourcesLoader.h" | 5 #include "modules/notifications/NotificationResourcesLoader.h" |
| 6 | 6 |
| 7 #include "platform/Histogram.h" | 7 #include "platform/Histogram.h" |
| 8 #include "platform/weborigin/KURL.h" | 8 #include "platform/weborigin/KURL.h" |
| 9 #include "public/platform/modules/notifications/WebNotificationConstants.h" | 9 #include "public/platform/modules/notifications/WebNotificationConstants.h" |
| 10 #include "public/platform/modules/notifications/WebNotificationData.h" | 10 #include "public/platform/modules/notifications/WebNotificationData.h" |
| 11 #include "public/platform/modules/notifications/WebNotificationResources.h" | 11 #include "public/platform/modules/notifications/WebNotificationResources.h" |
| 12 #include "skia/ext/image_operations.h" | 12 #include "skia/ext/image_operations.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "wtf/CurrentTime.h" | 14 #include "wtf/CurrentTime.h" |
| 15 #include "wtf/Threading.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Scales down |image| to fit within |maxSizePx| if its width or height is | 21 // Scales down |image| to fit within |maxSizePx| if its width or height is |
| 21 // larger than |maxSizePx| and returns the result. Otherwise does nothing and | 22 // larger than |maxSizePx| and returns the result. Otherwise does nothing and |
| 22 // returns |image| unchanged. | 23 // returns |image| unchanged. |
| 23 // TODO(mvanouwerkerk): Explore doing the scaling on a background thread. | 24 // TODO(mvanouwerkerk): Explore doing the scaling on a background thread. |
| 24 SkBitmap scaleDownIfNeeded(const SkBitmap& image, int maxSizePx) | 25 SkBitmap scaleDownIfNeeded(const SkBitmap& image, int maxSizePx) |
| 25 { | 26 { |
| 26 if (image.width() > maxSizePx || image.height() > maxSizePx) { | 27 if (image.width() > maxSizePx || image.height() > maxSizePx) { |
| 27 DEFINE_STATIC_LOCAL(CustomCountHistogram, scaleTimeHistogram, ("Notifica
tions.Icon.ScaleDownTime", 1, 1000 * 10 /* 10 seconds max */, 50 /* buckets */))
; | 28 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scaleTimeHistogram
, new CustomCountHistogram("Notifications.Icon.ScaleDownTime", 1, 1000 * 10 /* 1
0 seconds max */, 50 /* buckets */)); |
| 28 double startTime = monotonicallyIncreasingTimeMS(); | 29 double startTime = monotonicallyIncreasingTimeMS(); |
| 29 SkBitmap scaledImage = skia::ImageOperations::Resize(image, skia::ImageO
perations::RESIZE_BEST, std::min(image.width(), maxSizePx), std::min(image.heigh
t(), maxSizePx)); | 30 SkBitmap scaledImage = skia::ImageOperations::Resize(image, skia::ImageO
perations::RESIZE_BEST, std::min(image.width(), maxSizePx), std::min(image.heigh
t(), maxSizePx)); |
| 30 scaleTimeHistogram.count(monotonicallyIncreasingTimeMS() - startTime); | 31 scaleTimeHistogram.count(monotonicallyIncreasingTimeMS() - startTime); |
| 31 return scaledImage; | 32 return scaledImage; |
| 32 } | 33 } |
| 33 return image; | 34 return image; |
| 34 } | 35 } |
| 35 | 36 |
| 36 } // namespace | 37 } // namespace |
| 37 | 38 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 DCHECK_GT(m_pendingRequestCount, 0); | 120 DCHECK_GT(m_pendingRequestCount, 0); |
| 120 m_pendingRequestCount--; | 121 m_pendingRequestCount--; |
| 121 if (!m_pendingRequestCount) { | 122 if (!m_pendingRequestCount) { |
| 122 stop(); | 123 stop(); |
| 123 (*m_completionCallback)(this); | 124 (*m_completionCallback)(this); |
| 124 // The |this| pointer may have been deleted now. | 125 // The |this| pointer may have been deleted now. |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 | 128 |
| 128 } // namespace blink | 129 } // namespace blink |
| OLD | NEW |