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 "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 "google_apis/google_api_keys.h" | 9 #include "google_apis/google_api_keys.h" |
10 #include "sync/engine/net/server_connection_manager.h" | 10 #include "sync/engine/net/server_connection_manager.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 case sync_pb::SyncEnums::NOT_MY_BIRTHDAY: | 114 case sync_pb::SyncEnums::NOT_MY_BIRTHDAY: |
115 return NOT_MY_BIRTHDAY; | 115 return NOT_MY_BIRTHDAY; |
116 case sync_pb::SyncEnums::THROTTLED: | 116 case sync_pb::SyncEnums::THROTTLED: |
117 return THROTTLED; | 117 return THROTTLED; |
118 case sync_pb::SyncEnums::CLEAR_PENDING: | 118 case sync_pb::SyncEnums::CLEAR_PENDING: |
119 return CLEAR_PENDING; | 119 return CLEAR_PENDING; |
120 case sync_pb::SyncEnums::TRANSIENT_ERROR: | 120 case sync_pb::SyncEnums::TRANSIENT_ERROR: |
121 return TRANSIENT_ERROR; | 121 return TRANSIENT_ERROR; |
122 case sync_pb::SyncEnums::MIGRATION_DONE: | 122 case sync_pb::SyncEnums::MIGRATION_DONE: |
123 return MIGRATION_DONE; | 123 return MIGRATION_DONE; |
124 case sync_pb::SyncEnums::DISABLED_BY_ADMIN: | |
125 return DISABLED_BY_ADMIN; | |
124 case sync_pb::SyncEnums::UNKNOWN: | 126 case sync_pb::SyncEnums::UNKNOWN: |
125 return UNKNOWN_ERROR; | 127 return UNKNOWN_ERROR; |
126 case sync_pb::SyncEnums::USER_NOT_ACTIVATED: | 128 case sync_pb::SyncEnums::USER_NOT_ACTIVATED: |
127 case sync_pb::SyncEnums::AUTH_INVALID: | 129 case sync_pb::SyncEnums::AUTH_INVALID: |
128 case sync_pb::SyncEnums::ACCESS_DENIED: | 130 case sync_pb::SyncEnums::ACCESS_DENIED: |
129 return INVALID_CREDENTIAL; | 131 return INVALID_CREDENTIAL; |
130 default: | 132 default: |
131 NOTREACHED(); | 133 NOTREACHED(); |
132 return UNKNOWN_ERROR; | 134 return UNKNOWN_ERROR; |
133 } | 135 } |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 } | 336 } |
335 | 337 |
336 // TODO(lipalani) : Rename these function names as per the CR for issue 7740067. | 338 // TODO(lipalani) : Rename these function names as per the CR for issue 7740067. |
337 SyncProtocolError ConvertLegacyErrorCodeToNewError( | 339 SyncProtocolError ConvertLegacyErrorCodeToNewError( |
338 const sync_pb::SyncEnums::ErrorType& error_type) { | 340 const sync_pb::SyncEnums::ErrorType& error_type) { |
339 SyncProtocolError error; | 341 SyncProtocolError error; |
340 error.error_type = ConvertSyncProtocolErrorTypePBToLocalType(error_type); | 342 error.error_type = ConvertSyncProtocolErrorTypePBToLocalType(error_type); |
341 if (error_type == sync_pb::SyncEnums::CLEAR_PENDING || | 343 if (error_type == sync_pb::SyncEnums::CLEAR_PENDING || |
342 error_type == sync_pb::SyncEnums::NOT_MY_BIRTHDAY) { | 344 error_type == sync_pb::SyncEnums::NOT_MY_BIRTHDAY) { |
343 error.action = DISABLE_SYNC_ON_CLIENT; | 345 error.action = DISABLE_SYNC_ON_CLIENT; |
346 } else if (error_type == sync_pb::SyncEnums::DISABLED_BY_ADMIN) { | |
347 error.action = STOP_SYNC_FOR_DISABLED_ACCOUNT; | |
tim (not reviewing)
2013/05/13 04:18:58
nit - indent should be two spaces from 'if' (345 w
pavely
2013/05/13 22:37:09
Done.
| |
344 } // There is no other action we can compute for legacy server. | 348 } // There is no other action we can compute for legacy server. |
345 return error; | 349 return error; |
346 } | 350 } |
347 | 351 |
348 } // namespace | 352 } // namespace |
349 | 353 |
350 // static | 354 // static |
351 SyncerError SyncerProtoUtil::PostClientToServerMessage( | 355 SyncerError SyncerProtoUtil::PostClientToServerMessage( |
352 ClientToServerMessage* msg, | 356 ClientToServerMessage* msg, |
353 ClientToServerResponse* response, | 357 ClientToServerResponse* response, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 // Birthday mismatch overrides any error that is sent by the server. | 398 // Birthday mismatch overrides any error that is sent by the server. |
395 if (!VerifyResponseBirthday(*response, dir)) { | 399 if (!VerifyResponseBirthday(*response, dir)) { |
396 sync_protocol_error.error_type = NOT_MY_BIRTHDAY; | 400 sync_protocol_error.error_type = NOT_MY_BIRTHDAY; |
397 sync_protocol_error.action = | 401 sync_protocol_error.action = |
398 DISABLE_SYNC_ON_CLIENT; | 402 DISABLE_SYNC_ON_CLIENT; |
399 } else if (response->has_error()) { | 403 } else if (response->has_error()) { |
400 // This is a new server. Just get the error from the protocol. | 404 // This is a new server. Just get the error from the protocol. |
401 sync_protocol_error = ConvertErrorPBToLocalType(response->error()); | 405 sync_protocol_error = ConvertErrorPBToLocalType(response->error()); |
402 } else { | 406 } else { |
403 // Legacy server implementation. Compute the error based on |error_code|. | 407 // Legacy server implementation. Compute the error based on |error_code|. |
408 ::sync_pb::SyncEnums_ErrorType error_code = response->error_code(); | |
409 // error_code = sync_pb::SyncEnums::DISABLED_BY_ADMIN; | |
tim (not reviewing)
2013/05/13 04:18:58
This needs to be fixed / cleaned up.
pavely
2013/05/13 22:37:09
Done.
| |
404 sync_protocol_error = ConvertLegacyErrorCodeToNewError( | 410 sync_protocol_error = ConvertLegacyErrorCodeToNewError( |
405 response->error_code()); | 411 /*response->error_code()*/ error_code); |
406 } | 412 } |
407 | 413 |
408 // Now set the error into the status so the layers above us could read it. | 414 // Now set the error into the status so the layers above us could read it. |
409 sessions::StatusController* status = session->mutable_status_controller(); | 415 sessions::StatusController* status = session->mutable_status_controller(); |
410 status->set_sync_protocol_error(sync_protocol_error); | 416 status->set_sync_protocol_error(sync_protocol_error); |
411 | 417 |
412 // Inform the delegate of the error we got. | 418 // Inform the delegate of the error we got. |
413 session->delegate()->OnSyncProtocolError(session->TakeSnapshot()); | 419 session->delegate()->OnSyncProtocolError(session->TakeSnapshot()); |
414 | 420 |
415 // Update our state for any other commands we've received. | 421 // Update our state for any other commands we've received. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 LOG_IF(ERROR, 0 >= response->migrated_data_type_id_size()) | 466 LOG_IF(ERROR, 0 >= response->migrated_data_type_id_size()) |
461 << "MIGRATION_DONE but no types specified."; | 467 << "MIGRATION_DONE but no types specified."; |
462 // TODO(akalin): This should be a set union. | 468 // TODO(akalin): This should be a set union. |
463 session->mutable_status_controller()-> | 469 session->mutable_status_controller()-> |
464 set_types_needing_local_migration(GetTypesToMigrate(*response)); | 470 set_types_needing_local_migration(GetTypesToMigrate(*response)); |
465 return SERVER_RETURN_MIGRATION_DONE; | 471 return SERVER_RETURN_MIGRATION_DONE; |
466 case CLEAR_PENDING: | 472 case CLEAR_PENDING: |
467 return SERVER_RETURN_CLEAR_PENDING; | 473 return SERVER_RETURN_CLEAR_PENDING; |
468 case NOT_MY_BIRTHDAY: | 474 case NOT_MY_BIRTHDAY: |
469 return SERVER_RETURN_NOT_MY_BIRTHDAY; | 475 return SERVER_RETURN_NOT_MY_BIRTHDAY; |
476 case DISABLED_BY_ADMIN: | |
477 return SERVER_RETURN_DISABLED_BY_ADMIN; | |
470 default: | 478 default: |
471 NOTREACHED(); | 479 NOTREACHED(); |
472 return UNSET; | 480 return UNSET; |
473 } | 481 } |
474 } | 482 } |
475 | 483 |
476 // static | 484 // static |
477 bool SyncerProtoUtil::Compare(const syncable::Entry& local_entry, | 485 bool SyncerProtoUtil::Compare(const syncable::Entry& local_entry, |
478 const sync_pb::SyncEntity& server_entry) { | 486 const sync_pb::SyncEntity& server_entry) { |
479 const std::string name = NameFromSyncEntity(server_entry); | 487 const std::string name = NameFromSyncEntity(server_entry); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 std::string SyncerProtoUtil::ClientToServerResponseDebugString( | 622 std::string SyncerProtoUtil::ClientToServerResponseDebugString( |
615 const ClientToServerResponse& response) { | 623 const ClientToServerResponse& response) { |
616 // Add more handlers as needed. | 624 // Add more handlers as needed. |
617 std::string output; | 625 std::string output; |
618 if (response.has_get_updates()) | 626 if (response.has_get_updates()) |
619 output.append(GetUpdatesResponseString(response.get_updates())); | 627 output.append(GetUpdatesResponseString(response.get_updates())); |
620 return output; | 628 return output; |
621 } | 629 } |
622 | 630 |
623 } // namespace syncer | 631 } // namespace syncer |
OLD | NEW |