Index: third_party/WebKit/Source/modules/notifications/NotificationResourcesLoader.h |
diff --git a/third_party/WebKit/Source/modules/notifications/NotificationResourcesLoader.h b/third_party/WebKit/Source/modules/notifications/NotificationResourcesLoader.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f3a7f2bf92d2ce161d345e5b73c2ff37aeb69dba |
--- /dev/null |
+++ b/third_party/WebKit/Source/modules/notifications/NotificationResourcesLoader.h |
@@ -0,0 +1,79 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NotificationResourcesLoader_h |
+#define NotificationResourcesLoader_h |
+ |
+#include "core/dom/ContextLifecycleObserver.h" |
+#include "modules/ModulesExport.h" |
+#include "modules/notifications/NotificationImageLoader.h" |
+#include "platform/heap/GarbageCollected.h" |
+#include "platform/heap/Handle.h" |
+#include "platform/heap/HeapAllocator.h" |
+#include "platform/heap/ThreadState.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
+#include "wtf/Functional.h" |
+#include "wtf/OwnPtr.h" |
+#include "wtf/PassOwnPtr.h" |
+#include "wtf/Vector.h" |
+#include <memory> |
+ |
+namespace blink { |
+ |
+class ExecutionContext; |
+struct WebNotificationData; |
+struct WebNotificationResources; |
+ |
+class MODULES_EXPORT NotificationResourcesLoader final |
+ : public GarbageCollectedFinalized<NotificationResourcesLoader> |
+ , public ContextLifecycleObserver { |
+ USING_GARBAGE_COLLECTED_MIXIN(NotificationResourcesLoader); |
+ USING_PRE_FINALIZER(NotificationResourcesLoader, stop); |
+public: |
+ 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.
|
+ NotificationResourcesLoader(ExecutionContext*, |
+ PassOwnPtr<CompletionCallback>); |
Peter Beverloo
2016/04/13 18:32:28
micro nit: nowrap
Michael van Ouwerkerk
2016/04/14 13:42:12
Done.
|
+ ~NotificationResourcesLoader(); |
+ |
+ // Starts fetching the resources specified in the given WebNotificationData. |
+ // If all the urls for the resources are empty or invalid, |
+ // |m_completionCallback| will be run synchronously, otherwise it will be |
+ // run asynchronously when all fetches have finished. Should not be called |
+ // 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.
|
+ void start(const WebNotificationData&); |
+ |
+ // Returns a new WebNotificationResources populated with the resources that |
+ // have been fetched. |
+ std::unique_ptr<WebNotificationResources> getResources() const; |
+ |
+ // ContextLifecycleObserver interface. |
+ void contextDestroyed() override; |
+ |
+ DECLARE_VIRTUAL_TRACE(); |
+ |
+private: |
+ void loadImage(const KURL&, |
+ 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.
|
+ void didLoadIcon(const SkBitmap& image); |
+ void didLoadBadge(const SkBitmap& image); |
+ void didLoadActionIcon(size_t actionIndex, const SkBitmap& image); |
+ |
+ // Decrements |m_pendingRequestCount| and runs |m_completionCallback| if |
+ // there are no more pending requests. |
+ void didFinishRequest(); |
+ |
+ // 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.
|
+ void stop(); |
+ |
+ OwnPtr<CompletionCallback> m_completionCallback; |
+ int m_pendingRequestCount; |
+ HeapVector<Member<NotificationImageLoader>> m_imageLoaders; |
+ SkBitmap m_icon; |
+ SkBitmap m_badge; |
+ Vector<SkBitmap> m_actionIcons; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // NotificationResourcesLoader_h |