| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/internal_api/public/base/invalidation_util.h" | 5 #include "components/invalidation/invalidation_util.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "components/invalidation/invalidation.h" |
| 13 #include "google/cacheinvalidation/include/types.h" | 14 #include "google/cacheinvalidation/include/types.h" |
| 14 #include "google/cacheinvalidation/types.pb.h" | 15 #include "google/cacheinvalidation/types.pb.h" |
| 15 #include "sync/internal_api/public/base/invalidation.h" | |
| 16 | 16 |
| 17 namespace syncer { | 17 namespace syncer { |
| 18 | 18 |
| 19 bool ObjectIdLessThan::operator()(const invalidation::ObjectId& lhs, | 19 bool ObjectIdLessThan::operator()(const invalidation::ObjectId& lhs, |
| 20 const invalidation::ObjectId& rhs) const { | 20 const invalidation::ObjectId& rhs) const { |
| 21 return (lhs.source() < rhs.source()) || | 21 return (lhs.source() < rhs.source()) || |
| 22 (lhs.source() == rhs.source() && lhs.name() < rhs.name()); | 22 (lhs.source() == rhs.source() && lhs.name() < rhs.name()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 bool InvalidationVersionLessThan::operator()( | 25 bool InvalidationVersionLessThan::operator()(const Invalidation& a, |
| 26 const Invalidation& a, | 26 const Invalidation& b) const { |
| 27 const Invalidation& b) const { | |
| 28 DCHECK(a.object_id() == b.object_id()) | 27 DCHECK(a.object_id() == b.object_id()) |
| 29 << "a: " << ObjectIdToString(a.object_id()) << ", " | 28 << "a: " << ObjectIdToString(a.object_id()) << ", " |
| 30 << "b: " << ObjectIdToString(a.object_id()); | 29 << "b: " << ObjectIdToString(a.object_id()); |
| 31 | 30 |
| 32 if (a.is_unknown_version() && !b.is_unknown_version()) | 31 if (a.is_unknown_version() && !b.is_unknown_version()) |
| 33 return true; | 32 return true; |
| 34 | 33 |
| 35 if (!a.is_unknown_version() && b.is_unknown_version()) | 34 if (!a.is_unknown_version() && b.is_unknown_version()) |
| 36 return false; | 35 return false; |
| 37 | 36 |
| 38 if (a.is_unknown_version() && b.is_unknown_version()) | 37 if (a.is_unknown_version() && b.is_unknown_version()) |
| 39 return false; | 38 return false; |
| 40 | 39 |
| 41 return a.version() < b.version(); | 40 return a.version() < b.version(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 scoped_ptr<base::DictionaryValue> ObjectIdToValue( | 43 scoped_ptr<base::DictionaryValue> ObjectIdToValue( |
| 45 const invalidation::ObjectId& object_id) { | 44 const invalidation::ObjectId& object_id) { |
| 46 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 45 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 47 value->SetInteger("source", object_id.source()); | 46 value->SetInteger("source", object_id.source()); |
| 48 value->SetString("name", object_id.name()); | 47 value->SetString("name", object_id.name()); |
| 49 return value.Pass(); | 48 return value.Pass(); |
| 50 } | 49 } |
| 51 | 50 |
| 52 bool ObjectIdFromValue(const base::DictionaryValue& value, | 51 bool ObjectIdFromValue(const base::DictionaryValue& value, |
| 53 invalidation::ObjectId* out) { | 52 invalidation::ObjectId* out) { |
| 54 *out = invalidation::ObjectId(); | 53 *out = invalidation::ObjectId(); |
| 55 std::string name; | 54 std::string name; |
| 56 int source = 0; | 55 int source = 0; |
| 57 if (!value.GetInteger("source", &source) || | 56 if (!value.GetInteger("source", &source) || !value.GetString("name", &name)) { |
| 58 !value.GetString("name", &name)) { | |
| 59 return false; | 57 return false; |
| 60 } | 58 } |
| 61 *out = invalidation::ObjectId(source, name); | 59 *out = invalidation::ObjectId(source, name); |
| 62 return true; | 60 return true; |
| 63 } | 61 } |
| 64 | 62 |
| 65 std::string ObjectIdToString( | 63 std::string ObjectIdToString(const invalidation::ObjectId& object_id) { |
| 66 const invalidation::ObjectId& object_id) { | |
| 67 scoped_ptr<base::DictionaryValue> value(ObjectIdToValue(object_id)); | 64 scoped_ptr<base::DictionaryValue> value(ObjectIdToValue(object_id)); |
| 68 std::string str; | 65 std::string str; |
| 69 base::JSONWriter::Write(value.get(), &str); | 66 base::JSONWriter::Write(value.get(), &str); |
| 70 return str; | 67 return str; |
| 71 } | 68 } |
| 72 | 69 |
| 73 } // namespace syncer | 70 } // namespace syncer |
| OLD | NEW |