#ifndef COMPONENTS_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_
#define COMPONENTS_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_
#include <string>
#include "base/gtest_prod_util.h"
#include "base/time/time.h"
#include "components/sync/base/model_type.h"
#include "components/sync/base/syncer_error.h"
#include "components/sync/engine/cycle/sync_cycle.h"
namespace sync_pb {
class ClientToServerMessage;
class ClientToServerResponse;
class ClientToServerResponse_Error;
class SyncEntity;
}
namespace syncer {
class ServerConnectionManager;
struct SyncProtocolError;
ModelTypeSet GetTypesToMigrate(const sync_pb::ClientToServerResponse& response);
SyncProtocolError ConvertErrorPBToSyncProtocolError(
const sync_pb::ClientToServerResponse_Error& error);
class SyncerProtoUtil {
public:
SyncerProtoUtil(const SyncerProtoUtil&) = delete;
SyncerProtoUtil& operator=(const SyncerProtoUtil&) = delete;
static void AddRequiredFieldsToClientToServerMessage(
const SyncCycle* cycle,
sync_pb::ClientToServerMessage* msg);
static SyncerError PostClientToServerMessage(
const sync_pb::ClientToServerMessage& msg,
sync_pb::ClientToServerResponse* response,
SyncCycle* cycle,
ModelTypeSet* partial_failure_data_types);
static bool ShouldMaintainPosition(const sync_pb::SyncEntity& sync_entity);
static bool ShouldMaintainHierarchy(const sync_pb::SyncEntity& sync_entity);
static std::string ClientToServerResponseDebugString(
const sync_pb::ClientToServerResponse& response);
static std::string SyncEntityDebugString(const sync_pb::SyncEntity& entry);
static void SetProtocolVersion(sync_pb::ClientToServerMessage* msg);
private:
SyncerProtoUtil() = default;
static SyncProtocolError GetProtocolErrorFromResponse(
const sync_pb::ClientToServerResponse& response,
SyncCycleContext* context);
static bool IsSyncDisabledByAdmin(
const sync_pb::ClientToServerResponse& response);
static bool PostAndProcessHeaders(ServerConnectionManager* scm,
const sync_pb::ClientToServerMessage& msg,
sync_pb::ClientToServerResponse* response);
static SyncerError HandleClientToServerMessageResponse(
const sync_pb::ClientToServerResponse& response,
SyncCycle* cycle,
ModelTypeSet* partial_failure_data_types);
static base::TimeDelta GetThrottleDelay(
const sync_pb::ClientToServerResponse& response);
friend class LoopbackServerTest;
friend class SyncerProtoUtilTest;
FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, AddRequestBirthday);
FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, PostAndProcessHeaders);
FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, HandleThrottlingNoDatatypes);
FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, HandleThrottlingWithDatatypes);
};
}
#endif