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 #include "content/child/notifications/pending_notification.h" | |
6 | |
7 #include "base/barrier_closure.h" | |
8 #include "base/bind.h" | |
9 #include "base/callback.h" | |
10 #include "base/location.h" | |
11 #include "base/thread_task_runner_handle.h" | |
12 #include "content/public/common/notification_resources.h" | |
13 #include "url/gurl.h" | |
14 | |
15 namespace content { | |
16 | |
17 PendingNotification::PendingNotification( | |
18 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | |
19 const blink::WebNotificationData& notification_data, | |
20 const base::Closure& fetches_finished_callback) | |
21 : main_thread_task_runner_(main_thread_task_runner), | |
22 notification_data_(notification_data), | |
23 action_icons_(std::vector<SkBitmap>(notification_data_.actions.size())), | |
Peter Beverloo
2016/02/05 15:43:21
Initialization list declarations will construct th
Michael van Ouwerkerk
2016/02/08 14:38:52
Done.
| |
24 fetches_finished_barrier_closure_(BarrierClosure( | |
Peter Beverloo
2016/02/05 15:43:21
Why don't you have to specify base:: here?
Michael van Ouwerkerk
2016/02/08 14:38:52
Dunno, maybe because it has BASE_EXPORT? Certainly
| |
25 1 /* notification icon */ + notification_data_.actions.size(), | |
26 fetches_finished_callback)), | |
27 weak_factory_(this) {} | |
28 | |
29 PendingNotification::~PendingNotification() {} | |
30 | |
31 void PendingNotification::FetchResources() { | |
32 // TODO(mvanouwerkerk): Add a timeout mechanism: crbug.com/579137 | |
33 FetchImageResource(notification_data_.icon, | |
34 base::Bind(&PendingNotification::DidFetchNotificationIcon, | |
35 weak_factory_.GetWeakPtr())); | |
36 for (size_t i = 0; i < notification_data_.actions.size(); i++) { | |
37 FetchImageResource(notification_data_.actions[i].icon, | |
38 base::Bind(&PendingNotification::DidFetchActionIcon, | |
39 weak_factory_.GetWeakPtr(), i)); | |
40 } | |
41 } | |
42 | |
43 NotificationResources PendingNotification::GetResources() { | |
Peter Beverloo
2016/02/05 15:43:21
This will make a copy of all the resources. Since
Michael van Ouwerkerk
2016/02/08 14:38:52
It's not that bad, the bulky pixel data is thread-
| |
44 NotificationResources resources; | |
45 resources.notification_icon = notification_icon_; | |
46 resources.action_icons = action_icons_; | |
47 return resources; | |
48 } | |
49 | |
50 void PendingNotification::FetchImageResource( | |
51 const blink::WebURL& image_web_url, | |
52 const ImageLoadCompletedCallback& image_callback) { | |
53 if (image_web_url.isEmpty()) { | |
54 image_callback.Run(SkBitmap()); | |
55 return; | |
56 } | |
57 | |
58 // Convert to GURL before sending to the main thread (crbug.com/458640). | |
Peter Beverloo
2016/02/05 15:43:21
Per your request, a suggestion for an updated comm
Michael van Ouwerkerk
2016/02/08 14:38:52
Nice. Done.
| |
59 GURL image_gurl(image_web_url); | |
60 | |
61 scoped_refptr<NotificationImageLoader> image_loader( | |
62 new NotificationImageLoader(image_callback, | |
63 base::ThreadTaskRunnerHandle::Get())); | |
Peter Beverloo
2016/02/05 15:43:21
Something to consider: since we know both the targ
Michael van Ouwerkerk
2016/02/08 14:38:52
Cool. Done.
| |
64 image_loaders_.insert(image_loader); | |
65 main_thread_task_runner_->PostTask( | |
66 FROM_HERE, base::Bind(&NotificationImageLoader::StartOnMainThread, | |
67 image_loader, image_web_url)); | |
68 } | |
69 | |
70 void PendingNotification::DidFetchNotificationIcon( | |
71 const SkBitmap& notification_icon) { | |
72 notification_icon_ = notification_icon; | |
73 fetches_finished_barrier_closure_.Run(); | |
74 } | |
75 | |
76 void PendingNotification::DidFetchActionIcon(size_t action_index, | |
77 const SkBitmap& action_icon) { | |
78 action_icons_[action_index] = action_icon; | |
Peter Beverloo
2016/02/05 15:43:21
DCHECK_LT(action_index, action_icons_.size()); ?
Michael van Ouwerkerk
2016/02/08 14:38:52
Done.
| |
79 fetches_finished_barrier_closure_.Run(); | |
80 } | |
81 | |
82 } // namespace content | |
OLD | NEW |