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