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 NotificationResourcesLoader_h | |
| 6 #define NotificationResourcesLoader_h | |
| 7 | |
| 8 #include "core/dom/ContextLifecycleObserver.h" | |
| 9 #include "modules/ModulesExport.h" | |
| 10 #include "modules/notifications/NotificationImageLoader.h" | |
| 11 #include "platform/heap/GarbageCollected.h" | |
| 12 #include "platform/heap/Handle.h" | |
| 13 #include "platform/heap/HeapAllocator.h" | |
| 14 #include "platform/heap/ThreadState.h" | |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | |
| 16 #include "wtf/Functional.h" | |
| 17 #include "wtf/OwnPtr.h" | |
| 18 #include "wtf/PassOwnPtr.h" | |
| 19 #include "wtf/Vector.h" | |
| 20 #include <memory> | |
| 21 | |
| 22 namespace blink { | |
| 23 | |
| 24 class ExecutionContext; | |
| 25 struct WebNotificationData; | |
| 26 struct WebNotificationResources; | |
| 27 | |
| 28 class MODULES_EXPORT NotificationResourcesLoader final | |
| 29 : public GarbageCollectedFinalized<NotificationResourcesLoader> | |
| 30 , public ContextLifecycleObserver { | |
| 31 USING_GARBAGE_COLLECTED_MIXIN(NotificationResourcesLoader); | |
| 32 USING_PRE_FINALIZER(NotificationResourcesLoader, stop); | |
| 33 public: | |
| 34 using CompletionCallback = Function<void(NotificationResourcesLoader*)>; | |
|
Peter Beverloo
2016/04/13 18:32:28
Docs? Would be good to document that the instance
Michael van Ouwerkerk
2016/04/14 13:42:12
Done.
| |
| 35 NotificationResourcesLoader(ExecutionContext*, | |
| 36 PassOwnPtr<CompletionCallback>); | |
|
Peter Beverloo
2016/04/13 18:32:28
micro nit: nowrap
Michael van Ouwerkerk
2016/04/14 13:42:12
Done.
| |
| 37 ~NotificationResourcesLoader(); | |
| 38 | |
| 39 // Starts fetching the resources specified in the given WebNotificationData. | |
| 40 // If all the urls for the resources are empty or invalid, | |
| 41 // |m_completionCallback| will be run synchronously, otherwise it will be | |
| 42 // run asynchronously when all fetches have finished. Should not be called | |
| 43 // more than once. | |
|
Peter Beverloo
2016/04/13 18:32:28
Is there any way we can DCHECK for this contract?
Michael van Ouwerkerk
2016/04/14 13:42:12
I've added m_started for this.
| |
| 44 void start(const WebNotificationData&); | |
| 45 | |
| 46 // Returns a new WebNotificationResources populated with the resources that | |
| 47 // have been fetched. | |
| 48 std::unique_ptr<WebNotificationResources> getResources() const; | |
| 49 | |
| 50 // ContextLifecycleObserver interface. | |
| 51 void contextDestroyed() override; | |
| 52 | |
| 53 DECLARE_VIRTUAL_TRACE(); | |
| 54 | |
| 55 private: | |
| 56 void loadImage(const KURL&, | |
| 57 PassOwnPtr<NotificationImageLoader::ImageCallback>); | |
|
Peter Beverloo
2016/04/13 18:32:28
micro nit: nowrap
(This is invalid per Chromium s
Michael van Ouwerkerk
2016/04/14 13:42:12
Done.
| |
| 58 void didLoadIcon(const SkBitmap& image); | |
| 59 void didLoadBadge(const SkBitmap& image); | |
| 60 void didLoadActionIcon(size_t actionIndex, const SkBitmap& image); | |
| 61 | |
| 62 // Decrements |m_pendingRequestCount| and runs |m_completionCallback| if | |
| 63 // there are no more pending requests. | |
| 64 void didFinishRequest(); | |
| 65 | |
| 66 // Stops every loader in |m_imageLoaders|. | |
|
Peter Beverloo
2016/04/13 18:32:28
nit: Also document that this is the pre-finalizer.
Michael van Ouwerkerk
2016/04/14 13:42:12
Done.
| |
| 67 void stop(); | |
| 68 | |
| 69 OwnPtr<CompletionCallback> m_completionCallback; | |
| 70 int m_pendingRequestCount; | |
| 71 HeapVector<Member<NotificationImageLoader>> m_imageLoaders; | |
| 72 SkBitmap m_icon; | |
| 73 SkBitmap m_badge; | |
| 74 Vector<SkBitmap> m_actionIcons; | |
| 75 }; | |
| 76 | |
| 77 } // namespace blink | |
| 78 | |
| 79 #endif // NotificationResourcesLoader_h | |
| OLD | NEW |