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

Side by Side Diff: content/child/notifications/pending_notification.cc

Issue 1750083004: Add badge to web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/notifications/pending_notification.h" 5 #include "content/child/notifications/pending_notification.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 PendingNotification::~PendingNotification() {} 44 PendingNotification::~PendingNotification() {}
45 45
46 void PendingNotification::FetchResources( 46 void PendingNotification::FetchResources(
47 const blink::WebNotificationData& notification_data, 47 const blink::WebNotificationData& notification_data,
48 const base::Closure& fetches_finished_callback) { 48 const base::Closure& fetches_finished_callback) {
49 // TODO(mvanouwerkerk): Add a timeout mechanism: crbug.com/579137 49 // TODO(mvanouwerkerk): Add a timeout mechanism: crbug.com/579137
50 50
51 size_t num_actions = notification_data.actions.size(); 51 size_t num_actions = notification_data.actions.size();
52 action_icons_.resize(num_actions); 52 action_icons_.resize(num_actions);
53 53
54 size_t num_closures = 1 /* notification icon */ + num_actions; 54 size_t num_closures = 2 /* notification icon and small icon */ + num_actions;
55 fetches_finished_barrier_closure_ = 55 fetches_finished_barrier_closure_ =
56 base::BarrierClosure(num_closures, fetches_finished_callback); 56 base::BarrierClosure(num_closures, fetches_finished_callback);
57 57
58 FetchImageResource(notification_data.icon, 58 FetchImageResource(notification_data.icon,
59 base::Bind(&PendingNotification::DidFetchNotificationIcon, 59 base::Bind(&PendingNotification::DidFetchNotificationIcon,
60 weak_factory_.GetWeakPtr())); 60 weak_factory_.GetWeakPtr()));
61 FetchImageResource(notification_data.smallIcon,
62 base::Bind(&PendingNotification::DidFetchSmallIcon,
63 weak_factory_.GetWeakPtr()));
61 for (size_t i = 0; i < num_actions; i++) { 64 for (size_t i = 0; i < num_actions; i++) {
62 FetchImageResource(notification_data.actions[i].icon, 65 FetchImageResource(notification_data.actions[i].icon,
63 base::Bind(&PendingNotification::DidFetchActionIcon, 66 base::Bind(&PendingNotification::DidFetchActionIcon,
64 weak_factory_.GetWeakPtr(), i)); 67 weak_factory_.GetWeakPtr(), i));
65 } 68 }
66 } 69 }
67 70
68 NotificationResources PendingNotification::GetResources() const { 71 NotificationResources PendingNotification::GetResources() const {
69 NotificationResources resources; 72 NotificationResources resources;
70 resources.notification_icon = notification_icon_; 73 resources.notification_icon = notification_icon_;
74 resources.small_icon = small_icon_;
71 resources.action_icons = action_icons_; 75 resources.action_icons = action_icons_;
72 return resources; 76 return resources;
73 } 77 }
74 78
75 void PendingNotification::FetchImageResource( 79 void PendingNotification::FetchImageResource(
76 const blink::WebURL& image_web_url, 80 const blink::WebURL& image_web_url,
77 const ImageLoadCompletedCallback& image_callback) { 81 const ImageLoadCompletedCallback& image_callback) {
78 if (image_web_url.isEmpty()) { 82 if (image_web_url.isEmpty()) {
79 image_callback.Run(SkBitmap()); 83 image_callback.Run(SkBitmap());
80 return; 84 return;
(...skipping 14 matching lines...) Expand all
95 FROM_HERE, base::Bind(&NotificationImageLoader::StartOnMainThread, 99 FROM_HERE, base::Bind(&NotificationImageLoader::StartOnMainThread,
96 image_loader, image_gurl)); 100 image_loader, image_gurl));
97 } 101 }
98 102
99 void PendingNotification::DidFetchNotificationIcon(const SkBitmap& icon) { 103 void PendingNotification::DidFetchNotificationIcon(const SkBitmap& icon) {
100 notification_icon_ = 104 notification_icon_ =
101 ScaleDownIfNeeded(icon, kPlatformNotificationMaxIconSizePx); 105 ScaleDownIfNeeded(icon, kPlatformNotificationMaxIconSizePx);
102 fetches_finished_barrier_closure_.Run(); 106 fetches_finished_barrier_closure_.Run();
103 } 107 }
104 108
109 void PendingNotification::DidFetchSmallIcon(const SkBitmap& icon) {
110 small_icon_ =
111 ScaleDownIfNeeded(icon, kPlatformNotificationMaxSmallIconSizePx);
112 fetches_finished_barrier_closure_.Run();
113 }
114
105 void PendingNotification::DidFetchActionIcon(size_t action_index, 115 void PendingNotification::DidFetchActionIcon(size_t action_index,
106 const SkBitmap& icon) { 116 const SkBitmap& icon) {
107 DCHECK_LT(action_index, action_icons_.size()); 117 DCHECK_LT(action_index, action_icons_.size());
108 118
109 action_icons_[action_index] = 119 action_icons_[action_index] =
110 ScaleDownIfNeeded(icon, kPlatformNotificationMaxActionIconSizePx); 120 ScaleDownIfNeeded(icon, kPlatformNotificationMaxActionIconSizePx);
111 fetches_finished_barrier_closure_.Run(); 121 fetches_finished_barrier_closure_.Run();
112 } 122 }
113 123
114 } // namespace content 124 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698