summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/syncable
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-29 01:35:29 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-29 01:35:29 +0000
commit8d23b0ea77c6831eed69409deafe8249a42ffbba (patch)
tree8b98d5cee9373ffab617075cc2fc706f1a2fdd8d /chrome/browser/sync/syncable
parent270816d4315f238291ecffe9d617b1927b25f172 (diff)
downloadchromium_src-8d23b0ea77c6831eed69409deafe8249a42ffbba.zip
chromium_src-8d23b0ea77c6831eed69409deafe8249a42ffbba.tar.gz
chromium_src-8d23b0ea77c6831eed69409deafe8249a42ffbba.tar.bz2
Added ModelType <-> server sync type mappings and used them.
BUG=34645 TEST=manual Review URL: http://codereview.chromium.org/2856019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51089 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/syncable')
-rw-r--r--chrome/browser/sync/syncable/model_type.cc78
-rw-r--r--chrome/browser/sync/syncable/model_type.h13
2 files changed, 91 insertions, 0 deletions
diff --git a/chrome/browser/sync/syncable/model_type.cc b/chrome/browser/sync/syncable/model_type.cc
index f03373e..4c40498 100644
--- a/chrome/browser/sync/syncable/model_type.cc
+++ b/chrome/browser/sync/syncable/model_type.cc
@@ -132,4 +132,82 @@ std::string ModelTypeToString(ModelType model_type) {
}
}
+// TODO(akalin): Figure out a better way to do these mappings.
+
+namespace {
+const char kBookmarkNotificationType[] = "BOOKMARK";
+const char kPreferenceNotificationType[] = "PREFERENCE";
+const char kPasswordNotificationType[] = "PASSWORD";
+const char kAutofillNotificationType[] = "AUTOFILL";
+const char kThemeNotificationType[] = "THEME";
+const char kTypedUrlNotificationType[] = "TYPED_URL";
+const char kExtensionNotificationType[] = "EXTENSION";
+const char kNigoriNotificationType[] = "NIGORI";
+} // namespace
+
+bool RealModelTypeToNotificationType(ModelType model_type,
+ std::string* notification_type) {
+ switch (model_type) {
+ case BOOKMARKS:
+ *notification_type = kBookmarkNotificationType;
+ return true;
+ case PREFERENCES:
+ *notification_type = kPreferenceNotificationType;
+ return true;
+ case PASSWORDS:
+ *notification_type = kPasswordNotificationType;
+ return true;
+ case AUTOFILL:
+ *notification_type = kAutofillNotificationType;
+ return true;
+ case THEMES:
+ *notification_type = kThemeNotificationType;
+ return true;
+ case TYPED_URLS:
+ *notification_type = kTypedUrlNotificationType;
+ return true;
+ case EXTENSIONS:
+ *notification_type = kExtensionNotificationType;
+ return true;
+ case NIGORI:
+ *notification_type = kNigoriNotificationType;
+ return true;
+ default:
+ break;
+ }
+ notification_type->clear();
+ return false;
+}
+
+bool NotificationTypeToRealModelType(const std::string& notification_type,
+ ModelType* model_type) {
+ if (notification_type == kBookmarkNotificationType) {
+ *model_type = BOOKMARKS;
+ return true;
+ } else if (notification_type == kPreferenceNotificationType) {
+ *model_type = PREFERENCES;
+ return true;
+ } else if (notification_type == kPasswordNotificationType) {
+ *model_type = PASSWORDS;
+ return true;
+ } else if (notification_type == kAutofillNotificationType) {
+ *model_type = AUTOFILL;
+ return true;
+ } else if (notification_type == kThemeNotificationType) {
+ *model_type = THEMES;
+ return true;
+ } else if (notification_type == kTypedUrlNotificationType) {
+ *model_type = TYPED_URLS;
+ return true;
+ } else if (notification_type == kExtensionNotificationType) {
+ *model_type = EXTENSIONS;
+ return true;
+ } else if (notification_type == kNigoriNotificationType) {
+ *model_type = NIGORI;
+ return true;
+ }
+ *model_type = UNSPECIFIED;
+ return false;
+}
+
} // namespace syncable
diff --git a/chrome/browser/sync/syncable/model_type.h b/chrome/browser/sync/syncable/model_type.h
index 95d1d65..5c34fb8 100644
--- a/chrome/browser/sync/syncable/model_type.h
+++ b/chrome/browser/sync/syncable/model_type.h
@@ -86,6 +86,19 @@ ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics);
std::string ModelTypeToString(ModelType model_type);
+// Convert a real model type to a notification type (used for
+// subscribing to server-issued notifications). Returns true iff
+// |model_type| was a real model type and |notification_type| was
+// filled in.
+bool RealModelTypeToNotificationType(ModelType model_type,
+ std::string* notification_type);
+
+// Converts a notification type to a real model type. Returns true
+// iff |notification_type| was the notification type of a real model
+// type and |model_type| was filled in.
+bool NotificationTypeToRealModelType(const std::string& notification_type,
+ ModelType* model_type);
+
} // namespace syncable
#endif // CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_H_