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

Side by Side Diff: third_party/WebKit/Source/modules/notifications/NotificationImageLoader.cpp

Issue 1904293003: Restore the histograms for notification resource loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 7 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 "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 = std::move(imageCallback); 36 m_imageCallback = std::move(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
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 DEFINE_STATIC_LOCAL(CustomCountHistogram, finishedTimeHistogram, ("Notificat ions.Icon.LoadFinishTime", 1, 1000 * 60 * 60 /* 1 hour max */, 50 /* buckets */) );
89 finishedTimeHistogram.count(monotonicallyIncreasingTimeMS() - m_startTime);
90
85 if (m_data) { 91 if (m_data) {
92 DEFINE_STATIC_LOCAL(CustomCountHistogram, fileSizeHistogram, ("Notificat ions.Icon.FileSize", 1, 10000000 /* ~10mb max */, 50 /* buckets */));
93 fileSizeHistogram.count(m_data->size());
94
86 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*m_data.get(), Image Decoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); 95 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*m_data.get(), Image Decoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied);
87 if (decoder) { 96 if (decoder) {
88 decoder->setData(m_data.get(), true /* allDataReceived */); 97 decoder->setData(m_data.get(), true /* allDataReceived */);
89 // The |ImageFrame*| is owned by the decoder. 98 // The |ImageFrame*| is owned by the decoder.
90 ImageFrame* imageFrame = decoder->frameBufferAtIndex(0); 99 ImageFrame* imageFrame = decoder->frameBufferAtIndex(0);
91 if (imageFrame) { 100 if (imageFrame) {
92 (*m_imageCallback)(imageFrame->bitmap()); 101 (*m_imageCallback)(imageFrame->bitmap());
93 return; 102 return;
94 } 103 }
95 } 104 }
96 } 105 }
97 runCallbackWithEmptyBitmap(); 106 runCallbackWithEmptyBitmap();
98 } 107 }
99 108
100 void NotificationImageLoader::didFail(const ResourceError& error) 109 void NotificationImageLoader::didFail(const ResourceError& error)
101 { 110 {
111 DEFINE_STATIC_LOCAL(CustomCountHistogram, failedTimeHistogram, ("Notificatio ns.Icon.LoadFailTime", 1, 1000 * 60 * 60 /* 1 hour max */, 50 /* buckets */));
112 failedTimeHistogram.count(monotonicallyIncreasingTimeMS() - m_startTime);
113
102 runCallbackWithEmptyBitmap(); 114 runCallbackWithEmptyBitmap();
103 } 115 }
104 116
105 void NotificationImageLoader::didFailRedirectCheck() 117 void NotificationImageLoader::didFailRedirectCheck()
106 { 118 {
107 runCallbackWithEmptyBitmap(); 119 runCallbackWithEmptyBitmap();
108 } 120 }
109 121
110 void NotificationImageLoader::runCallbackWithEmptyBitmap() 122 void NotificationImageLoader::runCallbackWithEmptyBitmap()
111 { 123 {
112 // If this has been stopped it is not desirable to trigger further work, 124 // If this has been stopped it is not desirable to trigger further work,
113 // there is a shutdown of some sort in progress. 125 // there is a shutdown of some sort in progress.
114 if (m_stopped) 126 if (m_stopped)
115 return; 127 return;
116 128
117 (*m_imageCallback)(SkBitmap()); 129 (*m_imageCallback)(SkBitmap());
118 } 130 }
119 131
120 } // namespace blink 132 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698