| 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/weborigin/KURL.h" | 8 #include "platform/weborigin/KURL.h" |
| 8 #include "public/platform/modules/notifications/WebNotificationConstants.h" | 9 #include "public/platform/modules/notifications/WebNotificationConstants.h" |
| 9 #include "public/platform/modules/notifications/WebNotificationData.h" | 10 #include "public/platform/modules/notifications/WebNotificationData.h" |
| 10 #include "public/platform/modules/notifications/WebNotificationResources.h" | 11 #include "public/platform/modules/notifications/WebNotificationResources.h" |
| 11 #include "skia/ext/image_operations.h" | 12 #include "skia/ext/image_operations.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "wtf/CurrentTime.h" |
| 13 | 15 |
| 14 namespace blink { | 16 namespace blink { |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 // Scales down |image| to fit within |maxSizePx| if its width or height is | 20 // Scales down |image| to fit within |maxSizePx| if its width or height is |
| 19 // larger than |maxSizePx| and returns the result. Otherwise does nothing and | 21 // larger than |maxSizePx| and returns the result. Otherwise does nothing and |
| 20 // returns |image| unchanged. | 22 // returns |image| unchanged. |
| 21 // TODO(mvanouwerkerk): Explore doing the scaling on a background thread. | 23 // TODO(mvanouwerkerk): Explore doing the scaling on a background thread. |
| 22 SkBitmap scaleDownIfNeeded(const SkBitmap& image, int maxSizePx) | 24 SkBitmap scaleDownIfNeeded(const SkBitmap& image, int maxSizePx) |
| 23 { | 25 { |
| 24 if (image.width() > maxSizePx || image.height() > maxSizePx) | 26 if (image.width() > maxSizePx || image.height() > maxSizePx) { |
| 25 return skia::ImageOperations::Resize(image, skia::ImageOperations::RESIZ
E_BEST, std::min(image.width(), maxSizePx), std::min(image.height(), maxSizePx))
; | 27 DEFINE_STATIC_LOCAL(CustomCountHistogram, scaleTimeHistogram, ("Notifica
tions.Icon.ScaleDownTime", 1, 1000 * 10 /* 10 seconds max */, 50 /* buckets */))
; |
| 28 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 scaleTimeHistogram.count(monotonicallyIncreasingTimeMS() - startTime); |
| 31 return scaledImage; |
| 32 } |
| 26 return image; | 33 return image; |
| 27 } | 34 } |
| 28 | 35 |
| 29 } // namespace | 36 } // namespace |
| 30 | 37 |
| 31 NotificationResourcesLoader::NotificationResourcesLoader(PassOwnPtr<CompletionCa
llback> completionCallback) | 38 NotificationResourcesLoader::NotificationResourcesLoader(PassOwnPtr<CompletionCa
llback> completionCallback) |
| 32 : m_started(false), m_completionCallback(std::move(completionCallback)), m_p
endingRequestCount(0) | 39 : m_started(false), m_completionCallback(std::move(completionCallback)), m_p
endingRequestCount(0) |
| 33 { | 40 { |
| 34 ThreadState::current()->registerPreFinalizer(this); | 41 ThreadState::current()->registerPreFinalizer(this); |
| 35 DCHECK(m_completionCallback); | 42 DCHECK(m_completionCallback); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 DCHECK_GT(m_pendingRequestCount, 0); | 119 DCHECK_GT(m_pendingRequestCount, 0); |
| 113 m_pendingRequestCount--; | 120 m_pendingRequestCount--; |
| 114 if (!m_pendingRequestCount) { | 121 if (!m_pendingRequestCount) { |
| 115 stop(); | 122 stop(); |
| 116 (*m_completionCallback)(this); | 123 (*m_completionCallback)(this); |
| 117 // The |this| pointer may have been deleted now. | 124 // The |this| pointer may have been deleted now. |
| 118 } | 125 } |
| 119 } | 126 } |
| 120 | 127 |
| 121 } // namespace blink | 128 } // namespace blink |
| OLD | NEW |