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 CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATION_H_ | |
6 #define CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATION_H_ | |
7 | |
8 #include <set> | |
9 #include <vector> | |
10 | |
11 #include "base/callback_forward.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "content/child/notifications/notification_image_loader.h" | |
16 #include "third_party/WebKit/public/platform/WebURL.h" | |
17 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" | |
18 #include "third_party/skia/include/core/SkBitmap.h" | |
19 | |
20 namespace base { | |
21 class SingleThreadTaskRunner; | |
22 } | |
23 | |
24 namespace content { | |
25 | |
26 struct NotificationResources; | |
27 | |
28 // Stores the information associated with a pending notification, and fetches | |
29 // resources for it on the main thread. | |
30 class PendingNotification { | |
31 public: | |
32 PendingNotification( | |
33 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | |
34 const blink::WebNotificationData& notification_data, | |
Peter Beverloo
2016/02/05 15:43:21
The only reason that PendingNotification stores th
Michael van Ouwerkerk
2016/02/08 14:38:52
Ugh. The constructor does a bit more than that, an
| |
35 const base::Closure& fetches_finished_callback); | |
36 ~PendingNotification(); | |
37 | |
38 // Fetches all resources asynchronously on the main thread. | |
39 void FetchResources(); | |
40 | |
41 // Returns a new NotificationResources populated with the resources that have | |
42 // been fetched. | |
43 NotificationResources GetResources(); | |
44 | |
45 private: | |
46 // Fetches an image using |image_web_url| asynchronously on the main thread. | |
47 // The |image_callback| will be called on the worker thread. | |
48 void FetchImageResource(const blink::WebURL& image_web_url, | |
49 const ImageLoadCompletedCallback& image_callback); | |
50 | |
51 // To be called on the worker thread when the notification icon has been | |
52 // fetched. | |
53 void DidFetchNotificationIcon(const SkBitmap& notification_icon); | |
54 | |
55 // To be called on the worker thread when an action icon has been fetched. | |
56 void DidFetchActionIcon(size_t action_index, const SkBitmap& action_icon); | |
57 | |
58 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | |
59 | |
60 blink::WebNotificationData notification_data_; | |
61 | |
62 SkBitmap notification_icon_; | |
63 | |
64 std::vector<SkBitmap> action_icons_; | |
65 | |
66 base::Closure fetches_finished_barrier_closure_; | |
67 | |
68 std::set<scoped_refptr<NotificationImageLoader>> image_loaders_; | |
Peter Beverloo
2016/02/05 15:43:21
nit: May as well use a std::vector<> for this, sin
Michael van Ouwerkerk
2016/02/08 14:38:52
Done.
| |
69 | |
70 base::WeakPtrFactory<PendingNotification> weak_factory_; | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(PendingNotification); | |
73 }; | |
74 | |
75 } // namespace content | |
76 | |
77 #endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATION_H_ | |
OLD | NEW |