Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4332)

Unified Diff: chrome/browser/notifier/synced_notification.cc

Issue 11745024: Synced Notification Sync Change Processor (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Synced Notifications - CR changes per Zea and DCheng Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifier/synced_notification.cc
diff --git a/chrome/browser/notifier/synced_notification.cc b/chrome/browser/notifier/synced_notification.cc
new file mode 100644
index 0000000000000000000000000000000000000000..784ab35d4027bb32eb4696d7fe4fb05e5e8016f8
--- /dev/null
+++ b/chrome/browser/notifier/synced_notification.cc
@@ -0,0 +1,229 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifier/synced_notification.h"
+
+#include "sync/protocol/sync.pb.h"
+#include "sync/protocol/synced_notification_specifics.pb.h"
+
+using namespace sync_pb;
+
+namespace {
+const char kExtensionScheme[] = "chrome-extension://";
+} // namespace
+
+namespace notifier {
+
+// An important side effect of the constructor is that it keeps the
+// SyncNotificationSpecifics alive by putting it into the contained sync entity.
+SyncedNotification::SyncedNotification(const syncer::SyncData& sync_data)
+ : sync_data_(sync_data), has_local_changes_(false) {
+}
+
+SyncedNotification::~SyncedNotification() {}
+
+// TODO(petewil): Consider the timestamp too once it gets added to the protobuf.
+bool SyncedNotification::Equals(const SyncedNotification& other) const {
+ // Two notifications are equal if the <appId/coalescingKey> pair matches.
+ return (GetNotificationId() == other.GetNotificationId());
+}
+
+// Set the read state on the notification, returns true for success.
+bool SyncedNotification::SetReadState(
+ sync_pb::SyncedNotificationCoalesced_ReadState readState) {
+ if (!sync_data_.GetSpecifics().synced_notification().
+ has_coalesced_notification())
+ return false;
+
+ // TODO(petewil): implement
+ return true;
+}
+
+// Mark this notification as having been read locally.
+void SyncedNotification::NotificationHasBeenRead() {
+ // We set the is_local_ flag to true since we modified it locally
+ // then we create a sync change object to pass back up.
+ has_local_changes_ = true;
+
+ bool success = SetReadState(
+ sync_pb::SyncedNotificationCoalesced_ReadState_READ);
+ DCHECK(success);
+}
+
+// mark this notification as having been dismissed locally
+void SyncedNotification::NotificationHasBeenDeleted() {
+ // We set the is_deleted_ flag to true since we modified it locally
+ // then we create a sync change object to pass back up.
+ has_local_changes_ = true;
+
+ bool success = SetReadState(
+ sync_pb::SyncedNotificationCoalesced_ReadState_DISMISSED);
+ DCHECK(success);
+}
+
+// TODO(petewil): Consider whether the repeated code below can be re-used.
+// A first attempt to do so failed.
+
+const sync_pb::SyncedNotificationSpecifics*
+SyncedNotification::GetSyncedNotificationSpecifics() {
+ return &(sync_data_.GetSpecifics().synced_notification());
+}
+
+std::string SyncedNotification::GetFirstExternalId() const {
+ if (!sync_data_.GetSpecifics().synced_notification().
+ has_coalesced_notification())
+ return "";
+ if (sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().notification_size() < 1)
+ return "";
+ if (!sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().notification(0).has_external_id())
+ return "";
+
+ return sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().notification(0).external_id();
+}
+
+std::string SyncedNotification::GetTitle() const {
+ if (!sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().has_layout_type())
+ return "";
+
+ const SyncedNotificationRenderInfo_Layout_LayoutType layout_type =
+ sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().layout_type();
+
+ // Depending on the layout type, get the proper title.
+ switch (layout_type) {
+ case SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT: {
+ // If we have title and subtext, get that title.
+ if (!sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().
+ title_and_subtext_data().has_title())
+ return "";
+
+ return sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().
+ title_and_subtext_data().title();
+ }
+
+ case SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_IMAGE: {
+ // If we have title and image, get that title.
+ if (!sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().
+ title_and_image_data().has_title())
+ return "";
+
+ return sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().
+ title_and_image_data().title();
+ }
+ default: {
+ // This is an error case, we should never get here unless the protobuf
+ // is bad, or a new type is introduced and this code does not get updated.
+ DCHECK(false);
+ return "";
+ }
+ }
+}
+
+std::string SyncedNotification::GetAppId() const {
+ if (!sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().id().
+ has_app_id())
+ return "";
+ return sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().id().app_id();
+}
+
+std::string SyncedNotification::GetCoalescingKey() const {
+ if (!sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().id().
+ has_coalescing_key())
+ return "";
+ return sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().id().coalescing_key();
+}
+
+GURL SyncedNotification::GetOriginUrl() const {
+ std::string origin_url(kExtensionScheme);
+ origin_url += GetAppId();
+ return GURL(origin_url);
+}
+
+GURL SyncedNotification::GetIconUrl() const {
+ if (!sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().has_layout_type())
+ return GURL("");
dcheng 2013/01/23 18:39:43 GURL() instead of GURL("")
Pete Williamson 2013/01/24 01:48:11 Done.
+
+ const SyncedNotificationRenderInfo_Layout_LayoutType layout_type =
+ sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().layout_type();
+
+ // Depending on the layout type, get the icon.
+ if (SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT
+ == layout_type) {
+
+ // If we have title and subtext, get that icon.
+ if (!sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().
+ title_and_subtext_data().icon().has_url())
+ return GURL("");
+
+ return GURL(sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().
+ title_and_subtext_data().icon().url());
+
+ }
+ return GURL("");
+}
+
+std::string SyncedNotification::GetBody() const {
+ // If we have subtext data, concatenate the text lines and return it.
+ if (!sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().has_layout_type())
+ return "";
+
+ const SyncedNotificationRenderInfo_Layout_LayoutType layout_type =
+ sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().layout_type();
+
+ // Check if this layout type includes body text.
+ if (SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT
+ == layout_type) {
+
+ // If we have title and subtext, get the text.
+ if (!sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().
+ has_title_and_subtext_data())
+ return "";
+ int subtext_lines = sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().
+ title_and_subtext_data().subtext_size();
+ if (subtext_lines < 1)
+ return "";
+
+ std::string subtext;
+ for (int ii = 0; ii < subtext_lines; ++ii) {
+ subtext += sync_data_.GetSpecifics().synced_notification().
+ coalesced_notification().render_info().layout().
+ title_and_subtext_data().subtext(ii);
+ if ( ii < subtext_lines - 1)
+ subtext += '\n';
+ }
+ return subtext;
+ }
+ return "";
+}
+
+std::string SyncedNotification::GetNotificationId() const {
+ // Append the coalescing key to the app id to get the unique id.
+ std::string id = GetAppId();
+ id += "/";
+ id += GetCoalescingKey();
+
+ return id;
+}
+
+} // namespace notifier

Powered by Google App Engine
This is Rietveld 408576698