Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/engine/syncer_proto_util.h" | 5 #include "sync/engine/syncer_proto_util.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "sync/engine/net/server_connection_manager.h" | 9 #include "sync/engine/net/server_connection_manager.h" |
| 10 #include "sync/engine/syncer.h" | 10 #include "sync/engine/syncer.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 } | 156 } |
| 157 | 157 |
| 158 // static | 158 // static |
| 159 void SyncerProtoUtil::AddRequestBirthday(syncable::Directory* dir, | 159 void SyncerProtoUtil::AddRequestBirthday(syncable::Directory* dir, |
| 160 ClientToServerMessage* msg) { | 160 ClientToServerMessage* msg) { |
| 161 if (!dir->store_birthday().empty()) | 161 if (!dir->store_birthday().empty()) |
| 162 msg->set_store_birthday(dir->store_birthday()); | 162 msg->set_store_birthday(dir->store_birthday()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 // static | 165 // static |
| 166 void SyncerProtoUtil::AddBagOfChips(syncable::Directory* dir, | |
| 167 ClientToServerMessage* msg) { | |
| 168 msg->mutable_bag_of_chips()->ParseFromString(dir->bag_of_chips()); | |
| 169 } | |
| 170 | |
| 171 // static | |
| 166 void SyncerProtoUtil::SetProtocolVersion(ClientToServerMessage* msg) { | 172 void SyncerProtoUtil::SetProtocolVersion(ClientToServerMessage* msg) { |
| 167 const int current_version = | 173 const int current_version = |
| 168 ClientToServerMessage::default_instance().protocol_version(); | 174 ClientToServerMessage::default_instance().protocol_version(); |
| 169 msg->set_protocol_version(current_version); | 175 msg->set_protocol_version(current_version); |
| 170 } | 176 } |
| 171 | 177 |
| 172 // static | 178 // static |
| 173 bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm, | 179 bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm, |
| 174 sessions::SyncSession* session, | 180 sessions::SyncSession* session, |
| 175 const ClientToServerMessage& msg, | 181 const ClientToServerMessage& msg, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 delegate->OnSilencedUntil(throttled_until); | 242 delegate->OnSilencedUntil(throttled_until); |
| 237 } else { | 243 } else { |
| 238 tracker->SetUnthrottleTime(error.error_data_types, throttled_until); | 244 tracker->SetUnthrottleTime(error.error_data_types, throttled_until); |
| 239 } | 245 } |
| 240 } | 246 } |
| 241 | 247 |
| 242 namespace { | 248 namespace { |
| 243 | 249 |
| 244 // Helper function for an assertion in PostClientToServerMessage. | 250 // Helper function for an assertion in PostClientToServerMessage. |
| 245 bool IsVeryFirstGetUpdates(const ClientToServerMessage& message) { | 251 bool IsVeryFirstGetUpdates(const ClientToServerMessage& message) { |
| 252 DCHECK(message.has_bag_of_chips()); | |
| 246 if (!message.has_get_updates()) | 253 if (!message.has_get_updates()) |
| 247 return false; | 254 return false; |
| 248 DCHECK_LT(0, message.get_updates().from_progress_marker_size()); | 255 DCHECK_LT(0, message.get_updates().from_progress_marker_size()); |
| 249 for (int i = 0; i < message.get_updates().from_progress_marker_size(); ++i) { | 256 for (int i = 0; i < message.get_updates().from_progress_marker_size(); ++i) { |
| 250 if (!message.get_updates().from_progress_marker(i).token().empty()) | 257 if (!message.get_updates().from_progress_marker(i).token().empty()) |
| 251 return false; | 258 return false; |
| 252 } | 259 } |
| 253 return true; | 260 return true; |
| 254 } | 261 } |
| 255 | 262 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 | 347 |
| 341 // static | 348 // static |
| 342 SyncerError SyncerProtoUtil::PostClientToServerMessage( | 349 SyncerError SyncerProtoUtil::PostClientToServerMessage( |
| 343 const ClientToServerMessage& msg, | 350 const ClientToServerMessage& msg, |
| 344 ClientToServerResponse* response, | 351 ClientToServerResponse* response, |
| 345 SyncSession* session) { | 352 SyncSession* session) { |
| 346 | 353 |
| 347 CHECK(response); | 354 CHECK(response); |
| 348 DCHECK(!msg.get_updates().has_from_timestamp()); // Deprecated. | 355 DCHECK(!msg.get_updates().has_from_timestamp()); // Deprecated. |
| 349 DCHECK(!msg.get_updates().has_requested_types()); // Deprecated. | 356 DCHECK(!msg.get_updates().has_requested_types()); // Deprecated. |
| 350 DCHECK(msg.has_store_birthday() || IsVeryFirstGetUpdates(msg)) | 357 DCHECK(msg.has_store_birthday() || IsVeryFirstGetUpdates(msg)) |
|
Nicolas Zea
2012/09/07 18:38:43
I think the has_bag_of_chips dcheck should be sepa
qsr
2012/09/10 08:12:37
Sorry, typo. Done
| |
| 351 << "Must call AddRequestBirthday to set birthday."; | 358 << "Must call AddRequestBirthday to set birthday."; |
| 352 | 359 |
| 353 syncable::Directory* dir = session->context()->directory(); | 360 syncable::Directory* dir = session->context()->directory(); |
| 354 | 361 |
| 355 LogClientToServerMessage(msg); | 362 LogClientToServerMessage(msg); |
| 356 session->context()->traffic_recorder()->RecordClientToServerMessage(msg); | 363 session->context()->traffic_recorder()->RecordClientToServerMessage(msg); |
| 357 if (!PostAndProcessHeaders(session->context()->connection_manager(), session, | 364 if (!PostAndProcessHeaders(session->context()->connection_manager(), session, |
| 358 msg, response)) { | 365 msg, response)) { |
| 359 // There was an error establishing communication with the server. | 366 // There was an error establishing communication with the server. |
| 360 // We can not proceed beyond this point. | 367 // We can not proceed beyond this point. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 } | 509 } |
| 503 | 510 |
| 504 // static | 511 // static |
| 505 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse( | 512 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse( |
| 506 const sync_pb::CommitResponse_EntryResponse& entry) { | 513 const sync_pb::CommitResponse_EntryResponse& entry) { |
| 507 if (entry.has_non_unique_name()) | 514 if (entry.has_non_unique_name()) |
| 508 return entry.non_unique_name(); | 515 return entry.non_unique_name(); |
| 509 return entry.name(); | 516 return entry.name(); |
| 510 } | 517 } |
| 511 | 518 |
| 519 // static | |
| 520 void SyncerProtoUtil::PersistBagOfChips(syncable::Directory* dir, | |
| 521 const sync_pb::ClientToServerResponse& response) { | |
| 522 if (!response.has_new_bag_of_chips()) | |
| 523 return; | |
| 524 std::string bag_of_chips; | |
| 525 if (response.new_bag_of_chips().SerializeToString(&bag_of_chips)) | |
| 526 dir->set_bag_of_chips(bag_of_chips); | |
| 527 } | |
| 528 | |
| 512 std::string SyncerProtoUtil::SyncEntityDebugString( | 529 std::string SyncerProtoUtil::SyncEntityDebugString( |
| 513 const sync_pb::SyncEntity& entry) { | 530 const sync_pb::SyncEntity& entry) { |
| 514 const std::string& mtime_str = | 531 const std::string& mtime_str = |
| 515 GetTimeDebugString(ProtoTimeToTime(entry.mtime())); | 532 GetTimeDebugString(ProtoTimeToTime(entry.mtime())); |
| 516 const std::string& ctime_str = | 533 const std::string& ctime_str = |
| 517 GetTimeDebugString(ProtoTimeToTime(entry.ctime())); | 534 GetTimeDebugString(ProtoTimeToTime(entry.ctime())); |
| 518 return base::StringPrintf( | 535 return base::StringPrintf( |
| 519 "id: %s, parent_id: %s, " | 536 "id: %s, parent_id: %s, " |
| 520 "version: %"PRId64"d, " | 537 "version: %"PRId64"d, " |
| 521 "mtime: %" PRId64"d (%s), " | 538 "mtime: %" PRId64"d (%s), " |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 547 std::string SyncerProtoUtil::ClientToServerResponseDebugString( | 564 std::string SyncerProtoUtil::ClientToServerResponseDebugString( |
| 548 const ClientToServerResponse& response) { | 565 const ClientToServerResponse& response) { |
| 549 // Add more handlers as needed. | 566 // Add more handlers as needed. |
| 550 std::string output; | 567 std::string output; |
| 551 if (response.has_get_updates()) | 568 if (response.has_get_updates()) |
| 552 output.append(GetUpdatesResponseString(response.get_updates())); | 569 output.append(GetUpdatesResponseString(response.get_updates())); |
| 553 return output; | 570 return output; |
| 554 } | 571 } |
| 555 | 572 |
| 556 } // namespace syncer | 573 } // namespace syncer |
| OLD | NEW |