Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: third_party/WebKit/Source/modules/notifications/NotificationResourcesLoader.h

Issue 1847863002: Move notification resource loading from content/child to blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address peter's comments. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "modules/ModulesExport.h"
9 #include "modules/notifications/NotificationImageLoader.h"
10 #include "platform/heap/GarbageCollected.h"
11 #include "platform/heap/Handle.h"
12 #include "platform/heap/HeapAllocator.h"
13 #include "platform/heap/ThreadState.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "wtf/Functional.h"
16 #include "wtf/OwnPtr.h"
17 #include "wtf/PassOwnPtr.h"
18 #include "wtf/Vector.h"
19 #include <memory>
20
21 namespace blink {
22
23 class ExecutionContext;
24 struct WebNotificationData;
25 struct WebNotificationResources;
26
27 // Fetches the resources specified in a given WebNotificationData. Uses a
28 // callback to notify the caller when all fetches have finished.
29 class MODULES_EXPORT NotificationResourcesLoader final : public GarbageCollected Finalized<NotificationResourcesLoader> {
30 USING_PRE_FINALIZER(NotificationResourcesLoader, stop);
31 public:
32 // Called when all fetches have finished. Passes a pointer to the
33 // NotificationResourcesLoader so callers that use multiple loaders can use
34 // the same function to handle the callbacks.
35 using CompletionCallback = Function<void(NotificationResourcesLoader*)>;
36
37 explicit NotificationResourcesLoader(PassOwnPtr<CompletionCallback>);
38 ~NotificationResourcesLoader();
39
40 // Starts fetching the resources specified in the given WebNotificationData.
41 // If all the urls for the resources are empty or invalid,
42 // |m_completionCallback| will be run synchronously, otherwise it will be
43 // run asynchronously when all fetches have finished. Should not be called
44 // more than once.
45 void start(ExecutionContext*, const WebNotificationData&);
46
47 // Returns a new WebNotificationResources populated with the resources that
48 // have been fetched.
49 std::unique_ptr<WebNotificationResources> getResources() const;
50
51 // Stops every loader in |m_imageLoaders|. This is also used as the
52 // pre-finalizer.
53 void stop();
54
55 DECLARE_VIRTUAL_TRACE();
56
57 private:
58 void loadImage(ExecutionContext*, const KURL&, PassOwnPtr<NotificationImageL oader::ImageCallback>);
59 void didLoadIcon(const SkBitmap& image);
60 void didLoadBadge(const SkBitmap& image);
61 void didLoadActionIcon(size_t actionIndex, const SkBitmap& image);
62
63 // Decrements |m_pendingRequestCount| and runs |m_completionCallback| if
64 // there are no more pending requests.
65 void didFinishRequest();
66
67 bool m_started;
68 OwnPtr<CompletionCallback> m_completionCallback;
69 int m_pendingRequestCount;
70 HeapVector<Member<NotificationImageLoader>> m_imageLoaders;
71 SkBitmap m_icon;
72 SkBitmap m_badge;
73 Vector<SkBitmap> m_actionIcons;
74 };
75
76 } // namespace blink
77
78 #endif // NotificationResourcesLoader_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698