| 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/sync/test/fake_server/fake_server.h" | 5 #include "components/sync/test/fake_server/fake_server.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 // Maps data type IDs to the latest version seen for that type. | 112 // Maps data type IDs to the latest version seen for that type. |
| 113 const ModelTypeToVersionMap request_from_version_; | 113 const ModelTypeToVersionMap request_from_version_; |
| 114 | 114 |
| 115 // The minimum version seen among all data types. | 115 // The minimum version seen among all data types. |
| 116 const int min_version_; | 116 const int min_version_; |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 std::unique_ptr<UpdateSieve> UpdateSieve::Create( | 119 std::unique_ptr<UpdateSieve> UpdateSieve::Create( |
| 120 const sync_pb::GetUpdatesMessage& get_updates_message) { | 120 const sync_pb::GetUpdatesMessage& get_updates_message) { |
| 121 CHECK_GT(get_updates_message.from_progress_marker_size(), 0) | 121 // A GetUpdates request must have at least one progress marker. |
| 122 << "A GetUpdates request must have at least one progress marker."; | 122 CHECK_GT(get_updates_message.from_progress_marker_size(), 0); |
| 123 | 123 |
| 124 UpdateSieve::ModelTypeToVersionMap request_from_version; | 124 UpdateSieve::ModelTypeToVersionMap request_from_version; |
| 125 int64_t min_version = std::numeric_limits<int64_t>::max(); | 125 int64_t min_version = std::numeric_limits<int64_t>::max(); |
| 126 for (int i = 0; i < get_updates_message.from_progress_marker_size(); i++) { | 126 for (int i = 0; i < get_updates_message.from_progress_marker_size(); i++) { |
| 127 sync_pb::DataTypeProgressMarker marker = | 127 sync_pb::DataTypeProgressMarker marker = |
| 128 get_updates_message.from_progress_marker(i); | 128 get_updates_message.from_progress_marker(i); |
| 129 | 129 |
| 130 int64_t version = 0; | 130 int64_t version = 0; |
| 131 // Let the version remain zero if there is no token or an empty token (the | 131 // Let the version remain zero if there is no token or an empty token (the |
| 132 // first request for this type). | 132 // first request for this type). |
| 133 if (marker.has_token() && !marker.token().empty()) { | 133 if (marker.has_token() && !marker.token().empty()) { |
| 134 bool parsed = base::StringToInt64(marker.token(), &version); | 134 bool parsed = base::StringToInt64(marker.token(), &version); |
| 135 CHECK(parsed) << "Unable to parse progress marker token."; | 135 // Unable to parse progress marker token. |
| 136 CHECK(parsed); |
| 136 } | 137 } |
| 137 | 138 |
| 138 ModelType model_type = | 139 ModelType model_type = |
| 139 syncer::GetModelTypeFromSpecificsFieldNumber(marker.data_type_id()); | 140 syncer::GetModelTypeFromSpecificsFieldNumber(marker.data_type_id()); |
| 140 request_from_version[model_type] = version; | 141 request_from_version[model_type] = version; |
| 141 | 142 |
| 142 if (version < min_version) | 143 if (version < min_version) |
| 143 min_version = version; | 144 min_version = version; |
| 144 } | 145 } |
| 145 | 146 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 if (!authenticated_) { | 246 if (!authenticated_) { |
| 246 *error_code = 0; | 247 *error_code = 0; |
| 247 *response_code = net::HTTP_UNAUTHORIZED; | 248 *response_code = net::HTTP_UNAUTHORIZED; |
| 248 *response = string(); | 249 *response = string(); |
| 249 completion_closure.Run(); | 250 completion_closure.Run(); |
| 250 return; | 251 return; |
| 251 } | 252 } |
| 252 | 253 |
| 253 sync_pb::ClientToServerMessage message; | 254 sync_pb::ClientToServerMessage message; |
| 254 bool parsed = message.ParseFromString(request); | 255 bool parsed = message.ParseFromString(request); |
| 255 CHECK(parsed) << "Unable to parse the ClientToServerMessage."; | 256 // Unable to parse the ClientToServerMessage. |
| 257 CHECK(parsed); |
| 256 | 258 |
| 257 sync_pb::ClientToServerResponse response_proto; | 259 sync_pb::ClientToServerResponse response_proto; |
| 258 | 260 |
| 259 if (message.has_store_birthday() && | 261 if (message.has_store_birthday() && |
| 260 message.store_birthday() != GetStoreBirthday()) { | 262 message.store_birthday() != GetStoreBirthday()) { |
| 261 response_proto.set_error_code(sync_pb::SyncEnums::NOT_MY_BIRTHDAY); | 263 response_proto.set_error_code(sync_pb::SyncEnums::NOT_MY_BIRTHDAY); |
| 262 } else if (error_type_ != sync_pb::SyncEnums::SUCCESS && | 264 } else if (error_type_ != sync_pb::SyncEnums::SUCCESS && |
| 263 ShouldSendTriggeredError()) { | 265 ShouldSendTriggeredError()) { |
| 264 response_proto.set_error_code(error_type_); | 266 response_proto.set_error_code(error_type_); |
| 265 } else if (triggered_actionable_error_.get() && ShouldSendTriggeredError()) { | 267 } else if (triggered_actionable_error_.get() && ShouldSendTriggeredError()) { |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 DCHECK(thread_checker_.CalledOnValidThread()); | 722 DCHECK(thread_checker_.CalledOnValidThread()); |
| 721 return weak_ptr_factory_.GetWeakPtr(); | 723 return weak_ptr_factory_.GetWeakPtr(); |
| 722 } | 724 } |
| 723 | 725 |
| 724 std::string FakeServer::GetStoreBirthday() const { | 726 std::string FakeServer::GetStoreBirthday() const { |
| 725 DCHECK(thread_checker_.CalledOnValidThread()); | 727 DCHECK(thread_checker_.CalledOnValidThread()); |
| 726 return base::Int64ToString(store_birthday_); | 728 return base::Int64ToString(store_birthday_); |
| 727 } | 729 } |
| 728 | 730 |
| 729 } // namespace fake_server | 731 } // namespace fake_server |
| OLD | NEW |