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 "components/invalidation/public/invalidation.h" | 5 #include "components/invalidation/public/invalidation.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "components/invalidation/public/ack_handler.h" | 15 #include "components/invalidation/public/ack_handler.h" |
16 #include "components/invalidation/public/invalidation_util.h" | 16 #include "components/invalidation/public/invalidation_util.h" |
17 | 17 |
18 namespace syncer { | 18 namespace syncer { |
19 | 19 |
20 namespace { | 20 namespace { |
21 const char kObjectIdKey[] = "objectId"; | 21 const char kObjectIdKey[] = "objectId"; |
22 const char kIsUnknownVersionKey[] = "isUnknownVersion"; | 22 const char kIsUnknownVersionKey[] = "isUnknownVersion"; |
23 const char kVersionKey[] = "version"; | 23 const char kVersionKey[] = "version"; |
24 const char kPayloadKey[] = "payload"; | 24 const char kPayloadKey[] = "payload"; |
25 const int64 kInvalidVersion = -1; | 25 const int64_t kInvalidVersion = -1; |
26 } | 26 } |
27 | 27 |
28 Invalidation Invalidation::Init(const invalidation::ObjectId& id, | 28 Invalidation Invalidation::Init(const invalidation::ObjectId& id, |
29 int64 version, | 29 int64_t version, |
30 const std::string& payload) { | 30 const std::string& payload) { |
31 return Invalidation(id, false, version, payload, AckHandle::CreateUnique()); | 31 return Invalidation(id, false, version, payload, AckHandle::CreateUnique()); |
32 } | 32 } |
33 | 33 |
34 Invalidation Invalidation::InitUnknownVersion( | 34 Invalidation Invalidation::InitUnknownVersion( |
35 const invalidation::ObjectId& id) { | 35 const invalidation::ObjectId& id) { |
36 return Invalidation( | 36 return Invalidation( |
37 id, true, kInvalidVersion, std::string(), AckHandle::CreateUnique()); | 37 id, true, kInvalidVersion, std::string(), AckHandle::CreateUnique()); |
38 } | 38 } |
39 | 39 |
(...skipping 19 matching lines...) Expand all Loading... |
59 return scoped_ptr<Invalidation>(); | 59 return scoped_ptr<Invalidation>(); |
60 } | 60 } |
61 if (is_unknown_version) { | 61 if (is_unknown_version) { |
62 return scoped_ptr<Invalidation>(new Invalidation( | 62 return scoped_ptr<Invalidation>(new Invalidation( |
63 id, | 63 id, |
64 true, | 64 true, |
65 kInvalidVersion, | 65 kInvalidVersion, |
66 std::string(), | 66 std::string(), |
67 AckHandle::CreateUnique())); | 67 AckHandle::CreateUnique())); |
68 } | 68 } |
69 int64 version = 0; | 69 int64_t version = 0; |
70 std::string version_as_string; | 70 std::string version_as_string; |
71 if (!value.GetString(kVersionKey, &version_as_string) | 71 if (!value.GetString(kVersionKey, &version_as_string) |
72 || !base::StringToInt64(version_as_string, &version)) { | 72 || !base::StringToInt64(version_as_string, &version)) { |
73 DLOG(WARNING) << "Failed to parse version"; | 73 DLOG(WARNING) << "Failed to parse version"; |
74 return scoped_ptr<Invalidation>(); | 74 return scoped_ptr<Invalidation>(); |
75 } | 75 } |
76 std::string payload; | 76 std::string payload; |
77 if (!value.GetString(kPayloadKey, &payload)) { | 77 if (!value.GetString(kPayloadKey, &payload)) { |
78 DLOG(WARNING) << "Failed to parse payload"; | 78 DLOG(WARNING) << "Failed to parse payload"; |
79 return scoped_ptr<Invalidation>(); | 79 return scoped_ptr<Invalidation>(); |
(...skipping 10 matching lines...) Expand all Loading... |
90 } | 90 } |
91 | 91 |
92 invalidation::ObjectId Invalidation::object_id() const { | 92 invalidation::ObjectId Invalidation::object_id() const { |
93 return id_; | 93 return id_; |
94 } | 94 } |
95 | 95 |
96 bool Invalidation::is_unknown_version() const { | 96 bool Invalidation::is_unknown_version() const { |
97 return is_unknown_version_; | 97 return is_unknown_version_; |
98 } | 98 } |
99 | 99 |
100 int64 Invalidation::version() const { | 100 int64_t Invalidation::version() const { |
101 DCHECK(!is_unknown_version_); | 101 DCHECK(!is_unknown_version_); |
102 return version_; | 102 return version_; |
103 } | 103 } |
104 | 104 |
105 const std::string& Invalidation::payload() const { | 105 const std::string& Invalidation::payload() const { |
106 DCHECK(!is_unknown_version_); | 106 DCHECK(!is_unknown_version_); |
107 return payload_; | 107 return payload_; |
108 } | 108 } |
109 | 109 |
110 const AckHandle& Invalidation::ack_handle() const { | 110 const AckHandle& Invalidation::ack_handle() const { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 std::string Invalidation::ToString() const { | 159 std::string Invalidation::ToString() const { |
160 std::string output; | 160 std::string output; |
161 JSONStringValueSerializer serializer(&output); | 161 JSONStringValueSerializer serializer(&output); |
162 serializer.set_pretty_print(true); | 162 serializer.set_pretty_print(true); |
163 serializer.Serialize(*ToValue().get()); | 163 serializer.Serialize(*ToValue().get()); |
164 return output; | 164 return output; |
165 } | 165 } |
166 | 166 |
167 Invalidation::Invalidation(const invalidation::ObjectId& id, | 167 Invalidation::Invalidation(const invalidation::ObjectId& id, |
168 bool is_unknown_version, | 168 bool is_unknown_version, |
169 int64 version, | 169 int64_t version, |
170 const std::string& payload, | 170 const std::string& payload, |
171 AckHandle ack_handle) | 171 AckHandle ack_handle) |
172 : id_(id), | 172 : id_(id), |
173 is_unknown_version_(is_unknown_version), | 173 is_unknown_version_(is_unknown_version), |
174 version_(version), | 174 version_(version), |
175 payload_(payload), | 175 payload_(payload), |
176 ack_handle_(ack_handle) { | 176 ack_handle_(ack_handle) {} |
177 } | |
178 | 177 |
179 } // namespace syncer | 178 } // namespace syncer |
OLD | NEW |