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/test/engine/mock_commit_queue.h" | 5 #include "sync/test/engine/mock_commit_queue.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/logging.h" | 10 #include "base/logging.h" |
8 | 11 |
9 namespace syncer_v2 { | 12 namespace syncer_v2 { |
10 | 13 |
11 MockCommitQueue::MockCommitQueue() { | 14 MockCommitQueue::MockCommitQueue() { |
12 } | 15 } |
13 | 16 |
14 MockCommitQueue::~MockCommitQueue() { | 17 MockCommitQueue::~MockCommitQueue() { |
15 } | 18 } |
16 | 19 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return *it; | 63 return *it; |
61 } | 64 } |
62 } | 65 } |
63 } | 66 } |
64 | 67 |
65 NOTREACHED() << "Could not find commit for tag hash " << tag_hash << "."; | 68 NOTREACHED() << "Could not find commit for tag hash " << tag_hash << "."; |
66 return CommitRequestData(); | 69 return CommitRequestData(); |
67 } | 70 } |
68 | 71 |
69 UpdateResponseData MockCommitQueue::UpdateFromServer( | 72 UpdateResponseData MockCommitQueue::UpdateFromServer( |
70 int64 version_offset, | 73 int64_t version_offset, |
71 const std::string& tag_hash, | 74 const std::string& tag_hash, |
72 const sync_pb::EntitySpecifics& specifics) { | 75 const sync_pb::EntitySpecifics& specifics) { |
73 // Overwrite the existing server version if this is the new highest version. | 76 // Overwrite the existing server version if this is the new highest version. |
74 int64 old_version = GetServerVersion(tag_hash); | 77 int64_t old_version = GetServerVersion(tag_hash); |
75 int64 version = old_version + version_offset; | 78 int64_t version = old_version + version_offset; |
76 if (version > old_version) { | 79 if (version > old_version) { |
77 SetServerVersion(tag_hash, version); | 80 SetServerVersion(tag_hash, version); |
78 } | 81 } |
79 | 82 |
80 EntityData data; | 83 EntityData data; |
81 data.id = GenerateId(tag_hash); | 84 data.id = GenerateId(tag_hash); |
82 data.client_tag_hash = tag_hash; | 85 data.client_tag_hash = tag_hash; |
83 data.specifics = specifics; | 86 data.specifics = specifics; |
84 // These elements should have no effect on behavior, but we set them anyway | 87 // These elements should have no effect on behavior, but we set them anyway |
85 // so we can test they are properly copied around the system if we want to. | 88 // so we can test they are properly copied around the system if we want to. |
86 data.creation_time = base::Time::UnixEpoch() + base::TimeDelta::FromDays(1); | 89 data.creation_time = base::Time::UnixEpoch() + base::TimeDelta::FromDays(1); |
87 data.modification_time = | 90 data.modification_time = |
88 data.creation_time + base::TimeDelta::FromSeconds(version); | 91 data.creation_time + base::TimeDelta::FromSeconds(version); |
89 data.non_unique_name = specifics.preference().name(); | 92 data.non_unique_name = specifics.preference().name(); |
90 | 93 |
91 UpdateResponseData response_data; | 94 UpdateResponseData response_data; |
92 response_data.entity = data.Pass(); | 95 response_data.entity = data.Pass(); |
93 response_data.response_version = version; | 96 response_data.response_version = version; |
94 response_data.encryption_key_name = server_encryption_key_name_; | 97 response_data.encryption_key_name = server_encryption_key_name_; |
95 | 98 |
96 return response_data; | 99 return response_data; |
97 } | 100 } |
98 | 101 |
99 UpdateResponseData MockCommitQueue::TombstoneFromServer( | 102 UpdateResponseData MockCommitQueue::TombstoneFromServer( |
100 int64 version_offset, | 103 int64_t version_offset, |
101 const std::string& tag_hash) { | 104 const std::string& tag_hash) { |
102 int64 old_version = GetServerVersion(tag_hash); | 105 int64_t old_version = GetServerVersion(tag_hash); |
103 int64 version = old_version + version_offset; | 106 int64_t version = old_version + version_offset; |
104 if (version > old_version) { | 107 if (version > old_version) { |
105 SetServerVersion(tag_hash, version); | 108 SetServerVersion(tag_hash, version); |
106 } | 109 } |
107 | 110 |
108 EntityData data; | 111 EntityData data; |
109 data.id = GenerateId(tag_hash); | 112 data.id = GenerateId(tag_hash); |
110 data.client_tag_hash = tag_hash; | 113 data.client_tag_hash = tag_hash; |
111 // These elements should have no effect on behavior, but we set them anyway | 114 // These elements should have no effect on behavior, but we set them anyway |
112 // so we can test they are properly copied around the system if we want to. | 115 // so we can test they are properly copied around the system if we want to. |
113 data.creation_time = base::Time::UnixEpoch() + base::TimeDelta::FromDays(1); | 116 data.creation_time = base::Time::UnixEpoch() + base::TimeDelta::FromDays(1); |
(...skipping 22 matching lines...) Expand all Loading... |
136 response_data.id = entity.id; | 139 response_data.id = entity.id; |
137 } else { | 140 } else { |
138 // Otherwise we reuse the ID from the request. | 141 // Otherwise we reuse the ID from the request. |
139 response_data.id = GenerateId(client_tag_hash); | 142 response_data.id = GenerateId(client_tag_hash); |
140 } | 143 } |
141 | 144 |
142 response_data.client_tag_hash = client_tag_hash; | 145 response_data.client_tag_hash = client_tag_hash; |
143 response_data.sequence_number = request_data.sequence_number; | 146 response_data.sequence_number = request_data.sequence_number; |
144 | 147 |
145 // Increment the server version on successful commit. | 148 // Increment the server version on successful commit. |
146 int64 version = GetServerVersion(client_tag_hash); | 149 int64_t version = GetServerVersion(client_tag_hash); |
147 version++; | 150 version++; |
148 SetServerVersion(client_tag_hash, version); | 151 SetServerVersion(client_tag_hash, version); |
149 | 152 |
150 response_data.response_version = version; | 153 response_data.response_version = version; |
151 | 154 |
152 return response_data; | 155 return response_data; |
153 } | 156 } |
154 | 157 |
155 void MockCommitQueue::SetServerEncryptionKey( | 158 void MockCommitQueue::SetServerEncryptionKey( |
156 const std::string& key_name) { | 159 const std::string& key_name) { |
157 server_encryption_key_name_ = key_name; | 160 server_encryption_key_name_ = key_name; |
158 } | 161 } |
159 | 162 |
160 std::string MockCommitQueue::GenerateId(const std::string& tag_hash) { | 163 std::string MockCommitQueue::GenerateId(const std::string& tag_hash) { |
161 return "FakeId:" + tag_hash; | 164 return "FakeId:" + tag_hash; |
162 } | 165 } |
163 | 166 |
164 int64 MockCommitQueue::GetServerVersion(const std::string& tag_hash) { | 167 int64_t MockCommitQueue::GetServerVersion(const std::string& tag_hash) { |
165 std::map<const std::string, int64>::const_iterator it; | 168 std::map<const std::string, int64_t>::const_iterator it; |
166 it = server_versions_.find(tag_hash); | 169 it = server_versions_.find(tag_hash); |
167 if (it == server_versions_.end()) { | 170 if (it == server_versions_.end()) { |
168 return 0; | 171 return 0; |
169 } else { | 172 } else { |
170 return it->second; | 173 return it->second; |
171 } | 174 } |
172 } | 175 } |
173 | 176 |
174 void MockCommitQueue::SetServerVersion(const std::string& tag_hash, | 177 void MockCommitQueue::SetServerVersion(const std::string& tag_hash, |
175 int64 version) { | 178 int64_t version) { |
176 server_versions_[tag_hash] = version; | 179 server_versions_[tag_hash] = version; |
177 } | 180 } |
178 | 181 |
179 } // namespace syncer_v2 | 182 } // namespace syncer_v2 |
OLD | NEW |