| 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 <map> |
| 8 |
| 7 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 8 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 9 #include "google_apis/google_api_keys.h" | 11 #include "google_apis/google_api_keys.h" |
| 10 #include "sync/engine/net/server_connection_manager.h" | 12 #include "sync/engine/net/server_connection_manager.h" |
| 11 #include "sync/engine/syncer.h" | 13 #include "sync/engine/syncer.h" |
| 12 #include "sync/engine/syncer_types.h" | 14 #include "sync/engine/syncer_types.h" |
| 13 #include "sync/engine/traffic_logger.h" | 15 #include "sync/engine/traffic_logger.h" |
| 14 #include "sync/internal_api/public/base/model_type.h" | 16 #include "sync/internal_api/public/base/model_type.h" |
| 15 #include "sync/protocol/sync_enums.pb.h" | 17 #include "sync/protocol/sync_enums.pb.h" |
| 16 #include "sync/protocol/sync_protocol_error.h" | 18 #include "sync/protocol/sync_protocol_error.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 case sync_pb::SyncEnums::DISABLED_BY_ADMIN: | 125 case sync_pb::SyncEnums::DISABLED_BY_ADMIN: |
| 124 return DISABLED_BY_ADMIN; | 126 return DISABLED_BY_ADMIN; |
| 125 case sync_pb::SyncEnums::USER_ROLLBACK: | 127 case sync_pb::SyncEnums::USER_ROLLBACK: |
| 126 return USER_ROLLBACK; | 128 return USER_ROLLBACK; |
| 127 case sync_pb::SyncEnums::PARTIAL_FAILURE: | 129 case sync_pb::SyncEnums::PARTIAL_FAILURE: |
| 128 return PARTIAL_FAILURE; | 130 return PARTIAL_FAILURE; |
| 129 case sync_pb::SyncEnums::CLIENT_DATA_OBSOLETE: | 131 case sync_pb::SyncEnums::CLIENT_DATA_OBSOLETE: |
| 130 return CLIENT_DATA_OBSOLETE; | 132 return CLIENT_DATA_OBSOLETE; |
| 131 case sync_pb::SyncEnums::UNKNOWN: | 133 case sync_pb::SyncEnums::UNKNOWN: |
| 132 return UNKNOWN_ERROR; | 134 return UNKNOWN_ERROR; |
| 133 case sync_pb::SyncEnums::USER_NOT_ACTIVATED: | |
| 134 case sync_pb::SyncEnums::AUTH_INVALID: | |
| 135 case sync_pb::SyncEnums::ACCESS_DENIED: | |
| 136 return INVALID_CREDENTIAL; | |
| 137 default: | 135 default: |
| 138 NOTREACHED(); | 136 NOTREACHED(); |
| 139 return UNKNOWN_ERROR; | 137 return UNKNOWN_ERROR; |
| 140 } | 138 } |
| 141 } | 139 } |
| 142 | 140 |
| 143 ClientAction PBActionToClientAction(const sync_pb::SyncEnums::Action& action) { | 141 ClientAction PBActionToClientAction(const sync_pb::SyncEnums::Action& action) { |
| 144 switch (action) { | 142 switch (action) { |
| 145 case sync_pb::SyncEnums::UPGRADE_CLIENT: | 143 case sync_pb::SyncEnums::UPGRADE_CLIENT: |
| 146 return UPGRADE_CLIENT; | 144 return UPGRADE_CLIENT; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm, | 336 bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm, |
| 339 sessions::SyncSession* session, | 337 sessions::SyncSession* session, |
| 340 const ClientToServerMessage& msg, | 338 const ClientToServerMessage& msg, |
| 341 ClientToServerResponse* response) { | 339 ClientToServerResponse* response) { |
| 342 ServerConnectionManager::PostBufferParams params; | 340 ServerConnectionManager::PostBufferParams params; |
| 343 DCHECK(msg.has_protocol_version()); | 341 DCHECK(msg.has_protocol_version()); |
| 344 DCHECK_EQ(msg.protocol_version(), | 342 DCHECK_EQ(msg.protocol_version(), |
| 345 ClientToServerMessage::default_instance().protocol_version()); | 343 ClientToServerMessage::default_instance().protocol_version()); |
| 346 msg.SerializeToString(¶ms.buffer_in); | 344 msg.SerializeToString(¶ms.buffer_in); |
| 347 | 345 |
| 348 ScopedServerStatusWatcher server_status_watcher(scm, ¶ms.response); | |
| 349 // Fills in params.buffer_out and params.response. | 346 // Fills in params.buffer_out and params.response. |
| 350 if (!scm->PostBufferWithCachedAuth(¶ms, &server_status_watcher)) { | 347 if (!scm->PostBufferWithCachedAuth(¶ms)) { |
| 351 LOG(WARNING) << "Error posting from syncer:" << params.response; | 348 LOG(WARNING) << "Error posting from syncer:" << params.response; |
| 352 return false; | 349 return false; |
| 353 } | 350 } |
| 354 | 351 |
| 355 if (response->ParseFromString(params.buffer_out)) { | 352 return response->ParseFromString(params.buffer_out); |
| 356 // TODO(tim): This is an egregious layering violation (bug 35060). | |
| 357 switch (response->error_code()) { | |
| 358 case sync_pb::SyncEnums::ACCESS_DENIED: | |
| 359 case sync_pb::SyncEnums::AUTH_INVALID: | |
| 360 case sync_pb::SyncEnums::USER_NOT_ACTIVATED: | |
| 361 // Fires on ScopedServerStatusWatcher | |
| 362 params.response.server_status = HttpResponse::SYNC_AUTH_ERROR; | |
| 363 return false; | |
| 364 default: | |
| 365 return true; | |
| 366 } | |
| 367 } | |
| 368 | |
| 369 return false; | |
| 370 } | 353 } |
| 371 | 354 |
| 372 base::TimeDelta SyncerProtoUtil::GetThrottleDelay( | 355 base::TimeDelta SyncerProtoUtil::GetThrottleDelay( |
| 373 const ClientToServerResponse& response) { | 356 const ClientToServerResponse& response) { |
| 374 base::TimeDelta throttle_delay = | 357 base::TimeDelta throttle_delay = |
| 375 base::TimeDelta::FromSeconds(kSyncDelayAfterThrottled); | 358 base::TimeDelta::FromSeconds(kSyncDelayAfterThrottled); |
| 376 if (response.has_client_command()) { | 359 if (response.has_client_command()) { |
| 377 const sync_pb::ClientCommand& command = response.client_command(); | 360 const sync_pb::ClientCommand& command = response.client_command(); |
| 378 if (command.has_throttle_delay_seconds()) { | 361 if (command.has_throttle_delay_seconds()) { |
| 379 throttle_delay = | 362 throttle_delay = |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 std::string SyncerProtoUtil::ClientToServerResponseDebugString( | 601 std::string SyncerProtoUtil::ClientToServerResponseDebugString( |
| 619 const ClientToServerResponse& response) { | 602 const ClientToServerResponse& response) { |
| 620 // Add more handlers as needed. | 603 // Add more handlers as needed. |
| 621 std::string output; | 604 std::string output; |
| 622 if (response.has_get_updates()) | 605 if (response.has_get_updates()) |
| 623 output.append(GetUpdatesResponseString(response.get_updates())); | 606 output.append(GetUpdatesResponseString(response.get_updates())); |
| 624 return output; | 607 return output; |
| 625 } | 608 } |
| 626 | 609 |
| 627 } // namespace syncer | 610 } // namespace syncer |
| OLD | NEW |