OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NotificationImageLoader_h |
| 6 #define NotificationImageLoader_h |
| 7 |
| 8 #include "core/loader/ThreadableLoader.h" |
| 9 #include "core/loader/ThreadableLoaderClient.h" |
| 10 #include "platform/SharedBuffer.h" |
| 11 #include "platform/heap/Handle.h" |
| 12 #include "wtf/Functional.h" |
| 13 #include "wtf/OwnPtr.h" |
| 14 #include "wtf/PassOwnPtr.h" |
| 15 #include "wtf/RefPtr.h" |
| 16 |
| 17 class SkBitmap; |
| 18 |
| 19 namespace blink { |
| 20 |
| 21 class ExecutionContext; |
| 22 class KURL; |
| 23 class ResourceError; |
| 24 |
| 25 // Asynchronously downloads an image when given a url, decodes the loaded data, |
| 26 // and passes the bitmap to the given callback. |
| 27 class NotificationImageLoader final : public GarbageCollectedFinalized<Notificat
ionImageLoader>, public ThreadableLoaderClient { |
| 28 public: |
| 29 // The bitmap may be empty if the request failed or the image data could not |
| 30 // be decoded. |
| 31 using ImageCallback = Function<void(const SkBitmap&)>; |
| 32 |
| 33 NotificationImageLoader(); |
| 34 ~NotificationImageLoader() override; |
| 35 |
| 36 // Asynchronously downloads an image from the given url, decodes the loaded |
| 37 // data, and passes the bitmap to the callback. |
| 38 void start(ExecutionContext*, const KURL&, PassOwnPtr<ImageCallback>); |
| 39 |
| 40 // Cancels the pending load, if there is one. The |m_imageCallback| will not |
| 41 // be run. |
| 42 void stop(); |
| 43 |
| 44 // ThreadableLoaderClient interface. |
| 45 void didReceiveData(const char* data, unsigned length) override; |
| 46 void didFinishLoading(unsigned long resourceIdentifier, double finishTime) o
verride; |
| 47 void didFail(const ResourceError&) override; |
| 48 void didFailRedirectCheck() override; |
| 49 |
| 50 DEFINE_INLINE_TRACE() {} |
| 51 |
| 52 private: |
| 53 void runCallbackWithEmptyBitmap(); |
| 54 |
| 55 bool m_stopped; |
| 56 RefPtr<SharedBuffer> m_data; |
| 57 OwnPtr<ImageCallback> m_imageCallback; |
| 58 OwnPtr<ThreadableLoader> m_threadableLoader; |
| 59 }; |
| 60 |
| 61 } // namespace blink |
| 62 |
| 63 #endif // NotificationImageLoader_h |
OLD | NEW |