OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/notifications/sync_notifier/synced_notification.h" | 5 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 // If this URL matches one or more button bitmaps, save them off. | 109 // If this URL matches one or more button bitmaps, save them off. |
110 for (unsigned int i = 0; i < GetButtonCount(); ++i) { | 110 for (unsigned int i = 0; i < GetButtonCount(); ++i) { |
111 if (GetButtonIconUrl(i) == url && bitmap != NULL) | 111 if (GetButtonIconUrl(i) == url && bitmap != NULL) |
112 button_bitmaps_[i] = gfx::Image::CreateFrom1xBitmap(*bitmap); | 112 button_bitmaps_[i] = gfx::Image::CreateFrom1xBitmap(*bitmap); |
113 } | 113 } |
114 | 114 |
115 // Count off the bitmaps as they arrive. | 115 // Count off the bitmaps as they arrive. |
116 --active_fetcher_count_; | 116 --active_fetcher_count_; |
117 DCHECK_GE(active_fetcher_count_, 0); | |
118 // See if all bitmaps are accounted for, if so call Show. | 117 // See if all bitmaps are accounted for, if so call Show. |
119 if (active_fetcher_count_ == 0) { | 118 if (active_fetcher_count_ == 0) { |
120 Show(notification_manager_, notifier_service_, profile_); | 119 Show(notification_manager_, notifier_service_, profile_); |
121 } | 120 } |
122 } | 121 } |
123 | 122 |
124 void SyncedNotification::QueueBitmapFetchJobs( | 123 void SyncedNotification::QueueBitmapFetchJobs( |
125 NotificationUIManager* notification_manager, | 124 NotificationUIManager* notification_manager, |
126 ChromeNotifierService* notifier_service, | 125 ChromeNotifierService* notifier_service, |
127 Profile* profile) { | 126 Profile* profile) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // The delegate will eventually catch calls that the notification | 211 // The delegate will eventually catch calls that the notification |
213 // was read or deleted, and send the changes back to the server. | 212 // was read or deleted, and send the changes back to the server. |
214 scoped_refptr<NotificationDelegate> delegate = | 213 scoped_refptr<NotificationDelegate> delegate = |
215 new ChromeNotifierDelegate(GetKey(), notifier_service); | 214 new ChromeNotifierDelegate(GetKey(), notifier_service); |
216 | 215 |
217 // Some inputs and fields are only used if there is a notification center. | 216 // Some inputs and fields are only used if there is a notification center. |
218 if (UseRichNotifications()) { | 217 if (UseRichNotifications()) { |
219 base::Time creation_time = | 218 base::Time creation_time = |
220 base::Time::FromDoubleT(static_cast<double>(GetCreationTime())); | 219 base::Time::FromDoubleT(static_cast<double>(GetCreationTime())); |
221 int priority = GetPriority(); | 220 int priority = GetPriority(); |
222 int notification_count = GetNotificationCount(); | |
223 unsigned int button_count = GetButtonCount(); | 221 unsigned int button_count = GetButtonCount(); |
224 | 222 |
225 // Deduce which notification template to use from the data. | 223 // Deduce which notification template to use from the data. |
226 message_center::NotificationType notification_type = | 224 message_center::NotificationType notification_type = |
227 message_center::NOTIFICATION_TYPE_BASE_FORMAT; | 225 message_center::NOTIFICATION_TYPE_BASE_FORMAT; |
228 if (!image_url.is_empty()) { | 226 if (!image_url.is_empty()) { |
229 notification_type = message_center::NOTIFICATION_TYPE_IMAGE; | 227 notification_type = message_center::NOTIFICATION_TYPE_IMAGE; |
230 } else if (notification_count > 1) { | |
231 notification_type = message_center::NOTIFICATION_TYPE_MULTIPLE; | |
232 } else if (button_count > 0) { | 228 } else if (button_count > 0) { |
233 notification_type = message_center::NOTIFICATION_TYPE_BASE_FORMAT; | 229 notification_type = message_center::NOTIFICATION_TYPE_BASE_FORMAT; |
234 } | 230 } |
235 | 231 |
236 // Fill the optional fields with the information we need to make a | 232 // Fill the optional fields with the information we need to make a |
237 // notification. | 233 // notification. |
238 message_center::RichNotificationData rich_notification_data; | 234 message_center::RichNotificationData rich_notification_data; |
239 rich_notification_data.timestamp = creation_time; | 235 rich_notification_data.timestamp = creation_time; |
240 if (priority != SyncedNotification::kUndefinedPriority) | 236 if (priority != SyncedNotification::kUndefinedPriority) |
241 rich_notification_data.priority = priority; | 237 rich_notification_data.priority = priority; |
(...skipping 14 matching lines...) Expand all Loading... |
256 message_center::ButtonInfo button_info(UTF8ToUTF16(title)); | 252 message_center::ButtonInfo button_info(UTF8ToUTF16(title)); |
257 if (!button_bitmaps_[i].IsEmpty()) | 253 if (!button_bitmaps_[i].IsEmpty()) |
258 button_info.icon = button_bitmaps_[i]; | 254 button_info.icon = button_bitmaps_[i]; |
259 rich_notification_data.buttons.push_back(button_info); | 255 rich_notification_data.buttons.push_back(button_info); |
260 } | 256 } |
261 | 257 |
262 // Fill in the bitmap images. | 258 // Fill in the bitmap images. |
263 if (!image_bitmap_.IsEmpty()) | 259 if (!image_bitmap_.IsEmpty()) |
264 rich_notification_data.image = image_bitmap_; | 260 rich_notification_data.image = image_bitmap_; |
265 | 261 |
266 // Fill the individual notification fields for a multiple notification. | 262 // Set the ContextMessage inside the rich notification data for the |
267 if (notification_count > 1) { | 263 // annotation. |
268 for (int ii = 0; ii < notification_count; ++ii) { | 264 rich_notification_data.context_message = annotation; |
269 message_center::NotificationItem item( | |
270 UTF8ToUTF16(GetContainedNotificationTitle(ii)), | |
271 UTF8ToUTF16(GetContainedNotificationMessage(ii))); | |
272 rich_notification_data.items.push_back(item); | |
273 } | |
274 } | |
275 | 265 |
276 // The text encompasses both the description and the annotation. | 266 // If there is at least one person sending, use the first picture. |
277 if (!notification_text.empty()) | |
278 notification_text = notification_text + newline; | |
279 notification_text = notification_text + annotation; | |
280 | |
281 // If there is a single person sending, use their picture instead of the app | |
282 // icon. | |
283 // TODO(petewil): Someday combine multiple profile photos here. | 267 // TODO(petewil): Someday combine multiple profile photos here. |
284 gfx::Image icon_bitmap = app_icon_bitmap_; | 268 gfx::Image icon_bitmap = app_icon_bitmap_; |
285 if (GetProfilePictureCount() == 1) { | 269 if (GetProfilePictureCount() >= 1) { |
286 icon_bitmap = sender_bitmap_; | 270 icon_bitmap = sender_bitmap_; |
287 } | 271 } |
288 | 272 |
289 Notification ui_notification(notification_type, | 273 Notification ui_notification(notification_type, |
290 GetOriginUrl(), | 274 GetOriginUrl(), |
291 notification_heading, | 275 notification_heading, |
292 notification_text, | 276 notification_text, |
293 icon_bitmap, | 277 icon_bitmap, |
294 WebKit::WebTextDirectionDefault, | 278 WebKit::WebTextDirectionDefault, |
295 message_center::NotifierId(GetOriginUrl()), | 279 message_center::NotifierId(GetOriginUrl()), |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 | 667 |
684 std::string SyncedNotification::GetSendingServiceId() const { | 668 std::string SyncedNotification::GetSendingServiceId() const { |
685 // TODO(petewil): We are building a new protocol (a new sync datatype) to send | 669 // TODO(petewil): We are building a new protocol (a new sync datatype) to send |
686 // the service name and icon from the server. For now this method is | 670 // the service name and icon from the server. For now this method is |
687 // hardcoded to the name of our first service using synced notifications. | 671 // hardcoded to the name of our first service using synced notifications. |
688 // Once the new protocol is built, remove this hardcoding. | 672 // Once the new protocol is built, remove this hardcoding. |
689 return kFirstSyncedNotificationServiceId; | 673 return kFirstSyncedNotificationServiceId; |
690 } | 674 } |
691 | 675 |
692 } // namespace notifier | 676 } // namespace notifier |
OLD | NEW |