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 // Fetches the resources specified in a given WebNotificationData. Uses a | |
29 // callback to notify the caller when all fetches have finished. | |
30 class MODULES_EXPORT NotificationResourcesLoader final | |
31 : public GarbageCollectedFinalized<NotificationResourcesLoader> | |
32 , public ContextLifecycleObserver { | |
Peter Beverloo
2016/04/15 11:07:29
We can remove some magic here by making ServiceWor
Michael van Ouwerkerk
2016/04/18 11:26:53
Done.
| |
33 USING_GARBAGE_COLLECTED_MIXIN(NotificationResourcesLoader); | |
34 USING_PRE_FINALIZER(NotificationResourcesLoader, stop); | |
35 public: | |
36 // Called when all fetches have finished. Passes a pointer to the | |
37 // NotificationResourcesLoader so callers that use multiple loaders can use | |
38 // the same function to handle the callbacks. | |
39 using CompletionCallback = Function<void(NotificationResourcesLoader*)>; | |
40 | |
41 NotificationResourcesLoader(ExecutionContext*, PassOwnPtr<CompletionCallback >); | |
42 ~NotificationResourcesLoader(); | |
43 | |
44 // Starts fetching the resources specified in the given WebNotificationData. | |
45 // If all the urls for the resources are empty or invalid, | |
46 // |m_completionCallback| will be run synchronously, otherwise it will be | |
47 // run asynchronously when all fetches have finished. Should not be called | |
48 // more than once. | |
49 void start(const WebNotificationData&); | |
50 | |
51 // Returns a new WebNotificationResources populated with the resources that | |
52 // have been fetched. | |
53 std::unique_ptr<WebNotificationResources> getResources() const; | |
54 | |
55 // ContextLifecycleObserver interface. | |
56 void contextDestroyed() override; | |
57 | |
58 // Stops every loader in |m_imageLoaders|. This is also used as the | |
59 // pre-finalizer. | |
60 void stop(); | |
61 | |
62 DECLARE_VIRTUAL_TRACE(); | |
63 | |
64 private: | |
65 void loadImage(const KURL&, PassOwnPtr<NotificationImageLoader::ImageCallbac k>); | |
66 void didLoadIcon(const SkBitmap& image); | |
67 void didLoadBadge(const SkBitmap& image); | |
68 void didLoadActionIcon(size_t actionIndex, const SkBitmap& image); | |
69 | |
70 // Decrements |m_pendingRequestCount| and runs |m_completionCallback| if | |
71 // there are no more pending requests. | |
72 void didFinishRequest(); | |
73 | |
74 bool m_started; | |
75 OwnPtr<CompletionCallback> m_completionCallback; | |
76 int m_pendingRequestCount; | |
77 HeapVector<Member<NotificationImageLoader>> m_imageLoaders; | |
78 SkBitmap m_icon; | |
79 SkBitmap m_badge; | |
80 Vector<SkBitmap> m_actionIcons; | |
81 }; | |
82 | |
83 } // namespace blink | |
84 | |
85 #endif // NotificationResourcesLoader_h | |
OLD | NEW |