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

Unified Diff: sync/notifier/object_id_state_map.cc

Issue 10874096: [Sync] Rework Invalidator-related unit tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 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
« no previous file with comments | « sync/notifier/object_id_state_map.h ('k') | sync/notifier/p2p_invalidator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/notifier/object_id_state_map.cc
diff --git a/sync/notifier/object_id_state_map.cc b/sync/notifier/object_id_state_map.cc
index 2d3b7f782172680c0398b6002cfdb47ddef6361f..c673ed803f9b4095810b29ce7588d095077f31bc 100644
--- a/sync/notifier/object_id_state_map.cc
+++ b/sync/notifier/object_id_state_map.cc
@@ -4,6 +4,11 @@
#include "sync/notifier/object_id_state_map.h"
+#include <algorithm>
+
+#include "base/compiler_specific.h"
+#include "base/values.h"
+
namespace syncer {
ObjectIdSet ObjectIdStateMapToSet(const ObjectIdStateMap& id_state_map) {
@@ -25,6 +30,62 @@ ObjectIdStateMap ObjectIdSetToStateMap(const ObjectIdSet& ids,
return id_state_map;
}
+namespace {
+
+struct ObjectIdStateMapValueEquals {
+ bool operator()(const ObjectIdStateMap::value_type& value1,
+ const ObjectIdStateMap::value_type& value2) const {
+ return
+ (value1.first == value2.first) &&
+ value1.second.Equals(value2.second);
+ }
+};
+
+} // namespace
+
+bool ObjectIdStateMapEquals(const ObjectIdStateMap& id_state_map1,
+ const ObjectIdStateMap& id_state_map2) {
+ return
+ (id_state_map1.size() == id_state_map2.size()) &&
+ std::equal(id_state_map1.begin(), id_state_map1.end(),
+ id_state_map2.begin(), ObjectIdStateMapValueEquals());
+}
+
+scoped_ptr<base::ListValue> ObjectIdStateMapToValue(
+ const ObjectIdStateMap& id_state_map) {
+ scoped_ptr<ListValue> value(new ListValue());
+ for (ObjectIdStateMap::const_iterator it = id_state_map.begin();
+ it != id_state_map.end(); ++it) {
+ DictionaryValue* entry = new DictionaryValue();
+ entry->Set("objectId", ObjectIdToValue(it->first).release());
+ entry->Set("state", it->second.ToValue().release());
+ value->Append(entry);
+ }
+ return value.Pass();
+}
+
+bool ObjectIdStateMapFromValue(const base::ListValue& value,
+ ObjectIdStateMap* out) {
+ out->clear();
+ for (base::ListValue::const_iterator it = value.begin();
+ it != value.end(); ++it) {
+ const base::DictionaryValue* entry = NULL;
+ const base::DictionaryValue* id_value = NULL;
+ const base::DictionaryValue* state_value = NULL;
+ invalidation::ObjectId id;
+ InvalidationState state;
+ if (!(*it)->GetAsDictionary(&entry) ||
+ !entry->GetDictionary("objectId", &id_value) ||
+ !entry->GetDictionary("state", &state_value) ||
+ !ObjectIdFromValue(*id_value, &id) ||
+ !state.ResetFromValue(*state_value)) {
+ return false;
+ }
+ ignore_result(out->insert(std::make_pair(id, state)));
+ }
+ return true;
+}
+
ModelTypeStateMap ObjectIdStateMapToModelTypeStateMap(
const ObjectIdStateMap& id_state_map) {
ModelTypeStateMap type_state_map;
« no previous file with comments | « sync/notifier/object_id_state_map.h ('k') | sync/notifier/p2p_invalidator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698