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

Unified Diff: chrome/browser/sync/syncable/model_type.cc

Issue 7481023: Adding notifications for new sync types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now stores acknowledged types in a ListValue, not a StringValue. Created 9 years, 4 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/sync/syncable/model_type.cc
diff --git a/chrome/browser/sync/syncable/model_type.cc b/chrome/browser/sync/syncable/model_type.cc
index 28bafef06e1507c43c375cbd10757673f0874625..460985a3f5eaf46a000ac8f4e411660aa9dab66c 100644
--- a/chrome/browser/sync/syncable/model_type.cc
+++ b/chrome/browser/sync/syncable/model_type.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/sync/syncable/model_type.h"
#include "base/metrics/histogram.h"
+#include "base/string_split.h"
#include "base/values.h"
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/protocol/app_specifics.pb.h"
@@ -254,6 +255,21 @@ std::string ModelTypeSetToString(const ModelTypeSet& model_types) {
return result;
}
+ModelType ModelTypeFromValue(const Value& value) {
+ if (value.IsType(Value::TYPE_STRING)) {
+ std::string result;
+ CHECK(value.GetAsString(&result));
+ return ModelTypeFromString(result);
+ } else if (value.IsType(Value::TYPE_INTEGER)) {
+ int result;
+ CHECK(value.GetAsInteger(&result));
+ return ModelTypeFromInt(result);
+ } else {
+ NOTREACHED() << "Unsupported value type: " << value.GetType();
+ return UNSPECIFIED;
+ }
+}
+
ModelType ModelTypeFromString(const std::string& model_type_string) {
if (model_type_string == "Bookmarks")
return BOOKMARKS;
@@ -302,11 +318,23 @@ bool ModelTypeBitSetFromString(
const std::string& model_type_bitset_string,
ModelTypeBitSet* model_types) {
DCHECK(model_types);
- if (model_type_bitset_string.length() != MODEL_TYPE_COUNT)
- return false;
- if (model_type_bitset_string.find_first_not_of("01") != std::string::npos)
- return false;
- *model_types = ModelTypeBitSet(model_type_bitset_string);
+ ModelTypeBitSet bitset;
akalin 2011/08/10 01:16:21 Is this fn used anymore? If not, probably can del
Andrew T Wilson (Slow) 2011/08/10 23:40:12 We could. Won't the linker exclude it from the bin
+ if (!model_type_bitset_string.empty()) {
+ std::vector<std::string> types;
+ // Parse the comma-delimited list of types.
+ base::SplitString(model_type_bitset_string, ',', &types);
+
+ // Walk the list of types and set them in our ModelTypeBitSet.
+ for (std::vector<std::string>::const_iterator it = types.begin();
+ it != types.end();
+ ++it) {
+ ModelType type = ModelTypeFromString(*it);
+ if (type == UNSPECIFIED)
+ return false;
+ bitset.set(type);
+ }
+ }
+ *model_types = bitset;
return true;
}
@@ -330,6 +358,14 @@ ListValue* ModelTypeBitSetToValue(const ModelTypeBitSet& model_types) {
return value;
}
+ModelTypeBitSet ModelTypeBitSetFromValue(const base::ListValue& value) {
+ ModelTypeBitSet result;
+ for (ListValue::const_iterator i = value.begin(); i != value.end(); ++i) {
+ result.set(ModelTypeFromValue(**i));
akalin 2011/08/10 01:16:21 Do we really need this? I'd prefer iterating over
Andrew T Wilson (Slow) 2011/08/10 23:40:12 That's essentially what we have - it's just in a p
+ }
+ return result;
+}
+
ListValue* ModelTypeSetToValue(const ModelTypeSet& model_types) {
ListValue* value = new ListValue();
for (ModelTypeSet::const_iterator i = model_types.begin();

Powered by Google App Engine
This is Rietveld 408576698