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..69dca957671150add7b822b262024bee1e69c176 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()); |
| } |
| @@ -42,70 +43,17 @@ sync_pb::EntitySpecifics SyncedNotification::GetEntitySpecifics() const { |
| return entity_specifics; |
| } |
| -std::string SyncedNotification::title() const { |
| - return ExtractTitle(); |
| -} |
| - |
| -std::string SyncedNotification::heading() const { |
| - return ExtractHeading(); |
| -} |
| - |
| -std::string SyncedNotification::description() const { |
| - return ExtractDescription(); |
| -} |
| - |
| -std::string SyncedNotification::app_id() const { |
| - return ExtractAppId(); |
| -} |
| - |
| -std::string SyncedNotification::key() const { |
| - return ExtractKey(); |
| -} |
| - |
| -GURL SyncedNotification::origin_url() const { |
| - return ExtractOriginUrl(); |
| -} |
| - |
| -GURL SyncedNotification::app_icon_url() const { |
| - return ExtractAppIconUrl(); |
| -} |
| - |
| -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(); |
| -} |
| - |
| -SyncedNotification::ReadState SyncedNotification::read_state() const { |
| - return ExtractReadState(); |
| -} |
| - |
| // 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() && |
| - app_id() == other.app_id() && |
| - key() == other.key() && |
| - text() == other.text() && |
| - origin_url() == other.origin_url() && |
| - app_icon_url() == other.app_icon_url() && |
| - 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()); |
| + return (GetTitle() == other.GetTitle() && |
| + GetAppId() == other.GetAppId() && |
| + GetKey() == other.GetKey() && |
| + GetText() == other.GetText() && |
| + GetOriginUrl() == other.GetOriginUrl() && |
| + GetAppIconUrl() == other.GetAppIconUrl() && |
| + GetImageUrl() == other.GetImageUrl() ); |
| } |
| // Set the read state on the notification, returns true for success. |
| @@ -125,69 +73,58 @@ 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 { |
| +std::string SyncedNotification::GetTitle() 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(); |
| } |
| -std::string SyncedNotification::ExtractHeading() const { |
| +std::string SyncedNotification::GetHeading() 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(); |
| } |
| -std::string SyncedNotification::ExtractDescription() const { |
| +std::string SyncedNotification::GetDescription() 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(); |
| } |
| -std::string SyncedNotification::ExtractAppId() const { |
| +std::string SyncedNotification::GetAppId() const { |
| if (!specifics_.coalesced_notification().has_app_id()) |
| - return ""; |
| + return std::string(); |
| return specifics_.coalesced_notification().app_id(); |
| } |
| -std::string SyncedNotification::ExtractKey() const { |
| +std::string SyncedNotification::GetKey() const { |
| if (!specifics_.coalesced_notification().has_key()) |
| - return ""; |
| + return std::string(); |
| return specifics_.coalesced_notification().key(); |
| } |
| -GURL SyncedNotification::ExtractOriginUrl() const { |
| +GURL SyncedNotification::GetOriginUrl() const { |
| std::string origin_url(kExtensionScheme); |
| - origin_url += app_id(); |
| + origin_url += GetAppId(); |
| return GURL(origin_url); |
| } |
| -GURL SyncedNotification::ExtractAppIconUrl() const { |
| +// TODO(petewil): This only returns the first icon. We should make all the |
| +// icons available. |
| +GURL SyncedNotification::GetAppIconUrl() const { |
| if (specifics_.coalesced_notification().render_info().expanded_info(). |
| collapsed_info_size() == 0) |
| return GURL(); |
| @@ -203,7 +140,7 @@ GURL SyncedNotification::ExtractAppIconUrl() const { |
| // TODO(petewil): This currenly only handles the first image from the first |
| // collapsed item, someday return all images. |
| -GURL SyncedNotification::ExtractImageUrl() const { |
| +GURL SyncedNotification::GetImageUrl() const { |
| if (specifics_.coalesced_notification().render_info().expanded_info(). |
| simple_expanded_layout().media_size() == 0) |
| return GURL(); |
| @@ -216,16 +153,16 @@ GURL SyncedNotification::ExtractImageUrl() const { |
| expanded_info().simple_expanded_layout().media(0).image().url()); |
| } |
| -std::string SyncedNotification::ExtractText() const { |
| +std::string SyncedNotification::GetText() 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(); |
| } |
| -SyncedNotification::ReadState SyncedNotification::ExtractReadState() const { |
| +SyncedNotification::ReadState SyncedNotification::GetReadState() const { |
| DCHECK(specifics_.coalesced_notification().has_read_state()); |
| sync_pb::CoalescedSyncedNotification_ReadState found_read_state = |
| @@ -246,8 +183,148 @@ 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::GetCreationTime() const { |
| + if (!specifics_.coalesced_notification().has_creation_time_msec()) |
| + return 0; |
| + |
| + return specifics_.coalesced_notification().creation_time_msec(); |
| +} |
| + |
| +int SyncedNotification::GetPriority() const { |
| + if (!specifics_.coalesced_notification().has_priority()) |
| + return 0; |
|
miket_OOO
2013/03/28 01:03:52
See https://code.google.com/p/chromium/codesearch#
Pete Williamson
2013/03/28 17:16:12
Actually that brings up a bigger problem, the enum
|
| + return static_cast<int>(specifics_.coalesced_notification(). |
| + priority()); |
| +} |
| + |
| +int SyncedNotification::GetNotificationCount() const { |
| + return specifics_.coalesced_notification().render_info(). |
| + expanded_info().collapsed_info_size(); |
| +} |
| + |
| +int SyncedNotification::GetButtonCount() const { |
| + return specifics_.coalesced_notification().render_info().collapsed_info(). |
| + target_size(); |
| +} |
| + |
| +std::string SyncedNotification::GetDefaultDestinationTitle() 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::GetDefaultDestinationIconUrl() 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::GetDefaultDestinationUrl() 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::GetButtonOneTitle() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (GetButtonCount() < 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::GetButtonOneIconUrl() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (GetButtonCount() < 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::GetButtonOneUrl() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (GetButtonCount() < 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::GetButtonTwoTitle() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (GetButtonCount() < 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::GetButtonTwoIconUrl() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (GetButtonCount() < 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::GetButtonTwoUrl() const { |
| + // Must ensure that we have a target before trying to access it. |
| + if (GetButtonCount() < 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::GetContainedNotificationTitle( |
| + 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::GetContainedNotificationMessage( |
| + 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 |