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/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 return app_icon_ready && images_ready && sender_picture_ready && | 114 return app_icon_ready && images_ready && sender_picture_ready && |
115 button_bitmaps_ready; | 115 button_bitmaps_ready; |
116 } | 116 } |
117 | 117 |
118 // TODO(petewil): The fetch mechanism appears to be returning two bitmaps on the | 118 // TODO(petewil): The fetch mechanism appears to be returning two bitmaps on the |
119 // mac - perhaps one is regular, one is high dpi? If so, ensure we use the high | 119 // mac - perhaps one is regular, one is high dpi? If so, ensure we use the high |
120 // dpi bitmap when appropriate. | 120 // dpi bitmap when appropriate. |
121 void SyncedNotification::OnFetchComplete(const GURL url, | 121 void SyncedNotification::OnFetchComplete(const GURL url, |
122 const SkBitmap* bitmap) { | 122 const SkBitmap* bitmap) { |
123 // TODO(petewil): Add timeout mechanism in case bitmaps take too long. Do we | |
124 // already have one built into URLFetcher? | |
125 // Make sure we are on the thread we expect. | 123 // Make sure we are on the thread we expect. |
126 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 124 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
127 | 125 |
128 gfx::Image downloaded_image; | 126 gfx::Image downloaded_image; |
129 if (bitmap != NULL) | 127 if (bitmap != NULL) |
130 downloaded_image = gfx::Image::CreateFrom1xBitmap(*bitmap); | 128 downloaded_image = gfx::Image::CreateFrom1xBitmap(*bitmap); |
131 | 129 |
132 // Match the incoming bitmaps to URLs. In case this is a dup, make sure to | 130 // Match the incoming bitmaps to URLs. In case this is a dup, make sure to |
133 // try all potentially matching urls. | 131 // try all potentially matching urls. |
134 if (GetAppIconUrl() == url) { | 132 if (GetAppIconUrl() == url) { |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 notification_manager->Add(ui_notification, profile); | 377 notification_manager->Add(ui_notification, profile); |
380 } | 378 } |
381 | 379 |
382 DVLOG(1) << "Showing Synced Notification! " << heading << " " << text | 380 DVLOG(1) << "Showing Synced Notification! " << heading << " " << text |
383 << " " << GetAppIconUrl() << " " << replace_key << " " | 381 << " " << GetAppIconUrl() << " " << replace_key << " " |
384 << GetProfilePictureUrl(0) << " " << GetReadState(); | 382 << GetProfilePictureUrl(0) << " " << GetReadState(); |
385 | 383 |
386 return; | 384 return; |
387 } | 385 } |
388 | 386 |
| 387 // Display the notification if it has the specified app_id_name. |
| 388 void SyncedNotification::ShowIfNewlyEnabled( |
| 389 NotificationUIManager* notification_manager, |
| 390 ChromeNotifierService* notifier_service, |
| 391 Profile* profile, |
| 392 std::string app_id_name) { |
| 393 if (app_id_name == GetAppId()) |
| 394 Show(notification_manager, notifier_service, profile); |
| 395 } |
| 396 |
| 397 // Remove the notification if it has the specified app_id_name. |
| 398 void SyncedNotification::HideIfNewlyRemoved( |
| 399 NotificationUIManager* notification_manager, |
| 400 ChromeNotifierService* notifier_service, |
| 401 Profile* profile, |
| 402 std::string app_id_name) { |
| 403 if (app_id_name == GetAppId()) { |
| 404 notification_manager->CancelById(GetKey()); |
| 405 } |
| 406 } |
| 407 |
389 // This should detect even small changes in case the server updated the | 408 // This should detect even small changes in case the server updated the |
390 // notification. We ignore the timestamp if other fields match. | 409 // notification. We ignore the timestamp if other fields match. |
391 bool SyncedNotification::EqualsIgnoringReadState( | 410 bool SyncedNotification::EqualsIgnoringReadState( |
392 const SyncedNotification& other) const { | 411 const SyncedNotification& other) const { |
393 if (GetTitle() == other.GetTitle() && | 412 if (GetTitle() == other.GetTitle() && |
394 GetHeading() == other.GetHeading() && | 413 GetHeading() == other.GetHeading() && |
395 GetDescription() == other.GetDescription() && | 414 GetDescription() == other.GetDescription() && |
396 GetAnnotation() == other.GetAnnotation() && | 415 GetAnnotation() == other.GetAnnotation() && |
397 GetAppId() == other.GetAppId() && | 416 GetAppId() == other.GetAppId() && |
398 GetKey() == other.GetKey() && | 417 GetKey() == other.GetKey() && |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 std::string SyncedNotification::GetContainedNotificationMessage( | 758 std::string SyncedNotification::GetContainedNotificationMessage( |
740 int index) const { | 759 int index) const { |
741 if (specifics_.coalesced_notification().render_info().expanded_info(). | 760 if (specifics_.coalesced_notification().render_info().expanded_info(). |
742 collapsed_info_size() < index + 1) | 761 collapsed_info_size() < index + 1) |
743 return std::string(); | 762 return std::string(); |
744 | 763 |
745 return specifics_.coalesced_notification().render_info().expanded_info(). | 764 return specifics_.coalesced_notification().render_info().expanded_info(). |
746 collapsed_info(index).simple_collapsed_layout().description(); | 765 collapsed_info(index).simple_collapsed_layout().description(); |
747 } | 766 } |
748 | 767 |
749 std::string SyncedNotification::GetSendingServiceId() const { | |
750 // TODO(petewil): We are building a new protocol (a new sync datatype) to send | |
751 // the service name and icon from the server. For now this method is | |
752 // hardcoded to the name of our first service using synced notifications. | |
753 // Once the new protocol is built, remove this hardcoding. | |
754 return kFirstSyncedNotificationServiceId; | |
755 } | |
756 | |
757 const gfx::Image& SyncedNotification::GetAppIcon() const { | 768 const gfx::Image& SyncedNotification::GetAppIcon() const { |
758 return app_icon_bitmap_; | 769 return app_icon_bitmap_; |
759 } | 770 } |
760 | 771 |
761 void SyncedNotification::SetToastState(bool toast_state) { | 772 void SyncedNotification::SetToastState(bool toast_state) { |
762 toast_state_ = toast_state; | 773 toast_state_ = toast_state; |
763 } | 774 } |
764 | 775 |
765 } // namespace notifier | 776 } // namespace notifier |
OLD | NEW |