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/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 #include "wtf/Threading.h" |
20 #include <memory> | 20 #include <memory> |
21 | 21 |
22 namespace blink { | 22 namespace blink { |
23 | 23 |
24 NotificationImageLoader::NotificationImageLoader() | 24 NotificationImageLoader::NotificationImageLoader() |
25 : m_stopped(false), m_startTime(0.0) | 25 : m_stopped(false), m_startTime(0.0) |
26 { | 26 { |
27 } | 27 } |
28 | 28 |
29 NotificationImageLoader::~NotificationImageLoader() | 29 NotificationImageLoader::~NotificationImageLoader() |
30 { | 30 { |
haraken
2016/07/29 14:52:51
Can we add:
ASSERT(!m_threadableLoader);
?
yhirano
2016/08/01 06:20:06
It's possible, but as in WorkerThreadableLoader::P
| |
31 } | 31 } |
32 | 32 |
33 void NotificationImageLoader::start(ExecutionContext* executionContext, const KU RL& url, std::unique_ptr<ImageCallback> imageCallback) | 33 void NotificationImageLoader::start(ExecutionContext* executionContext, const KU RL& url, std::unique_ptr<ImageCallback> imageCallback) |
34 { | 34 { |
35 DCHECK(!m_stopped); | 35 DCHECK(!m_stopped); |
36 | 36 |
37 m_startTime = monotonicallyIncreasingTimeMS(); | 37 m_startTime = monotonicallyIncreasingTimeMS(); |
38 m_imageCallback = std::move(imageCallback); | 38 m_imageCallback = std::move(imageCallback); |
39 | 39 |
40 // TODO(mvanouwerkerk): Add a timeout mechanism: crbug.com/579137. | 40 // TODO(mvanouwerkerk): Add a timeout mechanism: crbug.com/579137. |
(...skipping 17 matching lines...) Expand all Loading... | |
58 } | 58 } |
59 | 59 |
60 void NotificationImageLoader::stop() | 60 void NotificationImageLoader::stop() |
61 { | 61 { |
62 if (m_stopped) | 62 if (m_stopped) |
63 return; | 63 return; |
64 | 64 |
65 m_stopped = true; | 65 m_stopped = true; |
66 if (m_threadableLoader) { | 66 if (m_threadableLoader) { |
67 m_threadableLoader->cancel(); | 67 m_threadableLoader->cancel(); |
68 // WorkerThreadableLoader keeps a Persistent<WorkerGlobalScope> to the | 68 m_threadableLoader = nullptr; |
69 // ExecutionContext it received in |create|. Kill it to prevent | |
70 // reference cycles involving a mix of GC and non-GC types that fail to | |
71 // clear in ThreadState::cleanup. | |
72 m_threadableLoader.reset(); | |
73 } | 69 } |
74 } | 70 } |
75 | 71 |
76 void NotificationImageLoader::didReceiveData(const char* data, unsigned length) | 72 void NotificationImageLoader::didReceiveData(const char* data, unsigned length) |
77 { | 73 { |
78 if (!m_data) | 74 if (!m_data) |
79 m_data = SharedBuffer::create(); | 75 m_data = SharedBuffer::create(); |
80 m_data->append(data, length); | 76 m_data->append(data, length); |
81 } | 77 } |
82 | 78 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 { | 121 { |
126 // If this has been stopped it is not desirable to trigger further work, | 122 // If this has been stopped it is not desirable to trigger further work, |
127 // there is a shutdown of some sort in progress. | 123 // there is a shutdown of some sort in progress. |
128 if (m_stopped) | 124 if (m_stopped) |
129 return; | 125 return; |
130 | 126 |
131 (*m_imageCallback)(SkBitmap()); | 127 (*m_imageCallback)(SkBitmap()); |
132 } | 128 } |
133 | 129 |
134 } // namespace blink | 130 } // namespace blink |
OLD | NEW |