Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/notifier/synced_notification.h" | |
| 6 | |
| 7 #include "sync/protocol/sync.pb.h" | |
| 8 #include "sync/protocol/synced_notification_specifics.pb.h" | |
| 9 | |
| 10 using namespace sync_pb; | |
| 11 | |
| 12 SyncedNotification::SyncedNotification(const syncer::SyncData sync_data) | |
| 13 : sync_data_(sync_data), has_local_changes_(false) { | |
| 14 } | |
| 15 | |
| 16 SyncedNotification::~SyncedNotification() {} | |
| 17 | |
| 18 void SyncedNotification::NotificationHasBeenRead() { | |
| 19 // We set the is_local_ flag to true since we modified it locally | |
| 20 // then we create a sync change object to pass back up | |
| 21 // TODO(petewil): Implement. | |
| 22 } | |
| 23 | |
| 24 void SyncedNotification::NotificationHasBeenDeleted() { | |
| 25 // We set the is_deleted_ flag to true since we modified it locally | |
| 26 // then we create a sync change object to pass back up. | |
| 27 // TODO(petewil): Implement. | |
| 28 } | |
| 29 | |
| 30 // TODO(petewil): Consider whether the repeated code below can be re-used. | |
| 31 // A first attempt to do so failed. | |
| 32 | |
| 33 const SyncedNotificationSpecifics* | |
| 34 SyncedNotification::GetSyncedNotificationSpecifics() { | |
| 35 return &(sync_data_.GetSpecifics().synced_notification()); | |
| 36 } | |
| 37 | |
| 38 const std::string SyncedNotification::get_first_external_id() const { | |
| 39 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 40 has_coalesced_notification()) | |
| 41 return ""; | |
| 42 if (sync_data_.GetSpecifics().synced_notification(). | |
| 43 coalesced_notification().notification_size() < 1) | |
| 44 return ""; | |
| 45 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 46 coalesced_notification().notification(0).has_external_id()) | |
| 47 return ""; | |
| 48 | |
| 49 return sync_data_.GetSpecifics().synced_notification(). | |
| 50 coalesced_notification().notification(0).external_id(); | |
| 51 } | |
| 52 | |
| 53 const std::string SyncedNotification::title() const { | |
| 54 | |
|
dcheng
2013/01/07 20:42:10
Remove extra newlines at the beginning of all bloc
Pete Williamson
2013/01/18 18:58:39
Done.
| |
| 55 if (!sync_data_.GetSpecifics().synced_notification(). | |
|
dcheng
2013/01/07 20:42:10
1) This seems overly complicated. I think a high l
Pete Williamson
2013/01/18 18:58:39
All functions renamed so they no longer have a nam
dcheng
2013/01/18 21:56:13
Sure but we can still change it at this point in t
Pete Williamson
2013/01/23 01:45:55
I used Nicolas's idea to eliminate a lot of the ex
| |
| 56 has_coalesced_notification()) | |
| 57 return ""; | |
| 58 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 59 coalesced_notification().has_render_info()) | |
| 60 return ""; | |
| 61 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 62 coalesced_notification().render_info().has_layout()) | |
| 63 return ""; | |
| 64 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 65 coalesced_notification().render_info().layout().has_layout_type()) | |
| 66 return ""; | |
| 67 | |
| 68 const RenderInfo_Layout_LayoutType layout_type = | |
| 69 sync_data_.GetSpecifics().synced_notification(). | |
| 70 coalesced_notification().render_info().layout().layout_type(); | |
| 71 | |
| 72 // Depending on the layout type, get the proper title. | |
| 73 if (RenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT == layout_type) { | |
| 74 | |
| 75 // If we have title and subtext, get that title. | |
| 76 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 77 coalesced_notification().render_info().layout(). | |
| 78 has_title_and_subtext_data()) | |
| 79 return ""; | |
| 80 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 81 coalesced_notification().render_info().layout(). | |
| 82 title_and_subtext_data().has_title()) | |
| 83 return ""; | |
| 84 | |
| 85 // We have a title after all, return it. | |
| 86 return sync_data_.GetSpecifics().synced_notification(). | |
| 87 coalesced_notification().render_info().layout(). | |
| 88 title_and_subtext_data().title(); | |
| 89 | |
| 90 } else if (RenderInfo_Layout_LayoutType_TITLE_AND_IMAGE == layout_type) { | |
| 91 | |
| 92 // If we have title and image, get that title. | |
| 93 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 94 coalesced_notification().render_info().layout(). | |
| 95 has_title_and_image_data()) | |
| 96 return ""; | |
| 97 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 98 coalesced_notification().render_info().layout(). | |
| 99 title_and_image_data().has_title()) | |
| 100 return ""; | |
| 101 | |
| 102 // We have a title after all, return it. | |
| 103 return sync_data_.GetSpecifics().synced_notification(). | |
| 104 coalesced_notification().render_info().layout(). | |
| 105 title_and_image_data().title(); | |
| 106 } else { | |
| 107 // This is an error case, we should never get here unless the protobuf | |
| 108 // is bad, or a new type is introduced and this code does not get updated. | |
| 109 DCHECK(false); | |
| 110 return ""; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 const std::string SyncedNotification::app_id() const { | |
|
dcheng
2013/01/07 20:42:10
Similar comment about incorrect naming (these are
Pete Williamson
2013/01/18 18:58:39
Done.
| |
| 115 | |
| 116 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 117 has_coalesced_notification()) | |
| 118 return ""; | |
| 119 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 120 coalesced_notification().has_id()) | |
| 121 return ""; | |
| 122 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 123 coalesced_notification().id(). | |
| 124 has_app_id()) | |
| 125 return ""; | |
| 126 return sync_data_.GetSpecifics().synced_notification(). | |
| 127 coalesced_notification().id().app_id(); | |
| 128 } | |
| 129 | |
| 130 const std::string SyncedNotification::coalescing_key() const { | |
| 131 | |
| 132 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 133 has_coalesced_notification()) | |
| 134 return ""; | |
| 135 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 136 coalesced_notification().has_id()) | |
| 137 return ""; | |
| 138 if (!sync_data_.GetSpecifics().synced_notification(). | |
| 139 coalesced_notification().id(). | |
| 140 has_coalescing_key()) | |
| 141 return ""; | |
| 142 return sync_data_.GetSpecifics().synced_notification(). | |
| 143 coalesced_notification().id().coalescing_key(); | |
| 144 } | |
| 145 | |
| OLD | NEW |