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

Side by Side Diff: sync/test/fake_server/fake_server.cc

Issue 327593003: Sync FakeServer cleanup: CHECKs and logging info (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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
« no previous file with comments | « no previous file | sync/test/fake_server/fake_server_entity.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fake_server/fake_server.h" 5 #include "sync/test/fake_server/fake_server.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 // Maps data type IDs to the latest version seen for that type. 109 // Maps data type IDs to the latest version seen for that type.
110 const ModelTypeToVersionMap request_from_version_; 110 const ModelTypeToVersionMap request_from_version_;
111 111
112 // The minimum version seen among all data types. 112 // The minimum version seen among all data types.
113 const int min_version_; 113 const int min_version_;
114 }; 114 };
115 115
116 scoped_ptr<UpdateSieve> UpdateSieve::Create( 116 scoped_ptr<UpdateSieve> UpdateSieve::Create(
117 const sync_pb::GetUpdatesMessage& get_updates_message) { 117 const sync_pb::GetUpdatesMessage& get_updates_message) {
118 DCHECK_GT(get_updates_message.from_progress_marker_size(), 0); 118 CHECK_GT(get_updates_message.from_progress_marker_size(), 0)
119 << "A GetUpdates request must have at least one progress marker.";
119 120
120 UpdateSieve::ModelTypeToVersionMap request_from_version; 121 UpdateSieve::ModelTypeToVersionMap request_from_version;
121 int64 min_version = std::numeric_limits<int64>::max(); 122 int64 min_version = std::numeric_limits<int64>::max();
122 for (int i = 0; i < get_updates_message.from_progress_marker_size(); i++) { 123 for (int i = 0; i < get_updates_message.from_progress_marker_size(); i++) {
123 sync_pb::DataTypeProgressMarker marker = 124 sync_pb::DataTypeProgressMarker marker =
124 get_updates_message.from_progress_marker(i); 125 get_updates_message.from_progress_marker(i);
125 126
126 int64 version = 0; 127 int64 version = 0;
127 // Let the version remain zero if there is no token or an empty token (the 128 // Let the version remain zero if there is no token or an empty token (the
128 // first request for this type). 129 // first request for this type).
129 if (marker.has_token() && !marker.token().empty()) { 130 if (marker.has_token() && !marker.token().empty()) {
130 bool parsed = base::StringToInt64(marker.token(), &version); 131 bool parsed = base::StringToInt64(marker.token(), &version);
131 DCHECK(parsed); 132 CHECK(parsed) << "Unable to parse progress marker token.";
132 } 133 }
133 134
134 ModelType model_type = syncer::GetModelTypeFromSpecificsFieldNumber( 135 ModelType model_type = syncer::GetModelTypeFromSpecificsFieldNumber(
135 marker.data_type_id()); 136 marker.data_type_id());
136 request_from_version[model_type] = version; 137 request_from_version[model_type] = version;
137 138
138 if (version < min_version) 139 if (version < min_version)
139 min_version = version; 140 min_version = version;
140 } 141 }
141 142
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 217
217 void FakeServer::HandleCommand(const string& request, 218 void FakeServer::HandleCommand(const string& request,
218 const HandleCommandCallback& callback) { 219 const HandleCommandCallback& callback) {
219 if (!authenticated_) { 220 if (!authenticated_) {
220 callback.Run(0, net::HTTP_UNAUTHORIZED, string()); 221 callback.Run(0, net::HTTP_UNAUTHORIZED, string());
221 return; 222 return;
222 } 223 }
223 224
224 sync_pb::ClientToServerMessage message; 225 sync_pb::ClientToServerMessage message;
225 bool parsed = message.ParseFromString(request); 226 bool parsed = message.ParseFromString(request);
226 DCHECK(parsed); 227 CHECK(parsed) << "Unable to parse the ClientToServerMessage.";
227 228
228 sync_pb::SyncEnums_ErrorType error_code; 229 sync_pb::SyncEnums_ErrorType error_code;
229 sync_pb::ClientToServerResponse response_proto; 230 sync_pb::ClientToServerResponse response_proto;
230 231
231 if (message.has_store_birthday() && 232 if (message.has_store_birthday() &&
232 message.store_birthday() != store_birthday_) { 233 message.store_birthday() != store_birthday_) {
233 error_code = sync_pb::SyncEnums::NOT_MY_BIRTHDAY; 234 error_code = sync_pb::SyncEnums::NOT_MY_BIRTHDAY;
234 } else { 235 } else {
235 bool success = false; 236 bool success = false;
236 switch (message.message_contents()) { 237 switch (message.message_contents()) {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 508
508 void FakeServer::AddObserver(Observer* observer) { 509 void FakeServer::AddObserver(Observer* observer) {
509 observers_.AddObserver(observer); 510 observers_.AddObserver(observer);
510 } 511 }
511 512
512 void FakeServer::RemoveObserver(Observer* observer) { 513 void FakeServer::RemoveObserver(Observer* observer) {
513 observers_.RemoveObserver(observer); 514 observers_.RemoveObserver(observer);
514 } 515 }
515 516
516 } // namespace fake_server 517 } // namespace fake_server
OLDNEW
« no previous file with comments | « no previous file | sync/test/fake_server/fake_server_entity.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698