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

Unified Diff: sync/syncable/model_type.cc

Issue 11958029: [Sync] Add support for proxy types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch to ProxyTypes Created 7 years, 10 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
« no previous file with comments | « sync/syncable/directory_backing_store_unittest.cc ('k') | sync/syncable/model_type_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/syncable/model_type.cc
diff --git a/sync/syncable/model_type.cc b/sync/syncable/model_type.cc
index 719f65b89dc816b07dfce59e0a8ed1c0ec27b6a7..08478102b5874fa872f5e66c1059b10beac1a929 100644
--- a/sync/syncable/model_type.cc
+++ b/sync/syncable/model_type.cc
@@ -27,6 +27,10 @@ namespace syncer {
void AddDefaultFieldValue(ModelType datatype,
sync_pb::EntitySpecifics* specifics) {
+ if (!ProtocolTypes().Has(datatype)) {
+ NOTREACHED() << "Only protocol types have field values.";
+ return;
+ }
switch (datatype) {
case BOOKMARKS:
specifics->mutable_bookmark();
@@ -97,15 +101,20 @@ void AddDefaultFieldValue(ModelType datatype,
}
ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) {
- for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
- ModelType model_type = ModelTypeFromInt(i);
- if (GetSpecificsFieldNumberFromModelType(model_type) == field_number)
- return model_type;
+ ModelTypeSet protocol_types = ProtocolTypes();
+ for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
+ iter.Inc()) {
+ if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number)
+ return iter.Get();
}
return UNSPECIFIED;
}
int GetSpecificsFieldNumberFromModelType(ModelType model_type) {
+ if (!ProtocolTypes().Has(model_type)) {
+ NOTREACHED() << "Only protocol types have field values.";
+ return 0;
+ }
switch (model_type) {
case BOOKMARKS:
return sync_pb::EntitySpecifics::kBookmarkFieldNumber;
@@ -285,8 +294,17 @@ bool ShouldMaintainPosition(ModelType model_type) {
return model_type == BOOKMARKS;
}
+ModelTypeSet ProtocolTypes() {
+ ModelTypeSet set = ModelTypeSet::All();
+ set.RemoveAll(ProxyTypes());
+ return set;
+}
+
ModelTypeSet UserTypes() {
ModelTypeSet set;
+ // TODO(sync): We should be able to build the actual enumset's internal
+ // bitset value here at compile time, rather than performing an iteration
+ // every time.
for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) {
set.Put(ModelTypeFromInt(i));
}
@@ -299,11 +317,18 @@ ModelTypeSet EncryptableUserTypes() {
encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES);
// Synced notifications are not encrypted since the server must see changes.
encryptable_user_types.Remove(SYNCED_NOTIFICATIONS);
+ // Proxy types have no sync representation and are therefore not encrypted.
+ // Note however that proxy types map to one or more protocol types, which
+ // may or may not be encrypted themselves.
+ encryptable_user_types.RemoveAll(ProxyTypes());
return encryptable_user_types;
}
ModelTypeSet ControlTypes() {
ModelTypeSet set;
+ // TODO(sync): We should be able to build the actual enumset's internal
+ // bitset value here at compile time, rather than performing an iteration
+ // every time.
for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) {
set.Put(ModelTypeFromInt(i));
}
@@ -314,6 +339,12 @@ ModelTypeSet ControlTypes() {
return set;
}
+ModelTypeSet ProxyTypes() {
+ ModelTypeSet set;
+ // TODO(zea): add a TABS type here.
+ return set;
+}
+
bool IsControlType(ModelType model_type) {
return ControlTypes().Has(model_type);
}
@@ -482,6 +513,8 @@ ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) {
// TODO(zea): remove all hardcoded tags in model associators and have them use
// this instead.
+// NOTE: Proxy types should return empty strings (so that we don't NOTREACHED
+// in tests when we verify they have no root node).
std::string ModelTypeToRootTag(ModelType type) {
switch (type) {
case BOOKMARKS:
@@ -534,7 +567,8 @@ std::string ModelTypeToRootTag(ModelType type) {
}
// TODO(akalin): Figure out a better way to do these mappings.
-
+// Note: Do not include proxy types in this list. They should never receive
+// or trigger notifications.
namespace {
const char kBookmarkNotificationType[] = "BOOKMARK";
const char kPreferenceNotificationType[] = "PREFERENCE";
« no previous file with comments | « sync/syncable/directory_backing_store_unittest.cc ('k') | sync/syncable/model_type_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698