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

Unified Diff: sync/notifier/object_id_state_map.cc

Issue 10837214: Refactor ModelTypePayloadMap and ObjectIdPayloadMap to StateMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test 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/object_id_state_map_test_util.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
new file mode 100644
index 0000000000000000000000000000000000000000..2d3b7f782172680c0398b6002cfdb47ddef6361f
--- /dev/null
+++ b/sync/notifier/object_id_state_map.cc
@@ -0,0 +1,59 @@
+// 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 "sync/notifier/object_id_state_map.h"
+
+namespace syncer {
+
+ObjectIdSet ObjectIdStateMapToSet(const ObjectIdStateMap& id_state_map) {
+ ObjectIdSet ids;
+ for (ObjectIdStateMap::const_iterator it = id_state_map.begin();
+ it != id_state_map.end(); ++it) {
+ ids.insert(it->first);
+ }
+ return ids;
+}
+
+ObjectIdStateMap ObjectIdSetToStateMap(const ObjectIdSet& ids,
+ const std::string& payload) {
+ ObjectIdStateMap id_state_map;
+ for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) {
+ // TODO(dcheng): Do we need to provide a way to set AckHandle?
+ id_state_map[*it].payload = payload;
+ }
+ return id_state_map;
+}
+
+ModelTypeStateMap ObjectIdStateMapToModelTypeStateMap(
+ const ObjectIdStateMap& id_state_map) {
+ ModelTypeStateMap type_state_map;
+ for (ObjectIdStateMap::const_iterator it = id_state_map.begin();
+ it != id_state_map.end(); ++it) {
+ ModelType model_type;
+ if (!ObjectIdToRealModelType(it->first, &model_type)) {
+ DLOG(WARNING) << "Invalid object ID: "
+ << ObjectIdToString(it->first);
+ continue;
+ }
+ type_state_map[model_type] = it->second;
+ }
+ return type_state_map;
+}
+
+ObjectIdStateMap ModelTypeStateMapToObjectIdStateMap(
+ const ModelTypeStateMap& type_state_map) {
+ ObjectIdStateMap id_state_map;
+ for (ModelTypeStateMap::const_iterator it = type_state_map.begin();
+ it != type_state_map.end(); ++it) {
+ invalidation::ObjectId id;
+ if (!RealModelTypeToObjectId(it->first, &id)) {
+ DLOG(WARNING) << "Invalid model type " << it->first;
+ continue;
+ }
+ id_state_map[id] = it->second;
+ }
+ return id_state_map;
+}
+
+} // namespace syncer
« no previous file with comments | « sync/notifier/object_id_state_map.h ('k') | sync/notifier/object_id_state_map_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698