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

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
« no previous file with comments | « sync/engine/syncer_proto_util.h ('k') | sync/protocol/sync.proto » ('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 (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 =
362 session->context()->connection_manager()->server_status(); 370 session->context()->connection_manager()->server_status();
363 371
364 DCHECK_NE(server_status, HttpResponse::NONE); 372 DCHECK_NE(server_status, HttpResponse::NONE);
365 DCHECK_NE(server_status, HttpResponse::SERVER_CONNECTION_OK); 373 DCHECK_NE(server_status, HttpResponse::SERVER_CONNECTION_OK);
366 374
367 return ServerConnectionErrorAsSyncerError(server_status); 375 return ServerConnectionErrorAsSyncerError(server_status);
368 } 376 }
369 377
370 LogClientToServerResponse(*response); 378 LogClientToServerResponse(*response);
371 session->context()->traffic_recorder()->RecordClientToServerResponse( 379 session->context()->traffic_recorder()->RecordClientToServerResponse(
372 *response); 380 *response);
373 381
382 // Persist a bag of chips if it has been sent by the server.
383 PersistBagOfChips(dir, *response);
384
374 SyncProtocolError sync_protocol_error; 385 SyncProtocolError sync_protocol_error;
375 386
376 // Birthday mismatch overrides any error that is sent by the server. 387 // Birthday mismatch overrides any error that is sent by the server.
377 if (!VerifyResponseBirthday(dir, response)) { 388 if (!VerifyResponseBirthday(dir, response)) {
378 sync_protocol_error.error_type = NOT_MY_BIRTHDAY; 389 sync_protocol_error.error_type = NOT_MY_BIRTHDAY;
379 sync_protocol_error.action = 390 sync_protocol_error.action =
380 DISABLE_SYNC_ON_CLIENT; 391 DISABLE_SYNC_ON_CLIENT;
381 } else if (response->has_error()) { 392 } else if (response->has_error()) {
382 // This is a new server. Just get the error from the protocol. 393 // This is a new server. Just get the error from the protocol.
383 sync_protocol_error = ConvertErrorPBToLocalType(response->error()); 394 sync_protocol_error = ConvertErrorPBToLocalType(response->error());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 513 }
503 514
504 // static 515 // static
505 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse( 516 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse(
506 const sync_pb::CommitResponse_EntryResponse& entry) { 517 const sync_pb::CommitResponse_EntryResponse& entry) {
507 if (entry.has_non_unique_name()) 518 if (entry.has_non_unique_name())
508 return entry.non_unique_name(); 519 return entry.non_unique_name();
509 return entry.name(); 520 return entry.name();
510 } 521 }
511 522
523 // static
524 void SyncerProtoUtil::PersistBagOfChips(syncable::Directory* dir,
525 const sync_pb::ClientToServerResponse& response) {
526 if (!response.has_new_bag_of_chips())
527 return;
528 std::string bag_of_chips;
529 if (response.new_bag_of_chips().SerializeToString(&bag_of_chips))
530 dir->set_bag_of_chips(bag_of_chips);
531 }
532
512 std::string SyncerProtoUtil::SyncEntityDebugString( 533 std::string SyncerProtoUtil::SyncEntityDebugString(
513 const sync_pb::SyncEntity& entry) { 534 const sync_pb::SyncEntity& entry) {
514 const std::string& mtime_str = 535 const std::string& mtime_str =
515 GetTimeDebugString(ProtoTimeToTime(entry.mtime())); 536 GetTimeDebugString(ProtoTimeToTime(entry.mtime()));
516 const std::string& ctime_str = 537 const std::string& ctime_str =
517 GetTimeDebugString(ProtoTimeToTime(entry.ctime())); 538 GetTimeDebugString(ProtoTimeToTime(entry.ctime()));
518 return base::StringPrintf( 539 return base::StringPrintf(
519 "id: %s, parent_id: %s, " 540 "id: %s, parent_id: %s, "
520 "version: %"PRId64"d, " 541 "version: %"PRId64"d, "
521 "mtime: %" PRId64"d (%s), " 542 "mtime: %" PRId64"d (%s), "
(...skipping 25 matching lines...) Expand all
547 std::string SyncerProtoUtil::ClientToServerResponseDebugString( 568 std::string SyncerProtoUtil::ClientToServerResponseDebugString(
548 const ClientToServerResponse& response) { 569 const ClientToServerResponse& response) {
549 // Add more handlers as needed. 570 // Add more handlers as needed.
550 std::string output; 571 std::string output;
551 if (response.has_get_updates()) 572 if (response.has_get_updates())
552 output.append(GetUpdatesResponseString(response.get_updates())); 573 output.append(GetUpdatesResponseString(response.get_updates()));
553 return output; 574 return output;
554 } 575 }
555 576
556 } // namespace syncer 577 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/syncer_proto_util.h ('k') | sync/protocol/sync.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698