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

Side by Side Diff: sync/internal_api/public/base/invalidation_util.cc

Issue 400073003: Finish decoupling sync and invalidations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix GN Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sync/internal_api/public/base/invalidation_util.h"
6
7 #include <ostream>
8 #include <sstream>
9
10 #include "base/json/json_writer.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
13 #include "google/cacheinvalidation/include/types.h"
14 #include "google/cacheinvalidation/types.pb.h"
15 #include "sync/internal_api/public/base/invalidation.h"
16
17 namespace syncer {
18
19 bool ObjectIdLessThan::operator()(const invalidation::ObjectId& lhs,
20 const invalidation::ObjectId& rhs) const {
21 return (lhs.source() < rhs.source()) ||
22 (lhs.source() == rhs.source() && lhs.name() < rhs.name());
23 }
24
25 bool InvalidationVersionLessThan::operator()(
26 const Invalidation& a,
27 const Invalidation& b) const {
28 DCHECK(a.object_id() == b.object_id())
29 << "a: " << ObjectIdToString(a.object_id()) << ", "
30 << "b: " << ObjectIdToString(a.object_id());
31
32 if (a.is_unknown_version() && !b.is_unknown_version())
33 return true;
34
35 if (!a.is_unknown_version() && b.is_unknown_version())
36 return false;
37
38 if (a.is_unknown_version() && b.is_unknown_version())
39 return false;
40
41 return a.version() < b.version();
42 }
43
44 scoped_ptr<base::DictionaryValue> ObjectIdToValue(
45 const invalidation::ObjectId& object_id) {
46 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
47 value->SetInteger("source", object_id.source());
48 value->SetString("name", object_id.name());
49 return value.Pass();
50 }
51
52 bool ObjectIdFromValue(const base::DictionaryValue& value,
53 invalidation::ObjectId* out) {
54 *out = invalidation::ObjectId();
55 std::string name;
56 int source = 0;
57 if (!value.GetInteger("source", &source) ||
58 !value.GetString("name", &name)) {
59 return false;
60 }
61 *out = invalidation::ObjectId(source, name);
62 return true;
63 }
64
65 std::string ObjectIdToString(
66 const invalidation::ObjectId& object_id) {
67 scoped_ptr<base::DictionaryValue> value(ObjectIdToValue(object_id));
68 std::string str;
69 base::JSONWriter::Write(value.get(), &str);
70 return str;
71 }
72
73 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/public/base/invalidation_util.h ('k') | sync/internal_api/public/base/invalidator_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698