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