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

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

Issue 1975803002: Notification histograms should be thread-safe statics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/notifications/NotificationResourcesLoader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/Histogram.h"
10 #include "platform/image-decoders/ImageDecoder.h" 10 #include "platform/image-decoders/ImageDecoder.h"
11 #include "platform/image-decoders/ImageFrame.h" 11 #include "platform/image-decoders/ImageFrame.h"
12 #include "platform/network/ResourceError.h" 12 #include "platform/network/ResourceError.h"
13 #include "platform/network/ResourceLoadPriority.h" 13 #include "platform/network/ResourceLoadPriority.h"
14 #include "platform/network/ResourceRequest.h" 14 #include "platform/network/ResourceRequest.h"
15 #include "platform/weborigin/KURL.h" 15 #include "platform/weborigin/KURL.h"
16 #include "public/platform/WebURLRequest.h" 16 #include "public/platform/WebURLRequest.h"
17 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "wtf/CurrentTime.h" 18 #include "wtf/CurrentTime.h"
19 #include "wtf/Threading.h"
19 20
20 namespace blink { 21 namespace blink {
21 22
22 NotificationImageLoader::NotificationImageLoader() 23 NotificationImageLoader::NotificationImageLoader()
23 : m_stopped(false), m_startTime(0.0) 24 : m_stopped(false), m_startTime(0.0)
24 { 25 {
25 } 26 }
26 27
27 NotificationImageLoader::~NotificationImageLoader() 28 NotificationImageLoader::~NotificationImageLoader()
28 { 29 {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 m_data->append(data, length); 79 m_data->append(data, length);
79 } 80 }
80 81
81 void NotificationImageLoader::didFinishLoading(unsigned long resourceIdentifier, double finishTime) 82 void NotificationImageLoader::didFinishLoading(unsigned long resourceIdentifier, double finishTime)
82 { 83 {
83 // If this has been stopped it is not desirable to trigger further work, 84 // If this has been stopped it is not desirable to trigger further work,
84 // there is a shutdown of some sort in progress. 85 // there is a shutdown of some sort in progress.
85 if (m_stopped) 86 if (m_stopped)
86 return; 87 return;
87 88
88 DEFINE_STATIC_LOCAL(CustomCountHistogram, finishedTimeHistogram, ("Notificat ions.Icon.LoadFinishTime", 1, 1000 * 60 * 60 /* 1 hour max */, 50 /* buckets */) ); 89 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, finishedTimeHistogram, new CustomCountHistogram("Notifications.Icon.LoadFinishTime", 1, 1000 * 60 * 60 /* 1 hour max */, 50 /* buckets */));
89 finishedTimeHistogram.count(monotonicallyIncreasingTimeMS() - m_startTime); 90 finishedTimeHistogram.count(monotonicallyIncreasingTimeMS() - m_startTime);
90 91
91 if (m_data) { 92 if (m_data) {
92 DEFINE_STATIC_LOCAL(CustomCountHistogram, fileSizeHistogram, ("Notificat ions.Icon.FileSize", 1, 10000000 /* ~10mb max */, 50 /* buckets */)); 93 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, fileSizeHistogram, new CustomCountHistogram("Notifications.Icon.FileSize", 1, 10000000 /* ~10mb ma x */, 50 /* buckets */));
93 fileSizeHistogram.count(m_data->size()); 94 fileSizeHistogram.count(m_data->size());
94 95
95 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);
96 if (decoder) { 97 if (decoder) {
97 decoder->setData(m_data.get(), true /* allDataReceived */); 98 decoder->setData(m_data.get(), true /* allDataReceived */);
98 // The |ImageFrame*| is owned by the decoder. 99 // The |ImageFrame*| is owned by the decoder.
99 ImageFrame* imageFrame = decoder->frameBufferAtIndex(0); 100 ImageFrame* imageFrame = decoder->frameBufferAtIndex(0);
100 if (imageFrame) { 101 if (imageFrame) {
101 (*m_imageCallback)(imageFrame->bitmap()); 102 (*m_imageCallback)(imageFrame->bitmap());
102 return; 103 return;
103 } 104 }
104 } 105 }
105 } 106 }
106 runCallbackWithEmptyBitmap(); 107 runCallbackWithEmptyBitmap();
107 } 108 }
108 109
109 void NotificationImageLoader::didFail(const ResourceError& error) 110 void NotificationImageLoader::didFail(const ResourceError& error)
110 { 111 {
111 DEFINE_STATIC_LOCAL(CustomCountHistogram, failedTimeHistogram, ("Notificatio ns.Icon.LoadFailTime", 1, 1000 * 60 * 60 /* 1 hour max */, 50 /* buckets */)); 112 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, failedTimeHistogram, n ew CustomCountHistogram("Notifications.Icon.LoadFailTime", 1, 1000 * 60 * 60 /* 1 hour max */, 50 /* buckets */));
112 failedTimeHistogram.count(monotonicallyIncreasingTimeMS() - m_startTime); 113 failedTimeHistogram.count(monotonicallyIncreasingTimeMS() - m_startTime);
113 114
114 runCallbackWithEmptyBitmap(); 115 runCallbackWithEmptyBitmap();
115 } 116 }
116 117
117 void NotificationImageLoader::didFailRedirectCheck() 118 void NotificationImageLoader::didFailRedirectCheck()
118 { 119 {
119 runCallbackWithEmptyBitmap(); 120 runCallbackWithEmptyBitmap();
120 } 121 }
121 122
122 void NotificationImageLoader::runCallbackWithEmptyBitmap() 123 void NotificationImageLoader::runCallbackWithEmptyBitmap()
123 { 124 {
124 // If this has been stopped it is not desirable to trigger further work, 125 // If this has been stopped it is not desirable to trigger further work,
125 // there is a shutdown of some sort in progress. 126 // there is a shutdown of some sort in progress.
126 if (m_stopped) 127 if (m_stopped)
127 return; 128 return;
128 129
129 (*m_imageCallback)(SkBitmap()); 130 (*m_imageCallback)(SkBitmap());
130 } 131 }
131 132
132 } // namespace blink 133 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/notifications/NotificationResourcesLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698