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

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

Issue 9158004: Detect sync server communication errors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update for review comments Created 8 years, 11 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 "chrome/browser/sync/engine/syncer_proto_util.h" 5 #include "chrome/browser/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 "chrome/browser/sync/engine/net/server_connection_manager.h" 9 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
10 #include "chrome/browser/sync/engine/syncer.h" 10 #include "chrome/browser/sync/engine/syncer.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 if (response.profiling_data().has_total_request_time()) { 75 if (response.profiling_data().has_total_request_time()) {
76 response_trace << " total time: " 76 response_trace << " total time: "
77 << response.profiling_data().total_request_time() << "ms"; 77 << response.profiling_data().total_request_time() << "ms";
78 } 78 }
79 DVLOG(1) << response_trace.str(); 79 DVLOG(1) << response_trace.str();
80 } 80 }
81 } 81 }
82 82
83 SyncerError ServerConnectionErrorAsSyncerError(
84 const HttpResponse::ServerConnectionCode server_status) {
85 switch (server_status) {
86 case HttpResponse::CONNECTION_UNAVAILABLE:
87 return NETWORK_CONNECTION_UNAVAILABLE;
88 case HttpResponse::IO_ERROR:
89 return NETWORK_IO_ERROR;
90 case HttpResponse::SYNC_SERVER_ERROR:
91 // FIXME what does this mean?
92 return SYNC_SERVER_ERROR;
93 case HttpResponse::SYNC_AUTH_ERROR:
94 return SYNC_AUTH_ERROR;
95 case HttpResponse::RETRY:
96 return SERVER_RETURN_TRANSIENT_ERROR;
97 case HttpResponse::SERVER_CONNECTION_OK:
98 case HttpResponse::NONE:
99 default:
100 NOTREACHED();
101 return UNSET;
102 }
103 }
104
83 } // namespace 105 } // namespace
84 106
85 // static 107 // static
86 void SyncerProtoUtil::HandleMigrationDoneResponse( 108 void SyncerProtoUtil::HandleMigrationDoneResponse(
87 const sync_pb::ClientToServerResponse* response, 109 const sync_pb::ClientToServerResponse* response,
88 sessions::SyncSession* session) { 110 sessions::SyncSession* session) {
89 LOG_IF(ERROR, 0 >= response->migrated_data_type_id_size()) 111 LOG_IF(ERROR, 0 >= response->migrated_data_type_id_size())
90 << "MIGRATION_DONE but no types specified."; 112 << "MIGRATION_DONE but no types specified.";
91 syncable::ModelTypeSet to_migrate; 113 syncable::ModelTypeSet to_migrate;
92 for (int i = 0; i < response->migrated_data_type_id_size(); i++) { 114 for (int i = 0; i < response->migrated_data_type_id_size(); i++) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 if (error_type == sync_pb::SyncEnums::CLEAR_PENDING || 318 if (error_type == sync_pb::SyncEnums::CLEAR_PENDING ||
297 error_type == sync_pb::SyncEnums::NOT_MY_BIRTHDAY) { 319 error_type == sync_pb::SyncEnums::NOT_MY_BIRTHDAY) {
298 error.action = browser_sync::DISABLE_SYNC_ON_CLIENT; 320 error.action = browser_sync::DISABLE_SYNC_ON_CLIENT;
299 } // There is no other action we can compute for legacy server. 321 } // There is no other action we can compute for legacy server.
300 return error; 322 return error;
301 } 323 }
302 324
303 } // namespace 325 } // namespace
304 326
305 // static 327 // static
306 bool SyncerProtoUtil::PostClientToServerMessage( 328 SyncerError SyncerProtoUtil::PostClientToServerMessage(
307 const ClientToServerMessage& msg, 329 const ClientToServerMessage& msg,
308 ClientToServerResponse* response, 330 ClientToServerResponse* response,
309 SyncSession* session) { 331 SyncSession* session) {
310 332
311 CHECK(response); 333 CHECK(response);
312 DCHECK(!msg.get_updates().has_from_timestamp()); // Deprecated. 334 DCHECK(!msg.get_updates().has_from_timestamp()); // Deprecated.
313 DCHECK(!msg.get_updates().has_requested_types()); // Deprecated. 335 DCHECK(!msg.get_updates().has_requested_types()); // Deprecated.
314 DCHECK(msg.has_store_birthday() || IsVeryFirstGetUpdates(msg)) 336 DCHECK(msg.has_store_birthday() || IsVeryFirstGetUpdates(msg))
315 << "Must call AddRequestBirthday to set birthday."; 337 << "Must call AddRequestBirthday to set birthday.";
316 338
317 ScopedDirLookup dir(session->context()->directory_manager(), 339 ScopedDirLookup dir(session->context()->directory_manager(),
318 session->context()->account_name()); 340 session->context()->account_name());
319 if (!dir.good()) 341 if (!dir.good())
320 return false; 342 return DIRECTORY_LOOKUP_FAILED;
321 343
322 if (!PostAndProcessHeaders(session->context()->connection_manager(), session, 344 if (!PostAndProcessHeaders(session->context()->connection_manager(), session,
323 msg, response)) 345 msg, response)) {
324 return false; 346 // There was an error establishing communication with the server.
347 // We can not proceed beyond this point.
348 const browser_sync::HttpResponse::ServerConnectionCode server_status =
349 session->context()->connection_manager()->server_status();
350
351 DCHECK_NE(server_status, browser_sync::HttpResponse::NONE);
352 DCHECK_NE(server_status, browser_sync::HttpResponse::SERVER_CONNECTION_OK);
353
354 return ServerConnectionErrorAsSyncerError(server_status);
355 }
325 356
326 browser_sync::SyncProtocolError sync_protocol_error; 357 browser_sync::SyncProtocolError sync_protocol_error;
327 358
328 // Birthday mismatch overrides any error that is sent by the server. 359 // Birthday mismatch overrides any error that is sent by the server.
329 if (!VerifyResponseBirthday(dir, response)) { 360 if (!VerifyResponseBirthday(dir, response)) {
330 sync_protocol_error.error_type = browser_sync::NOT_MY_BIRTHDAY; 361 sync_protocol_error.error_type = browser_sync::NOT_MY_BIRTHDAY;
331 sync_protocol_error.action = 362 sync_protocol_error.action =
332 browser_sync::DISABLE_SYNC_ON_CLIENT; 363 browser_sync::DISABLE_SYNC_ON_CLIENT;
333 } else if (response->has_error()) { 364 } else if (response->has_error()) {
334 // This is a new server. Just get the error from the protocol. 365 // This is a new server. Just get the error from the protocol.
(...skipping 10 matching lines...) Expand all
345 376
346 // Inform the delegate of the error we got. 377 // Inform the delegate of the error we got.
347 session->delegate()->OnSyncProtocolError(session->TakeSnapshot()); 378 session->delegate()->OnSyncProtocolError(session->TakeSnapshot());
348 379
349 // Now do any special handling for the error type and decide on the return 380 // Now do any special handling for the error type and decide on the return
350 // value. 381 // value.
351 switch (sync_protocol_error.error_type) { 382 switch (sync_protocol_error.error_type) {
352 case browser_sync::UNKNOWN_ERROR: 383 case browser_sync::UNKNOWN_ERROR:
353 LOG(WARNING) << "Sync protocol out-of-date. The server is using a more " 384 LOG(WARNING) << "Sync protocol out-of-date. The server is using a more "
354 << "recent version."; 385 << "recent version.";
355 return false; 386 return SERVER_RETURN_UNKNOWN_ERROR;
356 case browser_sync::SYNC_SUCCESS: 387 case browser_sync::SYNC_SUCCESS:
357 LogResponseProfilingData(*response); 388 LogResponseProfilingData(*response);
358 return true; 389 return SYNCER_OK;
359 case browser_sync::THROTTLED: 390 case browser_sync::THROTTLED:
360 LOG(WARNING) << "Client silenced by server."; 391 LOG(WARNING) << "Client silenced by server.";
361 HandleThrottleError(sync_protocol_error, 392 HandleThrottleError(sync_protocol_error,
362 base::TimeTicks::Now() + GetThrottleDelay(*response), 393 base::TimeTicks::Now() + GetThrottleDelay(*response),
363 session->context(), 394 session->context(),
364 session->delegate()); 395 session->delegate());
365 return false; 396 return SERVER_RETURN_THROTTLED;
366 case browser_sync::TRANSIENT_ERROR: 397 case browser_sync::TRANSIENT_ERROR:
367 return false; 398 return SERVER_RETURN_TRANSIENT_ERROR;
368 case browser_sync::MIGRATION_DONE: 399 case browser_sync::MIGRATION_DONE:
369 HandleMigrationDoneResponse(response, session); 400 HandleMigrationDoneResponse(response, session);
370 return false; 401 return SERVER_RETURN_MIGRATION_DONE;
371 case browser_sync::CLEAR_PENDING: 402 case browser_sync::CLEAR_PENDING:
403 return SERVER_RETURN_CLEAR_PENDING;
372 case browser_sync::NOT_MY_BIRTHDAY: 404 case browser_sync::NOT_MY_BIRTHDAY:
373 return false; 405 return SERVER_RETURN_NOT_MY_BIRTHDAY;
374 default: 406 default:
375 NOTREACHED(); 407 NOTREACHED();
376 return false; 408 return UNSET;
377 } 409 }
378 } 410 }
379 411
380 // static 412 // static
381 bool SyncerProtoUtil::Compare(const syncable::Entry& local_entry, 413 bool SyncerProtoUtil::Compare(const syncable::Entry& local_entry,
382 const SyncEntity& server_entry) { 414 const SyncEntity& server_entry) {
383 const std::string name = NameFromSyncEntity(server_entry); 415 const std::string name = NameFromSyncEntity(server_entry);
384 416
385 CHECK(local_entry.Get(ID) == server_entry.id()) << 417 CHECK(local_entry.Get(ID) == server_entry.id()) <<
386 " SyncerProtoUtil::Compare precondition not met."; 418 " SyncerProtoUtil::Compare precondition not met.";
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 std::string SyncerProtoUtil::ClientToServerResponseDebugString( 532 std::string SyncerProtoUtil::ClientToServerResponseDebugString(
501 const sync_pb::ClientToServerResponse& response) { 533 const sync_pb::ClientToServerResponse& response) {
502 // Add more handlers as needed. 534 // Add more handlers as needed.
503 std::string output; 535 std::string output;
504 if (response.has_get_updates()) 536 if (response.has_get_updates())
505 output.append(GetUpdatesResponseString(response.get_updates())); 537 output.append(GetUpdatesResponseString(response.get_updates()));
506 return output; 538 return output;
507 } 539 }
508 540
509 } // namespace browser_sync 541 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncer_proto_util.h ('k') | chrome/browser/sync/sessions/session_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698