Chromium Code Reviews| 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 "third_party/skia/include/core/SkBitmap.h" | |
| 13 #include "wtf/Functional.h" | |
| 14 #include "wtf/OwnPtr.h" | |
| 15 #include "wtf/PassOwnPtr.h" | |
| 16 #include "wtf/RefPtr.h" | |
| 17 | |
| 18 namespace blink { | |
| 19 | |
| 20 class ExecutionContext; | |
| 21 class KURL; | |
| 22 class ResourceError; | |
| 23 | |
| 24 class NotificationImageLoader final | |
|
Peter Beverloo
2016/04/13 18:32:27
As a meta comment, it would be nice to document cl
Michael van Ouwerkerk
2016/04/14 13:42:11
Done.
| |
| 25 : public GarbageCollectedFinalized<NotificationImageLoader> | |
| 26 , public ThreadableLoaderClient { | |
| 27 public: | |
| 28 // The bitmap may be empty if the request failed or the image data could not | |
| 29 // be decoded. | |
| 30 using ImageCallback = Function<void(const SkBitmap&)>; | |
| 31 | |
| 32 NotificationImageLoader(); | |
| 33 ~NotificationImageLoader() override; | |
| 34 | |
| 35 // Asynchronously downloads an image from the given url, decodes the loaded | |
| 36 // data, and passes the bitmap to the callback. | |
| 37 void start(ExecutionContext*, const KURL&, PassOwnPtr<ImageCallback>); | |
| 38 | |
| 39 // Cancels the pending load, if there is one. The |m_imageCallback| will not | |
| 40 // be run. | |
| 41 void stop(); | |
| 42 | |
| 43 // ThreadableLoaderClient interface. | |
| 44 void didReceiveData(const char* data, unsigned length) override; | |
| 45 void didFinishLoading(unsigned long resourceIdentifier, | |
|
Peter Beverloo
2016/04/13 18:32:27
micro nit: nowrap
Michael van Ouwerkerk
2016/04/14 13:42:11
Done.
| |
| 46 double finishTime) override; | |
| 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_isStopped; | |
| 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 |