Chromium Code Reviews| Index: chrome/browser/notifications/sync_notifier/synced_notification.cc |
| diff --git a/chrome/browser/notifications/sync_notifier/synced_notification.cc b/chrome/browser/notifications/sync_notifier/synced_notification.cc |
| index 951a50d98d455159f0237e14b805eb3b02409ce7..dc9b778f92473d82d3ecd3e6c387d2c5174cd82f 100644 |
| --- a/chrome/browser/notifications/sync_notifier/synced_notification.cc |
| +++ b/chrome/browser/notifications/sync_notifier/synced_notification.cc |
| @@ -33,6 +33,7 @@ SyncedNotification::SyncedNotification(const syncer::SyncData& sync_data) { |
| SyncedNotification::~SyncedNotification() {} |
| void SyncedNotification::Update(const syncer::SyncData& sync_data) { |
| + // TODO(petewil): Let's add checking that the notification looks valid. |
| specifics_.CopyFrom(sync_data.GetSpecifics().synced_notification()); |
| } |
| @@ -74,14 +75,6 @@ GURL SyncedNotification::image_url() const { |
| return ExtractImageUrl(); |
| } |
| -std::string SyncedNotification::first_external_id() const { |
| - return ExtractFirstExternalId(); |
| -} |
| - |
| -std::string SyncedNotification::notification_id() const { |
| - return ExtractNotificationId(); |
| -} |
| - |
| std::string SyncedNotification::text() const { |
| return ExtractText(); |
| } |
| @@ -90,7 +83,69 @@ SyncedNotification::ReadState SyncedNotification::read_state() const { |
| return ExtractReadState(); |
| } |
| +uint64 SyncedNotification::creation_time() const { |
| + return ExtractCreationTime(); |
| +} |
| + |
| +std::string SyncedNotification::default_destination_title() const { |
| + return ExtractDefaultDestinationTitle(); |
| +} |
| + |
| +std::string SyncedNotification::default_destination_icon_url() const { |
| + return ExtractDefaultDestinationIconUrl(); |
| +} |
| + |
| +std::string SyncedNotification::default_destination_url() const { |
| + return ExtractDefaultDestinationUrl(); |
| +} |
| + |
| +std::string SyncedNotification::button_one_title() const { |
| + return ExtractButtonOneTitle(); |
| +} |
| + |
| +std::string SyncedNotification::button_one_icon_url() const { |
| + return ExtractButtonOneIconUrl(); |
| +} |
| + |
| +std::string SyncedNotification::button_one_url() const { |
| + return ExtractButtonOneUrl(); |
| +} |
| + |
| +std::string SyncedNotification::button_two_title() const { |
| + return ExtractButtonTwoTitle(); |
| +} |
| + |
| +std::string SyncedNotification::button_two_icon_url() const { |
| + return ExtractButtonTwoIconUrl(); |
| +} |
| + |
| +std::string SyncedNotification::button_two_url() const { |
| + return ExtractButtonTwoUrl(); |
| +} |
| + |
| +int SyncedNotification::priority() const { |
| + return ExtractPriority(); |
| +} |
| + |
| +int SyncedNotification::button_count() const { |
| + return ExtractButtonCount(); |
| +} |
| + |
| +int SyncedNotification::notification_count() const { |
| + return ExtractNotificationCount(); |
| +} |
| + |
| +std::string SyncedNotification::contained_notification_title(int index) const { |
| + return ExtractContainedNotificationTitle(index); |
| +} |
| + |
| +std::string SyncedNotification::contained_notification_message( |
| + int index) const { |
| + return ExtractContainedNotificationMessage(index); |
| +} |
| + |
| // TODO(petewil): Consider the timestamp too once it gets added to the protobuf. |
| +// TODO: add more fields in here |
| bool SyncedNotification::EqualsIgnoringReadState( |
| const SyncedNotification& other) const { |
| return (title() == other.title() && |
| @@ -102,12 +157,6 @@ bool SyncedNotification::EqualsIgnoringReadState( |
| image_url() == other.image_url() ); |
| } |
| -bool SyncedNotification::IdMatches(const SyncedNotification& other) const { |
| - // Two notifications have the same ID if the <appId/coalescingKey> pair |
| - // matches. |
| - return (notification_id() == other.notification_id()); |
| -} |
| - |
| // Set the read state on the notification, returns true for success. |
| void SyncedNotification::SetReadState(const ReadState& read_state) { |
| @@ -125,27 +174,14 @@ void SyncedNotification::SetReadState(const ReadState& read_state) { |
| NOTREACHED(); |
| } |
| -void SyncedNotification::NotificationHasBeenRead() { |
| - SetReadState(kRead); |
| -} |
| - |
| void SyncedNotification::NotificationHasBeenDismissed() { |
| SetReadState(kDismissed); |
| } |
| -std::string SyncedNotification::ExtractFirstExternalId() const { |
| - if (!specifics_.has_coalesced_notification() || |
| - specifics_.coalesced_notification().notification_size() < 1 || |
| - !specifics_.coalesced_notification().notification(0).has_external_id()) |
| - return std::string(); |
| - |
| - return specifics_.coalesced_notification().notification(0).external_id(); |
| -} |
| - |
| std::string SyncedNotification::ExtractTitle() const { |
| if (!specifics_.coalesced_notification().render_info().expanded_info(). |
| simple_expanded_layout().has_title()) |
| - return ""; |
| + return std::string(); |
| return specifics_.coalesced_notification().render_info().expanded_info(). |
| simple_expanded_layout().title(); |
| @@ -154,7 +190,7 @@ std::string SyncedNotification::ExtractTitle() const { |
| std::string SyncedNotification::ExtractHeading() const { |
| if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| simple_collapsed_layout().has_heading()) |
| - return ""; |
| + return std::string(); |
| return specifics_.coalesced_notification().render_info().collapsed_info(). |
| simple_collapsed_layout().heading(); |
| @@ -163,7 +199,7 @@ std::string SyncedNotification::ExtractHeading() const { |
| std::string SyncedNotification::ExtractDescription() const { |
| if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| simple_collapsed_layout().has_description()) |
| - return ""; |
| + return std::string(); |
| return specifics_.coalesced_notification().render_info().collapsed_info(). |
| simple_collapsed_layout().description(); |
| @@ -171,13 +207,13 @@ std::string SyncedNotification::ExtractDescription() const { |
| std::string SyncedNotification::ExtractAppId() const { |
| if (!specifics_.coalesced_notification().has_app_id()) |
| - return ""; |
| + return std::string(); |
| return specifics_.coalesced_notification().app_id(); |
| } |
| std::string SyncedNotification::ExtractKey() const { |
| if (!specifics_.coalesced_notification().has_key()) |
| - return ""; |
| + return std::string(); |
| return specifics_.coalesced_notification().key(); |
| } |
| @@ -187,6 +223,8 @@ GURL SyncedNotification::ExtractOriginUrl() const { |
| return GURL(origin_url); |
| } |
| +// TODO(petewil): This only returns the first icon. We should make all the |
| +// icons available. |
| GURL SyncedNotification::ExtractAppIconUrl() const { |
| if (specifics_.coalesced_notification().render_info().expanded_info(). |
| collapsed_info_size() == 0) |
| @@ -219,7 +257,7 @@ GURL SyncedNotification::ExtractImageUrl() const { |
| std::string SyncedNotification::ExtractText() const { |
| if (!specifics_.coalesced_notification().render_info().expanded_info(). |
| simple_expanded_layout().has_text()) |
| - return ""; |
| + return std::string(); |
| return specifics_.coalesced_notification().render_info().expanded_info(). |
| simple_expanded_layout().text(); |
| @@ -246,8 +284,153 @@ SyncedNotification::ReadState SyncedNotification::ExtractReadState() const { |
| } |
| } |
| -std::string SyncedNotification::ExtractNotificationId() const { |
| - return key(); |
| +// Time in milliseconds since the unix epoch, or 0 if not available. |
| +uint64 SyncedNotification::ExtractCreationTime() const { |
| + uint64 creation_time_milliseconds; |
| + |
| + if (!specifics_.coalesced_notification().has_creation_time_msec()) |
| + return 0.0; |
|
dcheng
2013/03/26 17:49:29
return 0 is sufficient here.
Pete Williamson
2013/03/27 17:07:53
Done.
|
| + |
| + creation_time_milliseconds = specifics_.coalesced_notification(). |
|
dcheng
2013/03/26 17:49:29
return directly.
Pete Williamson
2013/03/27 17:07:53
Done.
|
| + creation_time_msec(); |
| + |
| + return creation_time_milliseconds; |
| +} |
| + |
| +int SyncedNotification::ExtractPriority() const { |
| + if (!specifics_.coalesced_notification().has_priority()) |
| + return 0; |
| + return static_cast<int>(specifics_.coalesced_notification(). |
| + priority()); |
| +} |
| + |
| +int SyncedNotification::ExtractNotificationCount() const { |
| + return specifics_.coalesced_notification().render_info(). |
| + expanded_info().collapsed_info_size(); |
| +} |
| + |
| +int SyncedNotification::ExtractButtonCount() const { |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target_size(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractDefaultDestinationTitle() const { |
| + if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| + default_destination().icon().has_alt_text()) { |
| + return std::string(); |
| + } |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + default_destination().icon().alt_text(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractDefaultDestinationIconUrl() const { |
| + if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| + default_destination().icon().has_url()) { |
| + return std::string(); |
| + } |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + default_destination().icon().url(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractDefaultDestinationUrl() const { |
| + if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| + default_destination().has_url()) { |
| + return std::string(); |
| + } |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + default_destination().url(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractButtonOneTitle() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (ExtractButtonCount() < 1) |
| + return std::string(); |
| + if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(0).action().icon().has_alt_text()) { |
| + return std::string(); |
| + } |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(0).action().icon().alt_text(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractButtonOneIconUrl() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (ExtractButtonCount() < 1) |
| + return std::string(); |
| + if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(0).action().icon().has_url()) { |
| + return std::string(); |
| + } |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(0).action().icon().url(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractButtonOneUrl() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (ExtractButtonCount() < 1) |
| + return std::string(); |
| + if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(0).action().has_url()) { |
| + return std::string(); |
| + } |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(0).action().url(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractButtonTwoTitle() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (ExtractButtonCount() < 2) |
| + return std::string(); |
| + if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(1).action().icon().has_alt_text()) { |
| + return std::string(); |
| + } |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(1).action().icon().alt_text(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractButtonTwoIconUrl() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (ExtractButtonCount() < 2) |
| + return std::string(); |
| + if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(1).action().icon().has_url()) { |
| + return std::string(); |
| + } |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(1).action().icon().url(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractButtonTwoUrl() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (ExtractButtonCount() < 2) |
| + return std::string(); |
| + if (!specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(1).action().has_url()) { |
| + return std::string(); |
| + } |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target(1).action().url(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractContainedNotificationTitle( |
| + int index) const { |
| + if (specifics_.coalesced_notification().render_info().expanded_info(). |
| + collapsed_info_size() < index + 1) |
| + return std::string(); |
| + |
| + return specifics_.coalesced_notification().render_info().expanded_info(). |
| + collapsed_info(index).simple_collapsed_layout().heading(); |
| +} |
| + |
| +std::string SyncedNotification::ExtractContainedNotificationMessage( |
| + int index) const { |
| + if (specifics_.coalesced_notification().render_info().expanded_info(). |
| + collapsed_info_size() < index + 1) |
| + return std::string(); |
| + |
| + return specifics_.coalesced_notification().render_info().expanded_info(). |
| + collapsed_info(index).simple_collapsed_layout().description(); |
| } |
| } // namespace notifier |