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