| 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 "sync/engine/net/server_connection_manager.h" | 10 #include "sync/engine/net/server_connection_manager.h" |
| 10 #include "sync/engine/syncer.h" | 11 #include "sync/engine/syncer.h" |
| 11 #include "sync/engine/syncer_types.h" | 12 #include "sync/engine/syncer_types.h" |
| 12 #include "sync/engine/throttled_data_type_tracker.h" | 13 #include "sync/engine/throttled_data_type_tracker.h" |
| 13 #include "sync/engine/traffic_logger.h" | 14 #include "sync/engine/traffic_logger.h" |
| 14 #include "sync/internal_api/public/base/model_type.h" | 15 #include "sync/internal_api/public/base/model_type.h" |
| 15 #include "sync/protocol/sync.pb.h" | 16 #include "sync/protocol/sync.pb.h" |
| 16 #include "sync/protocol/sync_enums.pb.h" | 17 #include "sync/protocol/sync_enums.pb.h" |
| 17 #include "sync/protocol/sync_protocol_error.h" | 18 #include "sync/protocol/sync_protocol_error.h" |
| 18 #include "sync/sessions/sync_session.h" | 19 #include "sync/sessions/sync_session.h" |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 error_type == sync_pb::SyncEnums::NOT_MY_BIRTHDAY) { | 340 error_type == sync_pb::SyncEnums::NOT_MY_BIRTHDAY) { |
| 340 error.action = DISABLE_SYNC_ON_CLIENT; | 341 error.action = DISABLE_SYNC_ON_CLIENT; |
| 341 } // There is no other action we can compute for legacy server. | 342 } // There is no other action we can compute for legacy server. |
| 342 return error; | 343 return error; |
| 343 } | 344 } |
| 344 | 345 |
| 345 } // namespace | 346 } // namespace |
| 346 | 347 |
| 347 // static | 348 // static |
| 348 SyncerError SyncerProtoUtil::PostClientToServerMessage( | 349 SyncerError SyncerProtoUtil::PostClientToServerMessage( |
| 349 const ClientToServerMessage& msg, | 350 ClientToServerMessage* msg, |
| 350 ClientToServerResponse* response, | 351 ClientToServerResponse* response, |
| 351 SyncSession* session) { | 352 SyncSession* session) { |
| 352 | 353 |
| 353 CHECK(response); | 354 CHECK(response); |
| 354 DCHECK(!msg.get_updates().has_from_timestamp()); // Deprecated. | 355 DCHECK(!msg->get_updates().has_from_timestamp()); // Deprecated. |
| 355 DCHECK(!msg.get_updates().has_requested_types()); // Deprecated. | 356 DCHECK(!msg->get_updates().has_requested_types()); // Deprecated. |
| 356 DCHECK(msg.has_store_birthday() || IsVeryFirstGetUpdates(msg)) | 357 |
| 357 << "Must call AddRequestBirthday to set birthday."; | 358 // Add must-have fields. |
| 358 DCHECK(msg.has_bag_of_chips()) | 359 SetProtocolVersion(msg); |
| 359 << "Must call AddBagOfChips to set bag_of_chips."; | 360 AddRequestBirthday(session->context()->directory(), msg); |
| 361 DCHECK(msg->has_store_birthday() || IsVeryFirstGetUpdates(*msg)); |
| 362 AddBagOfChips(session->context()->directory(), msg); |
| 363 msg->set_api_key(google_apis::GetAPIKey()); |
| 360 | 364 |
| 361 syncable::Directory* dir = session->context()->directory(); | 365 syncable::Directory* dir = session->context()->directory(); |
| 362 | 366 |
| 363 LogClientToServerMessage(msg); | 367 LogClientToServerMessage(*msg); |
| 364 session->context()->traffic_recorder()->RecordClientToServerMessage(msg); | 368 session->context()->traffic_recorder()->RecordClientToServerMessage(*msg); |
| 365 if (!PostAndProcessHeaders(session->context()->connection_manager(), session, | 369 if (!PostAndProcessHeaders(session->context()->connection_manager(), session, |
| 366 msg, response)) { | 370 *msg, response)) { |
| 367 // There was an error establishing communication with the server. | 371 // There was an error establishing communication with the server. |
| 368 // We can not proceed beyond this point. | 372 // We can not proceed beyond this point. |
| 369 const HttpResponse::ServerConnectionCode server_status = | 373 const HttpResponse::ServerConnectionCode server_status = |
| 370 session->context()->connection_manager()->server_status(); | 374 session->context()->connection_manager()->server_status(); |
| 371 | 375 |
| 372 DCHECK_NE(server_status, HttpResponse::NONE); | 376 DCHECK_NE(server_status, HttpResponse::NONE); |
| 373 DCHECK_NE(server_status, HttpResponse::SERVER_CONNECTION_OK); | 377 DCHECK_NE(server_status, HttpResponse::SERVER_CONNECTION_OK); |
| 374 | 378 |
| 375 return ServerConnectionErrorAsSyncerError(server_status); | 379 return ServerConnectionErrorAsSyncerError(server_status); |
| 376 } | 380 } |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 std::string SyncerProtoUtil::ClientToServerResponseDebugString( | 597 std::string SyncerProtoUtil::ClientToServerResponseDebugString( |
| 594 const ClientToServerResponse& response) { | 598 const ClientToServerResponse& response) { |
| 595 // Add more handlers as needed. | 599 // Add more handlers as needed. |
| 596 std::string output; | 600 std::string output; |
| 597 if (response.has_get_updates()) | 601 if (response.has_get_updates()) |
| 598 output.append(GetUpdatesResponseString(response.get_updates())); | 602 output.append(GetUpdatesResponseString(response.get_updates())); |
| 599 return output; | 603 return output; |
| 600 } | 604 } |
| 601 | 605 |
| 602 } // namespace syncer | 606 } // namespace syncer |
| OLD | NEW |