Chromium Code Reviews| 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/NotificationImageLoader.h" | 5 #include "modules/notifications/NotificationImageLoader.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "core/fetch/ResourceLoaderOptions.h" | 8 #include "core/fetch/ResourceLoaderOptions.h" |
| 9 #include "platform/Histogram.h" | |
| 9 #include "platform/image-decoders/ImageDecoder.h" | 10 #include "platform/image-decoders/ImageDecoder.h" |
| 10 #include "platform/image-decoders/ImageFrame.h" | 11 #include "platform/image-decoders/ImageFrame.h" |
| 11 #include "platform/network/ResourceError.h" | 12 #include "platform/network/ResourceError.h" |
| 12 #include "platform/network/ResourceLoadPriority.h" | 13 #include "platform/network/ResourceLoadPriority.h" |
| 13 #include "platform/network/ResourceRequest.h" | 14 #include "platform/network/ResourceRequest.h" |
| 14 #include "platform/weborigin/KURL.h" | 15 #include "platform/weborigin/KURL.h" |
| 15 #include "public/platform/WebURLRequest.h" | 16 #include "public/platform/WebURLRequest.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 18 #include "wtf/CurrentTime.h" | |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 NotificationImageLoader::NotificationImageLoader() | 22 NotificationImageLoader::NotificationImageLoader() |
| 21 : m_stopped(false) | 23 : m_stopped(false), m_startTime(0.0) |
| 22 { | 24 { |
| 23 } | 25 } |
| 24 | 26 |
| 25 NotificationImageLoader::~NotificationImageLoader() | 27 NotificationImageLoader::~NotificationImageLoader() |
| 26 { | 28 { |
| 27 } | 29 } |
| 28 | 30 |
| 29 void NotificationImageLoader::start(ExecutionContext* executionContext, const KU RL& url, PassOwnPtr<ImageCallback> imageCallback) | 31 void NotificationImageLoader::start(ExecutionContext* executionContext, const KU RL& url, PassOwnPtr<ImageCallback> imageCallback) |
| 30 { | 32 { |
| 31 DCHECK(!m_stopped); | 33 DCHECK(!m_stopped); |
| 32 | 34 |
| 35 m_startTime = monotonicallyIncreasingTimeMS(); | |
| 33 m_imageCallback = imageCallback; | 36 m_imageCallback = imageCallback; |
| 34 | 37 |
| 35 // TODO(mvanouwerkerk): Add a timeout mechanism: crbug.com/579137. | 38 // TODO(mvanouwerkerk): Add a timeout mechanism: crbug.com/579137. |
| 36 ThreadableLoaderOptions threadableLoaderOptions; | 39 ThreadableLoaderOptions threadableLoaderOptions; |
| 37 threadableLoaderOptions.preflightPolicy = PreventPreflight; | 40 threadableLoaderOptions.preflightPolicy = PreventPreflight; |
| 38 threadableLoaderOptions.crossOriginRequestPolicy = AllowCrossOriginRequests; | 41 threadableLoaderOptions.crossOriginRequestPolicy = AllowCrossOriginRequests; |
| 39 | 42 |
| 40 // TODO(mvanouwerkerk): Add an entry for notifications to FetchInitiatorType Names and use it. | 43 // TODO(mvanouwerkerk): Add an entry for notifications to FetchInitiatorType Names and use it. |
| 41 ResourceLoaderOptions resourceLoaderOptions; | 44 ResourceLoaderOptions resourceLoaderOptions; |
| 42 resourceLoaderOptions.allowCredentials = AllowStoredCredentials; | 45 resourceLoaderOptions.allowCredentials = AllowStoredCredentials; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 m_data->append(data, length); | 78 m_data->append(data, length); |
| 76 } | 79 } |
| 77 | 80 |
| 78 void NotificationImageLoader::didFinishLoading(unsigned long resourceIdentifier, double finishTime) | 81 void NotificationImageLoader::didFinishLoading(unsigned long resourceIdentifier, double finishTime) |
| 79 { | 82 { |
| 80 // If this has been stopped it is not desirable to trigger further work, | 83 // If this has been stopped it is not desirable to trigger further work, |
| 81 // there is a shutdown of some sort in progress. | 84 // there is a shutdown of some sort in progress. |
| 82 if (m_stopped) | 85 if (m_stopped) |
| 83 return; | 86 return; |
| 84 | 87 |
| 88 // Matches UMA_HISTOGRAM_LONG_TIMES - the way Notifications.Icon.LoadFinishT ime was originally defined. | |
|
Peter Beverloo
2016/04/22 15:56:13
Here and elsewhere -
"the way Notifications.Icon
Michael van Ouwerkerk
2016/04/25 11:28:28
Done.
| |
| 89 DEFINE_STATIC_LOCAL(CustomCountHistogram, finishedTimeHistogram, ("Notificat ions.Icon.LoadFinishTime", 1, 1000 * 60 * 60 /* 1 hour max */, 50 /* buckets */) ); | |
| 90 finishedTimeHistogram.count(monotonicallyIncreasingTimeMS() - m_startTime); | |
| 91 | |
| 85 if (m_data) { | 92 if (m_data) { |
| 93 DEFINE_STATIC_LOCAL(CustomCountHistogram, fileSizeHistogram, ("Notificat ions.Icon.FileSize", 1, 10000000 /* ~10mb max */, 50 /* buckets */)); | |
| 94 fileSizeHistogram.count(m_data->size()); | |
| 95 | |
| 86 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*m_data.get(), Image Decoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); | 96 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*m_data.get(), Image Decoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); |
| 87 if (decoder) { | 97 if (decoder) { |
| 88 decoder->setData(m_data.get(), true /* allDataReceived */); | 98 decoder->setData(m_data.get(), true /* allDataReceived */); |
| 89 // The |ImageFrame*| is owned by the decoder. | 99 // The |ImageFrame*| is owned by the decoder. |
| 90 ImageFrame* imageFrame = decoder->frameBufferAtIndex(0); | 100 ImageFrame* imageFrame = decoder->frameBufferAtIndex(0); |
| 91 if (imageFrame) { | 101 if (imageFrame) { |
| 92 (*m_imageCallback)(imageFrame->bitmap()); | 102 (*m_imageCallback)(imageFrame->bitmap()); |
| 93 return; | 103 return; |
| 94 } | 104 } |
| 95 } | 105 } |
| 96 } | 106 } |
| 97 runCallbackWithEmptyBitmap(); | 107 runCallbackWithEmptyBitmap(); |
| 98 } | 108 } |
| 99 | 109 |
| 100 void NotificationImageLoader::didFail(const ResourceError& error) | 110 void NotificationImageLoader::didFail(const ResourceError& error) |
| 101 { | 111 { |
| 112 // Matches UMA_HISTOGRAM_LONG_TIMES - the way Notifications.Icon.LoadFailTim e was originally defined. | |
| 113 DEFINE_STATIC_LOCAL(CustomCountHistogram, failedTimeHistogram, ("Notificatio ns.Icon.LoadFailTime", 1, 1000 * 60 * 60 /* 1 hour max */, 50 /* buckets */)); | |
| 114 failedTimeHistogram.count(monotonicallyIncreasingTimeMS() - m_startTime); | |
| 115 | |
| 102 runCallbackWithEmptyBitmap(); | 116 runCallbackWithEmptyBitmap(); |
| 103 } | 117 } |
| 104 | 118 |
| 105 void NotificationImageLoader::didFailRedirectCheck() | 119 void NotificationImageLoader::didFailRedirectCheck() |
| 106 { | 120 { |
| 107 runCallbackWithEmptyBitmap(); | 121 runCallbackWithEmptyBitmap(); |
| 108 } | 122 } |
| 109 | 123 |
| 110 void NotificationImageLoader::runCallbackWithEmptyBitmap() | 124 void NotificationImageLoader::runCallbackWithEmptyBitmap() |
| 111 { | 125 { |
| 112 // If this has been stopped it is not desirable to trigger further work, | 126 // If this has been stopped it is not desirable to trigger further work, |
| 113 // there is a shutdown of some sort in progress. | 127 // there is a shutdown of some sort in progress. |
| 114 if (m_stopped) | 128 if (m_stopped) |
| 115 return; | 129 return; |
| 116 | 130 |
| 117 (*m_imageCallback)(SkBitmap()); | 131 (*m_imageCallback)(SkBitmap()); |
| 118 } | 132 } |
| 119 | 133 |
| 120 } // namespace blink | 134 } // namespace blink |
| OLD | NEW |