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

Side by Side Diff: sync/engine/syncer_proto_util.cc

Issue 10916174: Implement a bag of chips for sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Follow review Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
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
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 SyncerError SyncerProtoUtil::PostClientToServerMessage( 348 SyncerError SyncerProtoUtil::PostClientToServerMessage(
343 const ClientToServerMessage& msg, 349 const ClientToServerMessage& msg,
344 ClientToServerResponse* response, 350 ClientToServerResponse* response,
345 SyncSession* session) { 351 SyncSession* session) {
346 352
347 CHECK(response); 353 CHECK(response);
348 DCHECK(!msg.get_updates().has_from_timestamp()); // Deprecated. 354 DCHECK(!msg.get_updates().has_from_timestamp()); // Deprecated.
349 DCHECK(!msg.get_updates().has_requested_types()); // Deprecated. 355 DCHECK(!msg.get_updates().has_requested_types()); // Deprecated.
350 DCHECK(msg.has_store_birthday() || IsVeryFirstGetUpdates(msg)) 356 DCHECK(msg.has_store_birthday() || IsVeryFirstGetUpdates(msg))
351 << "Must call AddRequestBirthday to set birthday."; 357 << "Must call AddRequestBirthday to set birthday.";
358 DCHECK(msg.has_bag_of_chips())
359 << "Must call AddBagOfChips to set bag_of_chips.";
352 360
353 syncable::Directory* dir = session->context()->directory(); 361 syncable::Directory* dir = session->context()->directory();
354 362
355 LogClientToServerMessage(msg); 363 LogClientToServerMessage(msg);
356 session->context()->traffic_recorder()->RecordClientToServerMessage(msg); 364 session->context()->traffic_recorder()->RecordClientToServerMessage(msg);
357 if (!PostAndProcessHeaders(session->context()->connection_manager(), session, 365 if (!PostAndProcessHeaders(session->context()->connection_manager(), session,
358 msg, response)) { 366 msg, response)) {
359 // There was an error establishing communication with the server. 367 // There was an error establishing communication with the server.
360 // We can not proceed beyond this point. 368 // We can not proceed beyond this point.
361 const HttpResponse::ServerConnectionCode server_status = 369 const HttpResponse::ServerConnectionCode server_status =
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 510 }
503 511
504 // static 512 // static
505 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse( 513 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse(
506 const sync_pb::CommitResponse_EntryResponse& entry) { 514 const sync_pb::CommitResponse_EntryResponse& entry) {
507 if (entry.has_non_unique_name()) 515 if (entry.has_non_unique_name())
508 return entry.non_unique_name(); 516 return entry.non_unique_name();
509 return entry.name(); 517 return entry.name();
510 } 518 }
511 519
520 // static
521 void SyncerProtoUtil::PersistBagOfChips(syncable::Directory* dir,
522 const sync_pb::ClientToServerResponse& response) {
523 if (!response.has_new_bag_of_chips())
524 return;
525 std::string bag_of_chips;
526 if (response.new_bag_of_chips().SerializeToString(&bag_of_chips))
527 dir->set_bag_of_chips(bag_of_chips);
528 }
529
512 std::string SyncerProtoUtil::SyncEntityDebugString( 530 std::string SyncerProtoUtil::SyncEntityDebugString(
513 const sync_pb::SyncEntity& entry) { 531 const sync_pb::SyncEntity& entry) {
514 const std::string& mtime_str = 532 const std::string& mtime_str =
515 GetTimeDebugString(ProtoTimeToTime(entry.mtime())); 533 GetTimeDebugString(ProtoTimeToTime(entry.mtime()));
516 const std::string& ctime_str = 534 const std::string& ctime_str =
517 GetTimeDebugString(ProtoTimeToTime(entry.ctime())); 535 GetTimeDebugString(ProtoTimeToTime(entry.ctime()));
518 return base::StringPrintf( 536 return base::StringPrintf(
519 "id: %s, parent_id: %s, " 537 "id: %s, parent_id: %s, "
520 "version: %"PRId64"d, " 538 "version: %"PRId64"d, "
521 "mtime: %" PRId64"d (%s), " 539 "mtime: %" PRId64"d (%s), "
(...skipping 25 matching lines...) Expand all
547 std::string SyncerProtoUtil::ClientToServerResponseDebugString( 565 std::string SyncerProtoUtil::ClientToServerResponseDebugString(
548 const ClientToServerResponse& response) { 566 const ClientToServerResponse& response) {
549 // Add more handlers as needed. 567 // Add more handlers as needed.
550 std::string output; 568 std::string output;
551 if (response.has_get_updates()) 569 if (response.has_get_updates())
552 output.append(GetUpdatesResponseString(response.get_updates())); 570 output.append(GetUpdatesResponseString(response.get_updates()));
553 return output; 571 return output;
554 } 572 }
555 573
556 } // namespace syncer 574 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698