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

Unified Diff: sync/notifier/invalidation_util.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/invalidation_util.h ('k') | sync/notifier/invalidator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/notifier/invalidation_util.cc
diff --git a/sync/notifier/invalidation_util.cc b/sync/notifier/invalidation_util.cc
index 7307292d4c7044c8be392783cefeef55a05f21a2..1c6b931f737f2b6b0321a6dc3a48e4e390512677 100644
--- a/sync/notifier/invalidation_util.cc
+++ b/sync/notifier/invalidation_util.cc
@@ -7,6 +7,9 @@
#include <ostream>
#include <sstream>
+#include "base/json/json_writer.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
#include "google/cacheinvalidation/include/types.h"
#include "google/cacheinvalidation/types.pb.h"
@@ -40,6 +43,35 @@ bool ObjectIdToRealModelType(const invalidation::ObjectId& object_id,
return NotificationTypeToRealModelType(object_id.name(), model_type);
}
+scoped_ptr<base::DictionaryValue> ObjectIdToValue(
+ const invalidation::ObjectId& object_id) {
+ scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
+ value->SetInteger("source", object_id.source());
+ value->SetString("name", object_id.name());
+ return value.Pass();
+}
+
+bool ObjectIdFromValue(const base::DictionaryValue& value,
+ invalidation::ObjectId* out) {
+ *out = invalidation::ObjectId();
+ std::string name;
+ int source = 0;
+ if (!value.GetInteger("source", &source) ||
+ !value.GetString("name", &name)) {
+ return false;
+ }
+ *out = invalidation::ObjectId(source, name);
+ return true;
+}
+
+std::string ObjectIdToString(
+ const invalidation::ObjectId& object_id) {
+ scoped_ptr<base::DictionaryValue> value(ObjectIdToValue(object_id));
+ std::string str;
+ base::JSONWriter::Write(value.get(), &str);
+ return str;
+}
+
ObjectIdSet ModelTypeSetToObjectIdSet(const ModelTypeSet& model_types) {
ObjectIdSet ids;
for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
@@ -66,16 +98,6 @@ ModelTypeSet ObjectIdSetToModelTypeSet(const ObjectIdSet& ids) {
return model_types;
}
-std::string ObjectIdToString(
- const invalidation::ObjectId& object_id) {
- std::stringstream ss;
- ss << "{ ";
- ss << "name: " << object_id.name() << ", ";
- ss << "source: " << object_id.source();
- ss << " }";
- return ss.str();
-}
-
std::string InvalidationToString(
const invalidation::Invalidation& invalidation) {
std::stringstream ss;
« no previous file with comments | « sync/notifier/invalidation_util.h ('k') | sync/notifier/invalidator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698