summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-12 18:15:45 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-12 18:15:45 +0000
commit447a5b6333539c309e015ee8f98ff6d9e131fa85 (patch)
tree4357764ce00fdfbff7809d348a16a5f601bd3b08 /sync
parent13d5e1af907ece2266b391c322344fb0af43d9f0 (diff)
downloadchromium_src-447a5b6333539c309e015ee8f98ff6d9e131fa85.zip
chromium_src-447a5b6333539c309e015ee8f98ff6d9e131fa85.tar.gz
chromium_src-447a5b6333539c309e015ee8f98ff6d9e131fa85.tar.bz2
Remove syncproto.h
Replace sync/engine/syncproto.h with sync/syncable/syncable_proto_util.h and .cc. The tasks that used to be performed by member functions of the syncer:: proto wrapper classes are now handled by static member functions. Unfortunately, serialization and de-serialization of syncable::Id to/from proto fields has gotten a bit uglier. On the other hand, it's now much less magical and mysterious. The test intended to prevent regressions of crbug.com/134715 has been replaced with a DCHECK. We'll have to rely on it to ensure that the protocol_version field is always explicitly set. BUG=136454 TEST= Review URL: https://chromiumcodereview.appspot.com/10735041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146393 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r--sync/engine/build_commit_command.cc26
-rw-r--r--sync/engine/build_commit_command.h7
-rw-r--r--sync/engine/build_commit_command_unittest.cc2
-rw-r--r--sync/engine/commit.cc9
-rw-r--r--sync/engine/download_updates_command.cc10
-rw-r--r--sync/engine/net/server_connection_manager.cc1
-rw-r--r--sync/engine/process_commit_response_command.cc53
-rw-r--r--sync/engine/process_commit_response_command.h24
-rw-r--r--sync/engine/process_commit_response_command_unittest.cc31
-rw-r--r--sync/engine/process_updates_command.cc18
-rw-r--r--sync/engine/store_timestamps_command.cc2
-rw-r--r--sync/engine/syncer.cc3
-rw-r--r--sync/engine/syncer.h1
-rw-r--r--sync/engine/syncer_proto_util.cc39
-rw-r--r--sync/engine/syncer_proto_util.h19
-rw-r--r--sync/engine/syncer_proto_util_unittest.cc12
-rw-r--r--sync/engine/syncer_unittest.cc1
-rw-r--r--sync/engine/syncer_util.cc38
-rw-r--r--sync/engine/syncer_util.h16
-rw-r--r--sync/engine/syncproto.h86
-rw-r--r--sync/engine/syncproto_unittest.cc18
-rw-r--r--sync/engine/verify_updates_command.cc30
-rw-r--r--sync/engine/verify_updates_command.h3
-rw-r--r--sync/engine/verify_updates_command_unittest.cc5
-rw-r--r--sync/sessions/session_state.h2
-rw-r--r--sync/sessions/status_controller.cc3
-rw-r--r--sync/sessions/status_controller.h4
-rw-r--r--sync/sessions/status_controller_unittest.cc2
-rw-r--r--sync/sync.gyp4
-rw-r--r--sync/syncable/DEPS3
-rw-r--r--sync/syncable/model_type.cc10
-rw-r--r--sync/syncable/syncable_proto_util.cc32
-rw-r--r--sync/syncable/syncable_proto_util.h36
-rw-r--r--sync/syncable/syncable_unittest.cc14
-rw-r--r--sync/test/engine/mock_connection_manager.cc3
35 files changed, 277 insertions, 290 deletions
diff --git a/sync/engine/build_commit_command.cc b/sync/engine/build_commit_command.cc
index fd23adc..32237f9 100644
--- a/sync/engine/build_commit_command.cc
+++ b/sync/engine/build_commit_command.cc
@@ -12,11 +12,13 @@
#include "base/string_util.h"
#include "sync/engine/syncer_proto_util.h"
#include "sync/protocol/bookmark_specifics.pb.h"
+#include "sync/protocol/sync.pb.h"
#include "sync/sessions/ordered_commit_set.h"
#include "sync/sessions/sync_session.h"
#include "sync/syncable/directory.h"
#include "sync/syncable/mutable_entry.h"
#include "sync/syncable/syncable_changes_version.h"
+#include "sync/syncable/syncable_proto_util.h"
#include "sync/syncable/write_transaction.h"
#include "sync/util/time.h"
@@ -54,14 +56,14 @@ int64 BuildCommitCommand::GetGap() {
BuildCommitCommand::BuildCommitCommand(
const sessions::OrderedCommitSet& batch_commit_set,
- ClientToServerMessage* commit_message)
+ sync_pb::ClientToServerMessage* commit_message)
: batch_commit_set_(batch_commit_set), commit_message_(commit_message) {
}
BuildCommitCommand::~BuildCommitCommand() {}
void BuildCommitCommand::AddExtensionsActivityToMessage(
- SyncSession* session, CommitMessage* message) {
+ SyncSession* session, sync_pb::CommitMessage* message) {
// We only send ExtensionsActivity to the server if bookmarks are being
// committed.
ExtensionsActivityMonitor* monitor = session->context()->extensions_monitor();
@@ -92,23 +94,25 @@ void BuildCommitCommand::AddExtensionsActivityToMessage(
}
namespace {
-void SetEntrySpecifics(MutableEntry* meta_entry, SyncEntity* sync_entry) {
+void SetEntrySpecifics(MutableEntry* meta_entry,
+ sync_pb::SyncEntity* sync_entry) {
// Add the new style extension and the folder bit.
sync_entry->mutable_specifics()->CopyFrom(meta_entry->Get(SPECIFICS));
sync_entry->set_folder(meta_entry->Get(syncable::IS_DIR));
- DCHECK(meta_entry->GetModelType() == sync_entry->GetModelType());
+ DCHECK_EQ(meta_entry->GetModelType(), GetModelType(*sync_entry));
}
} // namespace
SyncerError BuildCommitCommand::ExecuteImpl(SyncSession* session) {
commit_message_->set_share(session->context()->account_name());
- commit_message_->set_message_contents(ClientToServerMessage::COMMIT);
+ commit_message_->set_message_contents(sync_pb::ClientToServerMessage::COMMIT);
- CommitMessage* commit_message = commit_message_->mutable_commit();
+ sync_pb::CommitMessage* commit_message = commit_message_->mutable_commit();
commit_message->set_cache_guid(
session->write_transaction()->directory()->cache_guid());
AddExtensionsActivityToMessage(session, commit_message);
+ SyncerProtoUtil::SetProtocolVersion(commit_message_);
SyncerProtoUtil::AddRequestBirthday(
session->write_transaction()->directory(), commit_message_);
@@ -122,9 +126,8 @@ SyncerError BuildCommitCommand::ExecuteImpl(SyncSession* session) {
for (size_t i = 0; i < batch_commit_set_.Size(); i++) {
Id id = batch_commit_set_.GetCommitIdAt(i);
- SyncEntity* sync_entry =
- static_cast<SyncEntity*>(commit_message->add_entries());
- sync_entry->set_id(id);
+ sync_pb::SyncEntity* sync_entry = commit_message->add_entries();
+ sync_entry->set_id_string(SyncableIdToProto(id));
MutableEntry meta_entry(session->write_transaction(),
syncable::GET_BY_ID, id);
CHECK(meta_entry.good());
@@ -157,7 +160,7 @@ SyncerError BuildCommitCommand::ExecuteImpl(SyncSession* session) {
} else {
new_parent_id = meta_entry.Get(syncable::PARENT_ID);
}
- sync_entry->set_parent_id(new_parent_id);
+ sync_entry->set_parent_id_string(SyncableIdToProto(new_parent_id));
// If our parent has changed, send up the old one so the server
// can correctly deal with multiple parents.
@@ -167,7 +170,8 @@ SyncerError BuildCommitCommand::ExecuteImpl(SyncSession* session) {
if (new_parent_id != meta_entry.Get(syncable::SERVER_PARENT_ID) &&
0 != meta_entry.Get(syncable::BASE_VERSION) &&
syncable::CHANGES_VERSION != meta_entry.Get(syncable::BASE_VERSION)) {
- sync_entry->set_old_parent_id(meta_entry.Get(syncable::SERVER_PARENT_ID));
+ sync_entry->set_old_parent_id(
+ SyncableIdToProto(meta_entry.Get(syncable::SERVER_PARENT_ID)));
}
int64 version = meta_entry.Get(syncable::BASE_VERSION);
diff --git a/sync/engine/build_commit_command.h b/sync/engine/build_commit_command.h
index 0adab28..c1712a6 100644
--- a/sync/engine/build_commit_command.h
+++ b/sync/engine/build_commit_command.h
@@ -9,7 +9,6 @@
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "sync/engine/syncer_command.h"
-#include "sync/engine/syncproto.h"
#include "sync/syncable/entry_kernel.h"
namespace syncer {
@@ -37,7 +36,7 @@ class BuildCommitCommand : public SyncerCommand {
// The commit_message parameter is an output parameter which will contain the
// fully initialized commit message once ExecuteImpl() has been called.
BuildCommitCommand(const sessions::OrderedCommitSet& batch_commit_set,
- ClientToServerMessage* commit_message);
+ sync_pb::ClientToServerMessage* commit_message);
virtual ~BuildCommitCommand();
// SyncerCommand implementation.
@@ -52,7 +51,7 @@ class BuildCommitCommand : public SyncerCommand {
static int64 GetGap();
void AddExtensionsActivityToMessage(sessions::SyncSession* session,
- CommitMessage* message);
+ sync_pb::CommitMessage* message);
// Helper for computing position. Find the numeric position value
// of the closest already-synced entry. |direction| must be one of
// NEXT_ID or PREV_ID; this parameter controls the search direction.
@@ -70,7 +69,7 @@ class BuildCommitCommand : public SyncerCommand {
const sessions::OrderedCommitSet& batch_commit_set_;
// Output parameter; see constructor comment.
- ClientToServerMessage* commit_message_;
+ sync_pb::ClientToServerMessage* commit_message_;
};
} // namespace syncer
diff --git a/sync/engine/build_commit_command_unittest.cc b/sync/engine/build_commit_command_unittest.cc
index 66ba14b..6ad3c55 100644
--- a/sync/engine/build_commit_command_unittest.cc
+++ b/sync/engine/build_commit_command_unittest.cc
@@ -17,7 +17,7 @@ class BuildCommitCommandTest : public SyncerCommandTest {
private:
sessions::OrderedCommitSet batch_commit_set_;
- ClientToServerMessage commit_message_;
+ sync_pb::ClientToServerMessage commit_message_;
protected:
BuildCommitCommand command_;
diff --git a/sync/engine/commit.cc b/sync/engine/commit.cc
index 02bee1e..731643a 100644
--- a/sync/engine/commit.cc
+++ b/sync/engine/commit.cc
@@ -63,15 +63,12 @@ void ClearSyncingBits(syncable::Directory* dir,
// return value of this function is true.
bool PrepareCommitMessage(sessions::SyncSession* session,
sessions::OrderedCommitSet* commit_set,
- ClientToServerMessage* commit_message) {
+ sync_pb::ClientToServerMessage* commit_message) {
TRACE_EVENT0("sync", "PrepareCommitMessage");
commit_set->Clear();
commit_message->Clear();
- // TODO(134769): This is a temporary fix for crbug.com/134715.
- commit_message->set_protocol_version(commit_message->protocol_version());
-
WriteTransaction trans(FROM_HERE, SYNCER, session->context()->directory());
sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans);
@@ -96,10 +93,10 @@ bool PrepareCommitMessage(sessions::SyncSession* session,
SyncerError BuildAndPostCommitsImpl(Syncer* syncer,
sessions::SyncSession* session,
sessions::OrderedCommitSet* commit_set) {
- ClientToServerMessage commit_message;
+ sync_pb::ClientToServerMessage commit_message;
while (!syncer->ExitRequested() &&
PrepareCommitMessage(session, commit_set, &commit_message)) {
- ClientToServerResponse commit_response;
+ sync_pb::ClientToServerResponse commit_response;
DVLOG(1) << "Sending commit message.";
TRACE_EVENT_BEGIN0("sync", "PostCommit");
diff --git a/sync/engine/download_updates_command.cc b/sync/engine/download_updates_command.cc
index 48e4acf..22839f6 100644
--- a/sync/engine/download_updates_command.cc
+++ b/sync/engine/download_updates_command.cc
@@ -9,7 +9,6 @@
#include "base/command_line.h"
#include "sync/engine/syncer.h"
#include "sync/engine/syncer_proto_util.h"
-#include "sync/engine/syncproto.h"
#include "sync/internal_api/public/base/model_type_payload_map.h"
#include "sync/syncable/directory.h"
@@ -27,13 +26,13 @@ DownloadUpdatesCommand::DownloadUpdatesCommand(
DownloadUpdatesCommand::~DownloadUpdatesCommand() {}
SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) {
- ClientToServerMessage client_to_server_message;
- ClientToServerResponse update_response;
+ sync_pb::ClientToServerMessage client_to_server_message;
+ sync_pb::ClientToServerResponse update_response;
client_to_server_message.set_share(session->context()->account_name());
client_to_server_message.set_message_contents(
- ClientToServerMessage::GET_UPDATES);
- GetUpdatesMessage* get_updates =
+ sync_pb::ClientToServerMessage::GET_UPDATES);
+ sync_pb::GetUpdatesMessage* get_updates =
client_to_server_message.mutable_get_updates();
get_updates->set_create_mobile_bookmarks_folder(
create_mobile_bookmarks_folder_);
@@ -74,6 +73,7 @@ SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) {
get_updates->mutable_caller_info()->set_notifications_enabled(
session->context()->notifications_enabled());
+ SyncerProtoUtil::SetProtocolVersion(&client_to_server_message);
SyncerProtoUtil::AddRequestBirthday(dir, &client_to_server_message);
DebugInfo* debug_info = client_to_server_message.mutable_debug_info();
diff --git a/sync/engine/net/server_connection_manager.cc b/sync/engine/net/server_connection_manager.cc
index 048ff52..2e1f1f8 100644
--- a/sync/engine/net/server_connection_manager.cc
+++ b/sync/engine/net/server_connection_manager.cc
@@ -16,7 +16,6 @@
#include "net/http/http_status_code.h"
#include "sync/engine/net/url_translator.h"
#include "sync/engine/syncer.h"
-#include "sync/engine/syncproto.h"
#include "sync/protocol/sync.pb.h"
#include "sync/syncable/directory.h"
diff --git a/sync/engine/process_commit_response_command.cc b/sync/engine/process_commit_response_command.cc
index 26dca0e..be65c2e 100644
--- a/sync/engine/process_commit_response_command.cc
+++ b/sync/engine/process_commit_response_command.cc
@@ -13,11 +13,11 @@
#include "base/location.h"
#include "sync/engine/syncer_proto_util.h"
#include "sync/engine/syncer_util.h"
-#include "sync/engine/syncproto.h"
#include "sync/sessions/sync_session.h"
#include "sync/syncable/entry.h"
#include "sync/syncable/mutable_entry.h"
#include "sync/syncable/read_transaction.h"
+#include "sync/syncable/syncable_proto_util.h"
#include "sync/syncable/syncable_util.h"
#include "sync/syncable/write_transaction.h"
#include "sync/util/time.h"
@@ -25,6 +25,7 @@
using std::set;
using std::string;
using std::vector;
+using sync_pb::CommitResponse;
namespace syncer {
@@ -52,8 +53,8 @@ using syncable::SYNCING;
ProcessCommitResponseCommand::ProcessCommitResponseCommand(
const sessions::OrderedCommitSet& commit_set,
- const ClientToServerMessage& commit_message,
- const ClientToServerResponse& commit_response)
+ const sync_pb::ClientToServerMessage& commit_message,
+ const sync_pb::ClientToServerResponse& commit_response)
: commit_set_(commit_set),
commit_message_(commit_message),
commit_response_(commit_response) {
@@ -189,7 +190,7 @@ SyncerError ProcessCommitResponseCommand::ProcessCommitResponse(
}
}
-void LogServerError(const CommitResponse_EntryResponse& res) {
+void LogServerError(const sync_pb::CommitResponse_EntryResponse& res) {
if (res.has_error_message())
LOG(WARNING) << " " << res.error_message();
else
@@ -199,13 +200,11 @@ void LogServerError(const CommitResponse_EntryResponse& res) {
CommitResponse::ResponseType
ProcessCommitResponseCommand::ProcessSingleCommitResponse(
syncable::WriteTransaction* trans,
- const sync_pb::CommitResponse_EntryResponse& pb_server_entry,
+ const sync_pb::CommitResponse_EntryResponse& server_entry,
const sync_pb::SyncEntity& commit_request_entry,
const syncable::Id& pre_commit_id,
set<syncable::Id>* deleted_folders) {
- const CommitResponse_EntryResponse& server_entry =
- *static_cast<const CommitResponse_EntryResponse*>(&pb_server_entry);
MutableEntry local_entry(trans, GET_BY_ID, pre_commit_id);
CHECK(local_entry.good());
bool syncing_was_set = local_entry.Get(SYNCING);
@@ -249,8 +248,10 @@ ProcessCommitResponseCommand::ProcessSingleCommitResponse(
DCHECK_EQ(CommitResponse::SUCCESS, response) << response;
// Check to see if we've been given the ID of an existing entry. If so treat
// it as an error response and retry later.
- if (pre_commit_id != server_entry.id()) {
- Entry e(trans, GET_BY_ID, server_entry.id());
+ const syncable::Id& server_entry_id =
+ SyncableIdFromProto(server_entry.id_string());
+ if (pre_commit_id != server_entry_id) {
+ Entry e(trans, GET_BY_ID, server_entry_id);
if (e.good()) {
LOG(ERROR) << "Got duplicate id when commiting id: " << pre_commit_id <<
". Treating as an error return";
@@ -269,7 +270,7 @@ ProcessCommitResponseCommand::ProcessSingleCommitResponse(
const string& ProcessCommitResponseCommand::GetResultingPostCommitName(
const sync_pb::SyncEntity& committed_entry,
- const CommitResponse_EntryResponse& entry_response) {
+ const sync_pb::CommitResponse_EntryResponse& entry_response) {
const string& response_name =
SyncerProtoUtil::NameFromCommitEntryResponse(entry_response);
if (!response_name.empty())
@@ -279,7 +280,7 @@ const string& ProcessCommitResponseCommand::GetResultingPostCommitName(
bool ProcessCommitResponseCommand::UpdateVersionAfterCommit(
const sync_pb::SyncEntity& committed_entry,
- const CommitResponse_EntryResponse& entry_response,
+ const sync_pb::CommitResponse_EntryResponse& entry_response,
const syncable::Id& pre_commit_id,
syncable::MutableEntry* local_entry) {
int64 old_version = local_entry->Get(BASE_VERSION);
@@ -299,8 +300,8 @@ bool ProcessCommitResponseCommand::UpdateVersionAfterCommit(
}
if (bad_commit_version) {
LOG(ERROR) << "Bad version in commit return for " << *local_entry
- << " new_id:" << entry_response.id() << " new_version:"
- << entry_response.version();
+ << " new_id:" << SyncableIdFromProto(entry_response.id_string())
+ << " new_version:" << entry_response.version();
return false;
}
@@ -315,33 +316,35 @@ bool ProcessCommitResponseCommand::UpdateVersionAfterCommit(
}
bool ProcessCommitResponseCommand::ChangeIdAfterCommit(
- const CommitResponse_EntryResponse& entry_response,
+ const sync_pb::CommitResponse_EntryResponse& entry_response,
const syncable::Id& pre_commit_id,
syncable::MutableEntry* local_entry) {
syncable::WriteTransaction* trans = local_entry->write_transaction();
- if (entry_response.id() != pre_commit_id) {
+ const syncable::Id& entry_response_id =
+ SyncableIdFromProto(entry_response.id_string());
+ if (entry_response_id != pre_commit_id) {
if (pre_commit_id.ServerKnows()) {
// The server can sometimes generate a new ID on commit; for example,
// when committing an undeletion.
DVLOG(1) << " ID changed while committing an old entry. "
- << pre_commit_id << " became " << entry_response.id() << ".";
+ << pre_commit_id << " became " << entry_response_id << ".";
}
- MutableEntry same_id(trans, GET_BY_ID, entry_response.id());
+ MutableEntry same_id(trans, GET_BY_ID, entry_response_id);
// We should trap this before this function.
if (same_id.good()) {
- LOG(ERROR) << "ID clash with id " << entry_response.id()
+ LOG(ERROR) << "ID clash with id " << entry_response_id
<< " during commit " << same_id;
return false;
}
- ChangeEntryIDAndUpdateChildren(trans, local_entry, entry_response.id());
- DVLOG(1) << "Changing ID to " << entry_response.id();
+ ChangeEntryIDAndUpdateChildren(trans, local_entry, entry_response_id);
+ DVLOG(1) << "Changing ID to " << entry_response_id;
}
return true;
}
void ProcessCommitResponseCommand::UpdateServerFieldsAfterCommit(
const sync_pb::SyncEntity& committed_entry,
- const CommitResponse_EntryResponse& entry_response,
+ const sync_pb::CommitResponse_EntryResponse& entry_response,
syncable::MutableEntry* local_entry) {
// We just committed an entry successfully, and now we want to make our view
@@ -392,7 +395,7 @@ void ProcessCommitResponseCommand::UpdateServerFieldsAfterCommit(
void ProcessCommitResponseCommand::OverrideClientFieldsAfterCommit(
const sync_pb::SyncEntity& committed_entry,
- const CommitResponse_EntryResponse& entry_response,
+ const sync_pb::CommitResponse_EntryResponse& entry_response,
syncable::MutableEntry* local_entry) {
if (committed_entry.deleted()) {
// If an entry's been deleted, nothing else matters.
@@ -432,7 +435,7 @@ void ProcessCommitResponseCommand::OverrideClientFieldsAfterCommit(
void ProcessCommitResponseCommand::ProcessSuccessfulCommitResponse(
const sync_pb::SyncEntity& committed_entry,
- const CommitResponse_EntryResponse& entry_response,
+ const sync_pb::CommitResponse_EntryResponse& entry_response,
const syncable::Id& pre_commit_id, syncable::MutableEntry* local_entry,
bool syncing_was_set, set<syncable::Id>* deleted_folders) {
DCHECK(local_entry->Get(IS_UNSYNCED));
@@ -441,8 +444,8 @@ void ProcessCommitResponseCommand::ProcessSuccessfulCommitResponse(
if (!UpdateVersionAfterCommit(committed_entry, entry_response, pre_commit_id,
local_entry)) {
LOG(ERROR) << "Bad version in commit return for " << *local_entry
- << " new_id:" << entry_response.id() << " new_version:"
- << entry_response.version();
+ << " new_id:" << SyncableIdFromProto(entry_response.id_string())
+ << " new_version:" << entry_response.version();
return;
}
diff --git a/sync/engine/process_commit_response_command.h b/sync/engine/process_commit_response_command.h
index 96d8178..a849255 100644
--- a/sync/engine/process_commit_response_command.h
+++ b/sync/engine/process_commit_response_command.h
@@ -11,7 +11,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "sync/engine/model_changing_syncer_command.h"
-#include "sync/engine/syncproto.h"
+#include "sync/protocol/sync.pb.h"
namespace syncer {
@@ -52,8 +52,8 @@ class ProcessCommitResponseCommand : public ModelChangingSyncerCommand {
// or a serious error was encountered.
ProcessCommitResponseCommand(
const sessions::OrderedCommitSet& commit_set,
- const ClientToServerMessage& commit_message,
- const ClientToServerResponse& commit_response);
+ const sync_pb::ClientToServerMessage& commit_message,
+ const sync_pb::ClientToServerResponse& commit_response);
virtual ~ProcessCommitResponseCommand();
protected:
@@ -64,7 +64,7 @@ class ProcessCommitResponseCommand : public ModelChangingSyncerCommand {
sessions::SyncSession* session) OVERRIDE;
private:
- CommitResponse::ResponseType ProcessSingleCommitResponse(
+ sync_pb::CommitResponse::ResponseType ProcessSingleCommitResponse(
syncable::WriteTransaction* trans,
const sync_pb::CommitResponse_EntryResponse& pb_commit_response,
const sync_pb::SyncEntity& pb_committed_entry,
@@ -76,7 +76,7 @@ class ProcessCommitResponseCommand : public ModelChangingSyncerCommand {
void ProcessSuccessfulCommitResponse(
const sync_pb::SyncEntity& committed_entry,
- const CommitResponse_EntryResponse& entry_response,
+ const sync_pb::CommitResponse_EntryResponse& entry_response,
const syncable::Id& pre_commit_id, syncable::MutableEntry* local_entry,
bool syncing_was_set, std::set<syncable::Id>* deleted_folders);
@@ -84,14 +84,14 @@ class ProcessCommitResponseCommand : public ModelChangingSyncerCommand {
// Helper for ProcessSuccessfulCommitResponse.
bool UpdateVersionAfterCommit(
const sync_pb::SyncEntity& committed_entry,
- const CommitResponse_EntryResponse& entry_response,
+ const sync_pb::CommitResponse_EntryResponse& entry_response,
const syncable::Id& pre_commit_id,
syncable::MutableEntry* local_entry);
// If the server generated an ID for us during a commit, apply the new ID.
// Helper for ProcessSuccessfulCommitResponse.
bool ChangeIdAfterCommit(
- const CommitResponse_EntryResponse& entry_response,
+ const sync_pb::CommitResponse_EntryResponse& entry_response,
const syncable::Id& pre_commit_id,
syncable::MutableEntry* local_entry);
@@ -99,7 +99,7 @@ class ProcessCommitResponseCommand : public ModelChangingSyncerCommand {
// Helper for ProcessSuccessfulCommitResponse.
void UpdateServerFieldsAfterCommit(
const sync_pb::SyncEntity& committed_entry,
- const CommitResponse_EntryResponse& entry_response,
+ const sync_pb::CommitResponse_EntryResponse& entry_response,
syncable::MutableEntry* local_entry);
// The server can override some values during a commit; the overridden values
@@ -110,13 +110,13 @@ class ProcessCommitResponseCommand : public ModelChangingSyncerCommand {
// Helper for ProcessSuccessfulCommitResponse.
void OverrideClientFieldsAfterCommit(
const sync_pb::SyncEntity& committed_entry,
- const CommitResponse_EntryResponse& entry_response,
+ const sync_pb::CommitResponse_EntryResponse& entry_response,
syncable::MutableEntry* local_entry);
// Helper to extract the final name from the protobufs.
const std::string& GetResultingPostCommitName(
const sync_pb::SyncEntity& committed_entry,
- const CommitResponse_EntryResponse& entry_response);
+ const sync_pb::CommitResponse_EntryResponse& entry_response);
// Helper to clean up in case of failure.
void ClearSyncingBits(
@@ -124,8 +124,8 @@ class ProcessCommitResponseCommand : public ModelChangingSyncerCommand {
const std::vector<syncable::Id>& commit_ids);
const sessions::OrderedCommitSet& commit_set_;
- const ClientToServerMessage& commit_message_;
- const ClientToServerResponse& commit_response_;
+ const sync_pb::ClientToServerMessage& commit_message_;
+ const sync_pb::ClientToServerResponse& commit_response_;
DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommand);
};
diff --git a/sync/engine/process_commit_response_command_unittest.cc b/sync/engine/process_commit_response_command_unittest.cc
index be9fa22..b51f3e1 100644
--- a/sync/engine/process_commit_response_command_unittest.cc
+++ b/sync/engine/process_commit_response_command_unittest.cc
@@ -15,16 +15,20 @@
#include "sync/syncable/mutable_entry.h"
#include "sync/syncable/read_transaction.h"
#include "sync/syncable/syncable_id.h"
+#include "sync/syncable/syncable_proto_util.h"
#include "sync/syncable/write_transaction.h"
#include "sync/test/engine/fake_model_worker.h"
#include "sync/test/engine/syncer_command_test.h"
#include "sync/test/engine/test_id_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
+using std::string;
+using sync_pb::ClientToServerMessage;
+using sync_pb::CommitResponse;
+
namespace syncer {
using sessions::SyncSession;
-using std::string;
using syncable::BASE_VERSION;
using syncable::Entry;
using syncable::IS_DIR;
@@ -118,8 +122,8 @@ class ProcessCommitResponseCommandTest : public SyncerCommandTest {
const string& name,
syncer::ModelType model_type,
sessions::OrderedCommitSet *commit_set,
- syncer::ClientToServerMessage *commit,
- syncer::ClientToServerResponse *response) {
+ sync_pb::ClientToServerMessage *commit,
+ sync_pb::ClientToServerResponse *response) {
bool is_folder = true;
int64 metahandle = 0;
CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type,
@@ -136,14 +140,13 @@ class ProcessCommitResponseCommandTest : public SyncerCommandTest {
// Add to the commit message.
commit->set_message_contents(ClientToServerMessage::COMMIT);
- SyncEntity* entity = static_cast<SyncEntity*>(
- commit->mutable_commit()->add_entries());
+ sync_pb::SyncEntity* entity = commit->mutable_commit()->add_entries();
entity->set_non_unique_name(name);
entity->set_folder(is_folder);
- entity->set_parent_id(parent_id);
+ entity->set_parent_id_string(SyncableIdToProto(parent_id));
entity->set_version(entry.Get(syncable::BASE_VERSION));
entity->mutable_specifics()->CopyFrom(entry.Get(syncable::SPECIFICS));
- entity->set_id(item_id);
+ entity->set_id_string(SyncableIdToProto(item_id));
// Add to the response message.
response->set_error_code(sync_pb::SyncEnums::SUCCESS);
@@ -172,7 +175,7 @@ class ProcessCommitResponseCommandTest : public SyncerCommandTest {
}
}
- void SetLastErrorCode(CommitResponse::ResponseType error_code,
+ void SetLastErrorCode(sync_pb::CommitResponse::ResponseType error_code,
sync_pb::ClientToServerResponse* response) {
sync_pb::CommitResponse_EntryResponse* entry_response =
response->mutable_commit()->mutable_entryresponse(
@@ -190,8 +193,8 @@ class ProcessCommitResponseCommandTest : public SyncerCommandTest {
TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) {
sessions::OrderedCommitSet commit_set(session()->routing_info());
- syncer::ClientToServerMessage request;
- syncer::ClientToServerResponse response;
+ sync_pb::ClientToServerMessage request;
+ sync_pb::ClientToServerResponse response;
Id bookmark_folder_id = id_factory_.NewLocalId();
Id bookmark_id1 = id_factory_.NewLocalId();
@@ -274,8 +277,8 @@ TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) {
// of the children.
TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) {
sessions::OrderedCommitSet commit_set(session()->routing_info());
- syncer::ClientToServerMessage request;
- syncer::ClientToServerResponse response;
+ sync_pb::ClientToServerMessage request;
+ sync_pb::ClientToServerResponse response;
// Create the parent folder, a new item whose ID will change on commit.
Id folder_id = id_factory_.NewLocalId();
@@ -402,8 +405,8 @@ INSTANTIATE_TEST_CASE_P(ProcessCommitResponse,
// depending on the test parameter.
TEST_P(MixedResult, ExtensionActivity) {
sessions::OrderedCommitSet commit_set(session()->routing_info());
- syncer::ClientToServerMessage request;
- syncer::ClientToServerResponse response;
+ sync_pb::ClientToServerMessage request;
+ sync_pb::ClientToServerResponse response;
EXPECT_NE(routing_info().find(syncer::BOOKMARKS)->second,
routing_info().find(syncer::AUTOFILL)->second)
diff --git a/sync/engine/process_updates_command.cc b/sync/engine/process_updates_command.cc
index f239a6a..ccf3def 100644
--- a/sync/engine/process_updates_command.cc
+++ b/sync/engine/process_updates_command.cc
@@ -11,10 +11,10 @@
#include "sync/engine/syncer.h"
#include "sync/engine/syncer_proto_util.h"
#include "sync/engine/syncer_util.h"
-#include "sync/engine/syncproto.h"
#include "sync/sessions/sync_session.h"
#include "sync/syncable/directory.h"
#include "sync/syncable/mutable_entry.h"
+#include "sync/syncable/syncable_proto_util.h"
#include "sync/syncable/syncable_util.h"
#include "sync/syncable/write_transaction.h"
#include "sync/util/cryptographer.h"
@@ -72,12 +72,13 @@ SyncerError ProcessUpdatesCommand::ModelChangingExecuteImpl(
namespace {
// Returns true if the entry is still ok to process.
-bool ReverifyEntry(syncable::WriteTransaction* trans, const SyncEntity& entry,
+bool ReverifyEntry(syncable::WriteTransaction* trans,
+ const sync_pb::SyncEntity& entry,
syncable::MutableEntry* same_id) {
const bool deleted = entry.has_deleted() && entry.deleted();
- const bool is_directory = entry.IsFolder();
- const syncer::ModelType model_type = entry.GetModelType();
+ const bool is_directory = IsFolder(entry);
+ const syncer::ModelType model_type = GetModelType(entry);
return VERIFY_SUCCESS == VerifyUpdateConsistency(trans,
entry,
@@ -90,12 +91,10 @@ bool ReverifyEntry(syncable::WriteTransaction* trans, const SyncEntity& entry,
// Process a single update. Will avoid touching global state.
ServerUpdateProcessingResult ProcessUpdatesCommand::ProcessUpdate(
- const sync_pb::SyncEntity& proto_update,
+ const sync_pb::SyncEntity& update,
const Cryptographer* cryptographer,
syncable::WriteTransaction* const trans) {
-
- const SyncEntity& update = *static_cast<const SyncEntity*>(&proto_update);
- syncable::Id server_id = update.id();
+ const syncable::Id& server_id = SyncableIdFromProto(update.id_string());
const std::string name = SyncerProtoUtil::NameFromSyncEntity(update);
// Look to see if there's a local item that should recieve this update,
@@ -150,7 +149,8 @@ ServerUpdateProcessingResult ProcessUpdatesCommand::ProcessUpdate(
// overwrite SERVER_SPECIFICS.
// MTIME, CTIME, and NON_UNIQUE_NAME are not enforced.
if (!update.deleted() && !target_entry.Get(syncable::SERVER_IS_DEL) &&
- (update.parent_id() == target_entry.Get(syncable::SERVER_PARENT_ID)) &&
+ (SyncableIdFromProto(update.parent_id_string()) ==
+ target_entry.Get(syncable::SERVER_PARENT_ID)) &&
(update.position_in_parent() ==
target_entry.Get(syncable::SERVER_POSITION_IN_PARENT)) &&
update.has_specifics() && update.specifics().has_encrypted() &&
diff --git a/sync/engine/store_timestamps_command.cc b/sync/engine/store_timestamps_command.cc
index 5911fca..0925e33 100644
--- a/sync/engine/store_timestamps_command.cc
+++ b/sync/engine/store_timestamps_command.cc
@@ -18,7 +18,7 @@ SyncerError StoreTimestampsCommand::ExecuteImpl(
sessions::SyncSession* session) {
syncable::Directory* dir = session->context()->directory();
- const GetUpdatesResponse& updates =
+ const sync_pb::GetUpdatesResponse& updates =
session->status_controller().updates_response().get_updates();
sessions::StatusController* status = session->mutable_status_controller();
diff --git a/sync/engine/syncer.cc b/sync/engine/syncer.cc
index ff28c73..e813bc3 100644
--- a/sync/engine/syncer.cc
+++ b/sync/engine/syncer.cc
@@ -22,7 +22,6 @@
#include "sync/engine/resolve_conflicts_command.h"
#include "sync/engine/store_timestamps_command.h"
#include "sync/engine/syncer_types.h"
-#include "sync/engine/syncproto.h"
#include "sync/engine/throttled_data_type_tracker.h"
#include "sync/engine/verify_updates_command.h"
#include "sync/syncable/mutable_entry.h"
@@ -244,7 +243,7 @@ void Syncer::SyncShare(sessions::SyncSession* session,
}
void Syncer::ProcessClientCommand(sessions::SyncSession* session) {
- const ClientToServerResponse& response =
+ const sync_pb::ClientToServerResponse& response =
session->status_controller().updates_response();
if (!response.has_client_command())
return;
diff --git a/sync/engine/syncer.h b/sync/engine/syncer.h
index 6d05d43..81271ab 100644
--- a/sync/engine/syncer.h
+++ b/sync/engine/syncer.h
@@ -13,7 +13,6 @@
#include "base/synchronization/lock.h"
#include "sync/engine/conflict_resolver.h"
#include "sync/engine/syncer_types.h"
-#include "sync/engine/syncproto.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/sessions/sync_session.h"
#include "sync/util/extensions_activity_monitor.h"
diff --git a/sync/engine/syncer_proto_util.cc b/sync/engine/syncer_proto_util.cc
index 8a20b95..c88b7c3 100644
--- a/sync/engine/syncer_proto_util.cc
+++ b/sync/engine/syncer_proto_util.cc
@@ -19,10 +19,13 @@
#include "sync/syncable/directory.h"
#include "sync/syncable/entry.h"
#include "sync/syncable/syncable-inl.h"
+#include "sync/syncable/syncable_proto_util.h"
#include "sync/util/time.h"
using std::string;
using std::stringstream;
+using sync_pb::ClientToServerMessage;
+using sync_pb::ClientToServerResponse;
namespace syncer {
@@ -107,7 +110,7 @@ SyncerError ServerConnectionErrorAsSyncerError(
// static
void SyncerProtoUtil::HandleMigrationDoneResponse(
- const sync_pb::ClientToServerResponse* response,
+ const ClientToServerResponse* response,
sessions::SyncSession* session) {
LOG_IF(ERROR, 0 >= response->migrated_data_type_id_size())
<< "MIGRATION_DONE but no types specified.";
@@ -160,11 +163,21 @@ void SyncerProtoUtil::AddRequestBirthday(syncable::Directory* dir,
}
// static
+void SyncerProtoUtil::SetProtocolVersion(ClientToServerMessage* msg) {
+ const int current_version =
+ ClientToServerMessage::default_instance().protocol_version();
+ msg->set_protocol_version(current_version);
+}
+
+// static
bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm,
sessions::SyncSession* session,
const ClientToServerMessage& msg,
ClientToServerResponse* response) {
ServerConnectionManager::PostBufferParams params;
+ DCHECK(msg.has_protocol_version());
+ DCHECK_EQ(msg.protocol_version(),
+ ClientToServerMessage::default_instance().protocol_version());
msg.SerializeToString(&params.buffer_in);
ScopedServerStatusWatcher server_status_watcher(scm, &params.response);
@@ -199,7 +212,7 @@ bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm,
}
base::TimeDelta SyncerProtoUtil::GetThrottleDelay(
- const sync_pb::ClientToServerResponse& response) {
+ const ClientToServerResponse& response) {
base::TimeDelta throttle_delay =
base::TimeDelta::FromSeconds(kSyncDelayAfterThrottled);
if (response.has_client_command()) {
@@ -289,7 +302,7 @@ syncer::ClientAction ConvertClientActionPBToLocalClientAction(
}
syncer::SyncProtocolError ConvertErrorPBToLocalType(
- const sync_pb::ClientToServerResponse::Error& error) {
+ const ClientToServerResponse::Error& error) {
syncer::SyncProtocolError sync_protocol_error;
sync_protocol_error.error_type = ConvertSyncProtocolErrorTypePBToLocalType(
error.error_type());
@@ -415,15 +428,12 @@ SyncerError SyncerProtoUtil::PostClientToServerMessage(
// static
bool SyncerProtoUtil::Compare(const syncable::Entry& local_entry,
- const SyncEntity& server_entry) {
+ const sync_pb::SyncEntity& server_entry) {
const std::string name = NameFromSyncEntity(server_entry);
- CHECK(local_entry.Get(ID) == server_entry.id()) <<
- " SyncerProtoUtil::Compare precondition not met.";
- CHECK(server_entry.version() == local_entry.Get(BASE_VERSION)) <<
- " SyncerProtoUtil::Compare precondition not met.";
- CHECK(!local_entry.Get(IS_UNSYNCED)) <<
- " SyncerProtoUtil::Compare precondition not met.";
+ CHECK_EQ(local_entry.Get(ID), SyncableIdFromProto(server_entry.id_string()));
+ CHECK_EQ(server_entry.version(), local_entry.Get(BASE_VERSION));
+ CHECK(!local_entry.Get(IS_UNSYNCED));
if (local_entry.Get(IS_DEL) && server_entry.deleted())
return true;
@@ -439,11 +449,12 @@ bool SyncerProtoUtil::Compare(const syncable::Entry& local_entry,
LOG(WARNING) << "Client name mismatch";
return false;
}
- if (local_entry.Get(PARENT_ID) != server_entry.parent_id()) {
+ if (local_entry.Get(PARENT_ID) !=
+ SyncableIdFromProto(server_entry.parent_id_string())) {
LOG(WARNING) << "Parent ID mismatch";
return false;
}
- if (local_entry.Get(IS_DIR) != server_entry.IsFolder()) {
+ if (local_entry.Get(IS_DIR) != IsFolder(server_entry)) {
LOG(WARNING) << "Dir field mismatch";
return false;
}
@@ -492,7 +503,7 @@ const std::string& SyncerProtoUtil::NameFromSyncEntity(
// static
const std::string& SyncerProtoUtil::NameFromCommitEntryResponse(
- const CommitResponse_EntryResponse& entry) {
+ const sync_pb::CommitResponse_EntryResponse& entry) {
if (entry.has_non_unique_name())
return entry.non_unique_name();
return entry.name();
@@ -534,7 +545,7 @@ std::string GetUpdatesResponseString(
} // namespace
std::string SyncerProtoUtil::ClientToServerResponseDebugString(
- const sync_pb::ClientToServerResponse& response) {
+ const ClientToServerResponse& response) {
// Add more handlers as needed.
std::string output;
if (response.has_get_updates())
diff --git a/sync/engine/syncer_proto_util.h b/sync/engine/syncer_proto_util.h
index 689f168..53e3118 100644
--- a/sync/engine/syncer_proto_util.h
+++ b/sync/engine/syncer_proto_util.h
@@ -15,17 +15,17 @@
#include "sync/syncable/blob.h"
namespace sync_pb {
+class ClientToServerMessage;
class ClientToServerResponse;
+class CommitResponse_EntryResponse;
class EntitySpecifics;
+class SyncEntity;
}
namespace syncer {
-class ClientToServerMessage;
class ThrottledDataTypeTracker;
class ServerConnectionManager;
-class SyncEntity;
-class CommitResponse_EntryResponse;
namespace sessions {
class SyncProtocolError;
@@ -43,7 +43,7 @@ class SyncerProtoUtil {
// Returns true on success. Also handles store birthday verification: will
// produce a SyncError if the birthday is incorrect.
static SyncerError PostClientToServerMessage(
- const ClientToServerMessage& msg,
+ const sync_pb::ClientToServerMessage& msg,
sync_pb::ClientToServerResponse* response,
sessions::SyncSession* session);
@@ -55,7 +55,7 @@ class SyncerProtoUtil {
// local and server values diverge. However, this almost always indicates a
// sync bug somewhere earlier in the sync cycle.
static bool Compare(const syncable::Entry& local_entry,
- const SyncEntity& server_entry);
+ const sync_pb::SyncEntity& server_entry);
// Utility methods for converting between syncable::Blobs and protobuf byte
// fields.
@@ -72,7 +72,7 @@ class SyncerProtoUtil {
// Extract the name field from a commit entry response.
static const std::string& NameFromCommitEntryResponse(
- const CommitResponse_EntryResponse& entry);
+ const sync_pb::CommitResponse_EntryResponse& entry);
// EntitySpecifics is used as a filter for the GetUpdates message to tell
// the server which datatypes to send back. This adds a datatype so that
@@ -90,7 +90,10 @@ class SyncerProtoUtil {
// Pull the birthday from the dir and put it into the msg.
static void AddRequestBirthday(syncable::Directory* dir,
- ClientToServerMessage* msg);
+ sync_pb::ClientToServerMessage* msg);
+
+ // Set the protocol version field in the outgoing message.
+ static void SetProtocolVersion(sync_pb::ClientToServerMessage* msg);
private:
SyncerProtoUtil() {}
@@ -112,7 +115,7 @@ class SyncerProtoUtil {
// headers. Decode the server response.
static bool PostAndProcessHeaders(syncer::ServerConnectionManager* scm,
sessions::SyncSession* session,
- const ClientToServerMessage& msg,
+ const sync_pb::ClientToServerMessage& msg,
sync_pb::ClientToServerResponse* response);
static base::TimeDelta GetThrottleDelay(
diff --git a/sync/engine/syncer_proto_util_unittest.cc b/sync/engine/syncer_proto_util_unittest.cc
index 107dd55..21735d8 100644
--- a/sync/engine/syncer_proto_util_unittest.cc
+++ b/sync/engine/syncer_proto_util_unittest.cc
@@ -10,7 +10,6 @@
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/time.h"
-#include "sync/engine/syncproto.h"
#include "sync/engine/throttled_data_type_tracker.h"
#include "sync/internal_api/public/base/model_type_test_util.h"
#include "sync/protocol/bookmark_specifics.pb.h"
@@ -27,6 +26,10 @@
using ::testing::_;
+using sync_pb::ClientToServerMessage;
+using sync_pb::CommitResponse_EntryResponse;
+using sync_pb::SyncEntity;
+
namespace syncer {
using sessions::SyncSessionContext;
@@ -172,7 +175,7 @@ class SyncerProtoUtilTest : public testing::Test {
TEST_F(SyncerProtoUtilTest, VerifyResponseBirthday) {
// Both sides empty
EXPECT_TRUE(directory()->store_birthday().empty());
- ClientToServerResponse response;
+ sync_pb::ClientToServerResponse response;
EXPECT_FALSE(SyncerProtoUtil::VerifyResponseBirthday(directory(), &response));
// Remote set, local empty
@@ -219,7 +222,7 @@ class DummyConnectionManager : public syncer::ServerConnectionManager {
return false;
}
- ClientToServerResponse response;
+ sync_pb::ClientToServerResponse response;
if (access_denied_) {
response.set_error_code(sync_pb::SyncEnums::ACCESS_DENIED);
}
@@ -244,9 +247,10 @@ class DummyConnectionManager : public syncer::ServerConnectionManager {
TEST_F(SyncerProtoUtilTest, PostAndProcessHeaders) {
DummyConnectionManager dcm;
ClientToServerMessage msg;
+ SyncerProtoUtil::SetProtocolVersion(&msg);
msg.set_share("required");
msg.set_message_contents(ClientToServerMessage::GET_UPDATES);
- ClientToServerResponse response;
+ sync_pb::ClientToServerResponse response;
dcm.set_send_error(true);
EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL,
diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc
index 7545e26..c468623 100644
--- a/sync/engine/syncer_unittest.cc
+++ b/sync/engine/syncer_unittest.cc
@@ -29,7 +29,6 @@
#include "sync/engine/sync_scheduler.h"
#include "sync/engine/syncer.h"
#include "sync/engine/syncer_proto_util.h"
-#include "sync/engine/syncproto.h"
#include "sync/engine/throttled_data_type_tracker.h"
#include "sync/engine/traffic_recorder.h"
#include "sync/internal_api/public/base/model_type.h"
diff --git a/sync/engine/syncer_util.cc b/sync/engine/syncer_util.cc
index d50f487..51f46a0 100644
--- a/sync/engine/syncer_util.cc
+++ b/sync/engine/syncer_util.cc
@@ -14,7 +14,6 @@
#include "sync/engine/conflict_resolver.h"
#include "sync/engine/syncer_proto_util.h"
#include "sync/engine/syncer_types.h"
-#include "sync/engine/syncproto.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/protocol/bookmark_specifics.pb.h"
#include "sync/protocol/nigori_specifics.pb.h"
@@ -26,6 +25,7 @@
#include "sync/syncable/nigori_util.h"
#include "sync/syncable/read_transaction.h"
#include "sync/syncable/syncable_changes_version.h"
+#include "sync/syncable/syncable_proto_util.h"
#include "sync/syncable/syncable_util.h"
#include "sync/syncable/write_transaction.h"
#include "sync/util/cryptographer.h"
@@ -71,13 +71,14 @@ using syncable::WriteTransaction;
syncable::Id FindLocalIdToUpdate(
syncable::BaseTransaction* trans,
- const SyncEntity& update) {
+ const sync_pb::SyncEntity& update) {
// Expected entry points of this function:
// SyncEntity has NOT been applied to SERVER fields.
// SyncEntity has NOT been applied to LOCAL fields.
// DB has not yet been modified, no entries created for this update.
const std::string& client_id = trans->directory()->cache_guid();
+ const syncable::Id& update_id = SyncableIdFromProto(update.id_string());
if (update.has_client_defined_unique_tag() &&
!update.client_defined_unique_tag().empty()) {
@@ -106,10 +107,10 @@ syncable::Id FindLocalIdToUpdate(
// TODO(chron): Unit test the case with IS_DEL and make sure.
if (local_entry.good()) {
if (local_entry.Get(ID).ServerKnows()) {
- if (local_entry.Get(ID) != update.id()) {
+ if (local_entry.Get(ID) != update_id) {
// Case 2.
LOG(WARNING) << "Duplicated client tag.";
- if (local_entry.Get(ID) < update.id()) {
+ if (local_entry.Get(ID) < update_id) {
// Signal an error; drop this update on the floor. Note that
// we don't server delete the item, because we don't allow it to
// exist locally at all. So the item will remain orphaned on
@@ -118,7 +119,7 @@ syncable::Id FindLocalIdToUpdate(
}
}
// Target this change to the existing local entry; later,
- // we'll change the ID of the local entry to update.id()
+ // we'll change the ID of the local entry to update_id
// if needed.
return local_entry.Get(ID);
} else {
@@ -172,14 +173,14 @@ syncable::Id FindLocalIdToUpdate(
DCHECK(!local_entry.Get(ID).ServerKnows());
DVLOG(1) << "Reuniting lost commit response IDs. server id: "
- << update.id() << " local id: " << local_entry.Get(ID)
+ << update_id << " local id: " << local_entry.Get(ID)
<< " new version: " << new_version;
return local_entry.Get(ID);
}
}
// Fallback: target an entry having the server ID, creating one if needed.
- return update.id();
+ return update_id;
}
UpdateAttemptResponse AttemptToUpdateEntry(
@@ -341,7 +342,7 @@ void UpdateBookmarkSpecifics(const std::string& singleton_tag,
// Pass in name and checksum because of UTF8 conversion.
void UpdateServerFieldsFromUpdate(
MutableEntry* target,
- const SyncEntity& update,
+ const sync_pb::SyncEntity& update,
const std::string& name) {
if (update.deleted()) {
if (target->Get(SERVER_IS_DEL)) {
@@ -368,14 +369,14 @@ void UpdateServerFieldsFromUpdate(
return;
}
- DCHECK(target->Get(ID) == update.id())
+ DCHECK_EQ(target->Get(ID), SyncableIdFromProto(update.id_string()))
<< "ID Changing not supported here";
- target->Put(SERVER_PARENT_ID, update.parent_id());
+ target->Put(SERVER_PARENT_ID, SyncableIdFromProto(update.parent_id_string()));
target->Put(SERVER_NON_UNIQUE_NAME, name);
target->Put(SERVER_VERSION, update.version());
target->Put(SERVER_CTIME, ProtoTimeToTime(update.ctime()));
target->Put(SERVER_MTIME, ProtoTimeToTime(update.mtime()));
- target->Put(SERVER_IS_DIR, update.IsFolder());
+ target->Put(SERVER_IS_DIR, IsFolder(update));
if (update.has_server_defined_unique_tag()) {
const std::string& tag = update.server_defined_unique_tag();
target->Put(UNIQUE_SERVER_TAG, tag);
@@ -386,12 +387,12 @@ void UpdateServerFieldsFromUpdate(
}
// Store the datatype-specific part as a protobuf.
if (update.has_specifics()) {
- DCHECK(update.GetModelType() != syncer::UNSPECIFIED)
+ DCHECK_NE(GetModelType(update), UNSPECIFIED)
<< "Storing unrecognized datatype in sync database.";
target->Put(SERVER_SPECIFICS, update.specifics());
} else if (update.has_bookmarkdata()) {
// Legacy protocol response for bookmark data.
- const SyncEntity::BookmarkData& bookmark = update.bookmarkdata();
+ const sync_pb::SyncEntity::BookmarkData& bookmark = update.bookmarkdata();
UpdateBookmarkSpecifics(update.server_defined_unique_tag(),
bookmark.bookmark_url(),
bookmark.bookmark_favicon(),
@@ -572,7 +573,7 @@ void MarkDeletedChildrenSynced(
}
VerifyResult VerifyNewEntry(
- const SyncEntity& update,
+ const sync_pb::SyncEntity& update,
syncable::Entry* target,
const bool deleted) {
if (target->good()) {
@@ -591,13 +592,14 @@ VerifyResult VerifyNewEntry(
// consistency rules.
VerifyResult VerifyUpdateConsistency(
syncable::WriteTransaction* trans,
- const SyncEntity& update,
+ const sync_pb::SyncEntity& update,
syncable::MutableEntry* target,
const bool deleted,
const bool is_directory,
syncer::ModelType model_type) {
CHECK(target->good());
+ const syncable::Id& update_id = SyncableIdFromProto(update.id_string());
// If the update is a delete, we don't really need to worry at this stage.
if (deleted)
@@ -624,7 +626,7 @@ VerifyResult VerifyUpdateConsistency(
}
}
- if (!deleted && (target->Get(ID) == update.id()) &&
+ if (!deleted && (target->Get(ID) == update_id) &&
(target->Get(SERVER_IS_DEL) ||
(!target->Get(IS_UNSYNCED) && target->Get(IS_DEL) &&
target->Get(BASE_VERSION) > 0))) {
@@ -647,7 +649,7 @@ VerifyResult VerifyUpdateConsistency(
<< SyncerProtoUtil::SyncEntityDebugString(update);
return VERIFY_FAIL;
}
- if (target->Get(ID) == update.id()) {
+ if (target->Get(ID) == update_id) {
if (target->Get(SERVER_VERSION) > update.version()) {
LOG(WARNING) << "We've already seen a more recent version.";
LOG(WARNING) << " Entry: " << *target;
@@ -663,7 +665,7 @@ VerifyResult VerifyUpdateConsistency(
// Assumes we have an existing entry; verify an update that seems to be
// expressing an 'undelete'
VerifyResult VerifyUndelete(syncable::WriteTransaction* trans,
- const SyncEntity& update,
+ const sync_pb::SyncEntity& update,
syncable::MutableEntry* target) {
// TODO(nick): We hit this path for items deleted items that the server
// tells us to re-create; only deleted items with positive base versions
diff --git a/sync/engine/syncer_util.h b/sync/engine/syncer_util.h
index ddd21a7..ad70f40 100644
--- a/sync/engine/syncer_util.h
+++ b/sync/engine/syncer_util.h
@@ -18,10 +18,12 @@
#include "sync/syncable/metahandle_set.h"
#include "sync/syncable/syncable_id.h"
-namespace syncer {
+namespace sync_pb {
+class SyncEntity;
+}
+namespace syncer {
class Cryptographer;
-class SyncEntity;
// If the server sent down a client-tagged entry, or an entry whose
// commit response was lost, it is necessary to update a local entry
@@ -34,7 +36,7 @@ class SyncEntity;
// ID. This function does not alter the database.
syncable::Id FindLocalIdToUpdate(
syncable::BaseTransaction* trans,
- const SyncEntity& server_entry);
+ const sync_pb::SyncEntity& server_entry);
UpdateAttemptResponse AttemptToUpdateEntry(
syncable::WriteTransaction* const trans,
@@ -45,7 +47,7 @@ UpdateAttemptResponse AttemptToUpdateEntry(
// Pass in name to avoid redundant UTF8 conversion.
void UpdateServerFieldsFromUpdate(
syncable::MutableEntry* local_entry,
- const SyncEntity& server_entry,
+ const sync_pb::SyncEntity& server_entry,
const std::string& name);
// Creates a new Entry iff no Entry exists with the given id.
@@ -63,14 +65,14 @@ void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans,
VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry);
-VerifyResult VerifyNewEntry(const SyncEntity& update,
+VerifyResult VerifyNewEntry(const sync_pb::SyncEntity& update,
syncable::Entry* target,
const bool deleted);
// Assumes we have an existing entry; check here for updates that break
// consistency rules.
VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans,
- const SyncEntity& update,
+ const sync_pb::SyncEntity& update,
syncable::MutableEntry* target,
const bool deleted,
const bool is_directory,
@@ -79,7 +81,7 @@ VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans,
// Assumes we have an existing entry; verify an update that seems to be
// expressing an 'undelete'
VerifyResult VerifyUndelete(syncable::WriteTransaction* trans,
- const SyncEntity& update,
+ const sync_pb::SyncEntity& update,
syncable::MutableEntry* target);
// Append |item|, followed by a chain of its predecessors selected by
diff --git a/sync/engine/syncproto.h b/sync/engine/syncproto.h
deleted file mode 100644
index 282255c..0000000
--- a/sync/engine/syncproto.h
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-// Wrappers to help us work with ids and protobuffers.
-
-#ifndef SYNC_ENGINE_SYNCPROTO_H_
-#define SYNC_ENGINE_SYNCPROTO_H_
-
-#include "sync/internal_api/public/base/model_type.h"
-#include "sync/protocol/sync.pb.h"
-#include "sync/syncable/syncable_id.h"
-
-namespace syncer {
-
-template<class Base>
-class IdWrapper : public Base {
- public:
- IdWrapper() {}
- explicit IdWrapper(const Base& other) : Base(other) {
- }
- syncable::Id id() const {
- return syncable::Id::CreateFromServerId(Base::id_string());
- }
- void set_id(const syncable::Id& id) {
- Base::set_id_string(id.GetServerId());
- }
-};
-
-// These wrapper classes contain no data, so their super classes can be cast to
-// them directly.
-class SyncEntity : public IdWrapper<sync_pb::SyncEntity> {
- public:
- SyncEntity() {}
- explicit SyncEntity(const sync_pb::SyncEntity& other)
- : IdWrapper<sync_pb::SyncEntity>(other) {
- }
-
- void set_parent_id(const syncable::Id& id) {
- set_parent_id_string(id.GetServerId());
- }
- syncable::Id parent_id() const {
- return syncable::Id::CreateFromServerId(parent_id_string());
- }
- void set_old_parent_id(const syncable::Id& id) {
- IdWrapper<sync_pb::SyncEntity>::set_old_parent_id(
- id.GetServerId());
- }
- syncable::Id old_parent_id() const {
- return syncable::Id::CreateFromServerId(
- sync_pb::SyncEntity::old_parent_id());
- }
- // Binary predicate helper to determine whether an Entity represents a folder
- // or non-folder object. Use this instead of checking these properties
- // directly, because the addition of bookmarks to the protobuf schema
- // makes the check slightly more tricky.
- bool IsFolder() const {
- return ((has_folder() && folder()) ||
- (has_bookmarkdata() && bookmarkdata().bookmark_folder()));
- }
-
- syncer::ModelType GetModelType() const {
- return syncer::GetModelType(*this);
- }
-};
-
-class CommitResponse_EntryResponse
- : public IdWrapper<sync_pb::CommitResponse_EntryResponse> {
-};
-
-class ClientToServerMessage : public sync_pb::ClientToServerMessage {
- public:
- ClientToServerMessage() {
- set_protocol_version(protocol_version());
- }
-};
-
-typedef sync_pb::CommitMessage CommitMessage;
-typedef sync_pb::ClientToServerResponse ClientToServerResponse;
-typedef sync_pb::CommitResponse CommitResponse;
-typedef sync_pb::GetUpdatesResponse GetUpdatesResponse;
-typedef sync_pb::GetUpdatesMessage GetUpdatesMessage;
-
-} // namespace syncer
-
-#endif // SYNC_ENGINE_SYNCPROTO_H_
diff --git a/sync/engine/syncproto_unittest.cc b/sync/engine/syncproto_unittest.cc
deleted file mode 100644
index 1ceaab3..0000000
--- a/sync/engine/syncproto_unittest.cc
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "sync/engine/syncproto.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace syncer {
-
-class SyncProtoTest : public testing::Test {
-};
-
-TEST_F(SyncProtoTest, ProtocolVersionPresent) {
- ClientToServerMessage csm;
- EXPECT_TRUE(csm.has_protocol_version());
-}
-
-} // namespace syncer
diff --git a/sync/engine/verify_updates_command.cc b/sync/engine/verify_updates_command.cc
index 0446924..e105ec8 100644
--- a/sync/engine/verify_updates_command.cc
+++ b/sync/engine/verify_updates_command.cc
@@ -11,11 +11,12 @@
#include "sync/engine/syncer_proto_util.h"
#include "sync/engine/syncer_types.h"
#include "sync/engine/syncer_util.h"
-#include "sync/engine/syncproto.h"
#include "sync/internal_api/public/engine/model_safe_worker.h"
#include "sync/protocol/bookmark_specifics.pb.h"
+#include "sync/protocol/sync.pb.h"
#include "sync/syncable/entry.h"
#include "sync/syncable/mutable_entry.h"
+#include "sync/syncable/syncable_proto_util.h"
#include "sync/syncable/write_transaction.h"
namespace syncer {
@@ -49,9 +50,10 @@ namespace {
//
// For more information, see FindLocalIdToUpdate().
bool UpdateContainsNewVersion(syncable::BaseTransaction *trans,
- const SyncEntity &update) {
+ const sync_pb::SyncEntity &update) {
int64 existing_version = -1; // The server always sends positive versions.
- syncable::Entry existing_entry(trans, GET_BY_ID, update.id());
+ syncable::Entry existing_entry(trans, GET_BY_ID,
+ SyncableIdFromProto(update.id_string()));
if (existing_entry.good())
existing_version = existing_entry.Get(syncable::BASE_VERSION);
@@ -62,7 +64,7 @@ bool UpdateContainsNewVersion(syncable::BaseTransaction *trans,
// will have refused to unify the update.
// We should not attempt to apply it at all since it violates consistency
// rules.
-VerifyResult VerifyTagConsistency(const SyncEntity& entry,
+VerifyResult VerifyTagConsistency(const sync_pb::SyncEntity& entry,
const syncable::MutableEntry& same_id) {
if (entry.has_client_defined_unique_tag() &&
entry.client_defined_unique_tag() !=
@@ -80,7 +82,7 @@ std::set<ModelSafeGroup> VerifyUpdatesCommand::GetGroupsToChange(
const sessions::SyncSession& session) const {
std::set<ModelSafeGroup> groups_with_updates;
- const GetUpdatesResponse& updates =
+ const sync_pb::GetUpdatesResponse& updates =
session.status_controller().updates_response().get_updates();
for (int i = 0; i < updates.entries().size(); i++) {
groups_with_updates.insert(
@@ -97,7 +99,8 @@ SyncerError VerifyUpdatesCommand::ModelChangingExecuteImpl(
syncable::Directory* dir = session->context()->directory();
WriteTransaction trans(FROM_HERE, SYNCER, dir);
sessions::StatusController* status = session->mutable_status_controller();
- const GetUpdatesResponse& updates = status->updates_response().get_updates();
+ const sync_pb::GetUpdatesResponse& updates =
+ status->updates_response().get_updates();
int update_count = updates.entries().size();
ModelTypeSet requested_types = syncer::GetRoutingInfoTypes(
@@ -105,9 +108,8 @@ SyncerError VerifyUpdatesCommand::ModelChangingExecuteImpl(
DVLOG(1) << update_count << " entries to verify";
for (int i = 0; i < update_count; i++) {
- const SyncEntity& update =
- *reinterpret_cast<const SyncEntity *>(&(updates.entries(i)));
- ModelSafeGroup g = GetGroupForModelType(update.GetModelType(),
+ const sync_pb::SyncEntity& update = updates.entries(i);
+ ModelSafeGroup g = GetGroupForModelType(GetModelType(update),
session->routing_info());
if (g != status->group_restriction())
continue;
@@ -127,15 +129,15 @@ SyncerError VerifyUpdatesCommand::ModelChangingExecuteImpl(
}
VerifyUpdatesCommand::VerifyUpdateResult VerifyUpdatesCommand::VerifyUpdate(
- syncable::WriteTransaction* trans, const SyncEntity& entry,
+ syncable::WriteTransaction* trans, const sync_pb::SyncEntity& entry,
const ModelTypeSet& requested_types,
const ModelSafeRoutingInfo& routes) {
- syncable::Id id = entry.id();
+ syncable::Id id = SyncableIdFromProto(entry.id_string());
VerifyUpdateResult result = {VERIFY_FAIL, GROUP_PASSIVE};
const bool deleted = entry.has_deleted() && entry.deleted();
- const bool is_directory = entry.IsFolder();
- const syncer::ModelType model_type = entry.GetModelType();
+ const bool is_directory = IsFolder(entry);
+ const syncer::ModelType model_type = GetModelType(entry);
if (!id.ServerKnows()) {
LOG(ERROR) << "Illegal negative id in received updates";
@@ -152,7 +154,7 @@ VerifyUpdatesCommand::VerifyUpdateResult VerifyUpdatesCommand::VerifyUpdate(
syncable::MutableEntry same_id(trans, GET_BY_ID, id);
result.value = VerifyNewEntry(entry, &same_id, deleted);
- syncer::ModelType placement_type = !deleted ? entry.GetModelType()
+ syncer::ModelType placement_type = !deleted ? GetModelType(entry)
: same_id.good() ? same_id.GetModelType() : syncer::UNSPECIFIED;
result.placement = GetGroupForModelType(placement_type, routes);
diff --git a/sync/engine/verify_updates_command.h b/sync/engine/verify_updates_command.h
index 4fe74a5..2e7adf8d 100644
--- a/sync/engine/verify_updates_command.h
+++ b/sync/engine/verify_updates_command.h
@@ -9,7 +9,6 @@
#include "base/compiler_specific.h"
#include "sync/engine/model_changing_syncer_command.h"
#include "sync/engine/syncer_types.h"
-#include "sync/engine/syncproto.h"
#include "sync/internal_api/public/engine/model_safe_worker.h"
namespace syncer {
@@ -38,7 +37,7 @@ class VerifyUpdatesCommand : public ModelChangingSyncerCommand {
ModelSafeGroup placement;
};
VerifyUpdateResult VerifyUpdate(syncable::WriteTransaction* trans,
- const SyncEntity& entry,
+ const sync_pb::SyncEntity& entry,
const syncer::ModelTypeSet& requested_types,
const ModelSafeRoutingInfo& routes);
DISALLOW_COPY_AND_ASSIGN(VerifyUpdatesCommand);
diff --git a/sync/engine/verify_updates_command_unittest.cc b/sync/engine/verify_updates_command_unittest.cc
index 8bf9ead..3375af8 100644
--- a/sync/engine/verify_updates_command_unittest.cc
+++ b/sync/engine/verify_updates_command_unittest.cc
@@ -52,7 +52,7 @@ class VerifyUpdatesCommandTest : public SyncerCommandTest {
entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
}
- void AddUpdate(GetUpdatesResponse* updates,
+ void AddUpdate(sync_pb::GetUpdatesResponse* updates,
const std::string& id, const std::string& parent,
const syncer::ModelType& type) {
sync_pb::SyncEntity* e = updates->add_entries();
@@ -77,7 +77,8 @@ TEST_F(VerifyUpdatesCommandTest, AllVerified) {
ExpectNoGroupsToChange(command_);
- GetUpdatesResponse* updates = session()->mutable_status_controller()->
+ sync_pb::GetUpdatesResponse* updates =
+ session()->mutable_status_controller()->
mutable_updates_response()->mutable_get_updates();
AddUpdate(updates, "b1", root, syncer::BOOKMARKS);
AddUpdate(updates, "b2", root, syncer::BOOKMARKS);
diff --git a/sync/sessions/session_state.h b/sync/sessions/session_state.h
index a9468b5..290ecee 100644
--- a/sync/sessions/session_state.h
+++ b/sync/sessions/session_state.h
@@ -16,7 +16,7 @@
#include <vector>
#include "sync/engine/syncer_types.h"
-#include "sync/engine/syncproto.h"
+#include "sync/protocol/sync.pb.h"
#include "sync/syncable/syncable_id.h"
namespace syncer {
diff --git a/sync/sessions/status_controller.cc b/sync/sessions/status_controller.cc
index 64fbb856..92bef9f 100644
--- a/sync/sessions/status_controller.cc
+++ b/sync/sessions/status_controller.cc
@@ -161,7 +161,8 @@ void StatusController::reset_conflicts_resolved() {
// Returns the number of updates received from the sync server.
int64 StatusController::CountUpdates() const {
- const ClientToServerResponse& updates = model_neutral_.updates_response;
+ const sync_pb::ClientToServerResponse& updates =
+ model_neutral_.updates_response;
if (updates.has_get_updates()) {
return updates.get_updates().entries().size();
} else {
diff --git a/sync/sessions/status_controller.h b/sync/sessions/status_controller.h
index 9d4fbb4..9ffc93f 100644
--- a/sync/sessions/status_controller.h
+++ b/sync/sessions/status_controller.h
@@ -73,10 +73,10 @@ class StatusController {
void set_updates_request_types(syncer::ModelTypeSet value) {
model_neutral_.updates_request_types = value;
}
- const ClientToServerResponse& updates_response() const {
+ const sync_pb::ClientToServerResponse& updates_response() const {
return model_neutral_.updates_response;
}
- ClientToServerResponse* mutable_updates_response() {
+ sync_pb::ClientToServerResponse* mutable_updates_response() {
return &model_neutral_.updates_response;
}
diff --git a/sync/sessions/status_controller_unittest.cc b/sync/sessions/status_controller_unittest.cc
index 055ba6d..ee1a737 100644
--- a/sync/sessions/status_controller_unittest.cc
+++ b/sync/sessions/status_controller_unittest.cc
@@ -82,7 +82,7 @@ TEST_F(StatusControllerTest, HasConflictingUpdates_NonBlockingUpdates) {
TEST_F(StatusControllerTest, CountUpdates) {
StatusController status(routes_);
EXPECT_EQ(0, status.CountUpdates());
- ClientToServerResponse* response(status.mutable_updates_response());
+ sync_pb::ClientToServerResponse* response(status.mutable_updates_response());
sync_pb::SyncEntity* entity1 = response->mutable_get_updates()->add_entries();
sync_pb::SyncEntity* entity2 = response->mutable_get_updates()->add_entries();
ASSERT_TRUE(entity1 != NULL && entity2 != NULL);
diff --git a/sync/sync.gyp b/sync/sync.gyp
index acc88e5..b1554f5 100644
--- a/sync/sync.gyp
+++ b/sync/sync.gyp
@@ -106,7 +106,6 @@
'engine/syncer_types.h',
'engine/syncer_util.cc',
'engine/syncer_util.h',
- 'engine/syncproto.h',
'engine/throttled_data_type_tracker.cc',
'engine/throttled_data_type_tracker.h',
'engine/traffic_logger.cc',
@@ -177,6 +176,8 @@
'syncable/syncable_enum_conversions.h',
'syncable/syncable_id.cc',
'syncable/syncable_id.h',
+ 'syncable/syncable_proto_util.cc',
+ 'syncable/syncable_proto_util.h',
'syncable/syncable_util.cc',
'syncable/syncable_util.h',
'syncable/transaction_observer.h',
@@ -539,7 +540,6 @@
'engine/resolve_conflicts_command_unittest.cc',
'engine/syncer_proto_util_unittest.cc',
'engine/syncer_unittest.cc',
- 'engine/syncproto_unittest.cc',
'engine/sync_scheduler_unittest.cc',
'engine/sync_scheduler_whitebox_unittest.cc',
'engine/throttled_data_type_tracker_unittest.cc',
diff --git a/sync/syncable/DEPS b/sync/syncable/DEPS
index ee20e97..37279ad 100644
--- a/sync/syncable/DEPS
+++ b/sync/syncable/DEPS
@@ -7,7 +7,4 @@ include_rules = [
"+sync/protocol",
"+sync/test",
"+sync/util",
-
- # this file is weird.
- "+sync/engine/syncproto.h",
]
diff --git a/sync/syncable/model_type.cc b/sync/syncable/model_type.cc
index 1bf1ded..4c75f91 100644
--- a/sync/syncable/model_type.cc
+++ b/sync/syncable/model_type.cc
@@ -6,7 +6,6 @@
#include "base/string_split.h"
#include "base/values.h"
-#include "sync/engine/syncproto.h"
#include "sync/protocol/app_notification_specifics.pb.h"
#include "sync/protocol/app_setting_specifics.pb.h"
#include "sync/protocol/app_specifics.pb.h"
@@ -22,6 +21,7 @@
#include "sync/protocol/sync.pb.h"
#include "sync/protocol/theme_specifics.pb.h"
#include "sync/protocol/typed_url_specifics.pb.h"
+#include "sync/syncable/syncable_proto_util.h"
namespace syncer {
@@ -145,10 +145,8 @@ int GetSpecificsFieldNumberFromModelType(ModelType model_type) {
}
// Note: keep this consistent with GetModelType in syncable.cc!
-ModelType GetModelType(const sync_pb::SyncEntity& sync_pb_entity) {
- const syncer::SyncEntity& sync_entity =
- static_cast<const syncer::SyncEntity&>(sync_pb_entity);
- DCHECK(!sync_entity.id().IsRoot()); // Root shouldn't ever go over the wire.
+ModelType GetModelType(const sync_pb::SyncEntity& sync_entity) {
+ DCHECK(!IsRoot(sync_entity)); // Root shouldn't ever go over the wire.
if (sync_entity.deleted())
return UNSPECIFIED;
@@ -164,7 +162,7 @@ ModelType GetModelType(const sync_pb::SyncEntity& sync_pb_entity) {
// Loose check for server-created top-level folders that aren't
// bound to a particular model type.
if (!sync_entity.server_defined_unique_tag().empty() &&
- sync_entity.IsFolder()) {
+ IsFolder(sync_entity)) {
return TOP_LEVEL_FOLDER;
}
diff --git a/sync/syncable/syncable_proto_util.cc b/sync/syncable/syncable_proto_util.cc
new file mode 100644
index 0000000..4f35b19
--- /dev/null
+++ b/sync/syncable/syncable_proto_util.cc
@@ -0,0 +1,32 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/syncable/syncable_proto_util.h"
+
+#include "sync/protocol/sync.pb.h"
+
+namespace syncer {
+
+syncable::Id SyncableIdFromProto(const std::string& proto_string) {
+ return syncable::Id::CreateFromServerId(proto_string);
+}
+
+std::string SyncableIdToProto(const syncable::Id& syncable_id) {
+ return syncable_id.GetServerId();
+}
+
+bool IsFolder(const sync_pb::SyncEntity& entity) {
+ // TODO(sync): The checks for has_folder() and has_bookmarkdata() are likely
+ // no longer necessary. We should remove them if we can convince ourselves
+ // that doing so won't break anything.
+ return ((entity.has_folder() && entity.folder()) ||
+ (entity.has_bookmarkdata() &&
+ entity.bookmarkdata().bookmark_folder()));
+}
+
+bool IsRoot(const sync_pb::SyncEntity& entity) {
+ return SyncableIdFromProto(entity.id_string()).IsRoot();
+}
+
+} // namespace syncer
diff --git a/sync/syncable/syncable_proto_util.h b/sync/syncable/syncable_proto_util.h
new file mode 100644
index 0000000..299aca5
--- /dev/null
+++ b/sync/syncable/syncable_proto_util.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYNCABLE_PROTOCOL_PROTO_UTIL_H_
+#define SYNCABLE_PROTOCOL_PROTO_UTIL_H_
+
+#include <string>
+
+#include "sync/syncable/syncable_id.h"
+
+namespace sync_pb {
+class SyncEntity;
+}
+
+namespace syncer {
+
+// Converts from a specially formatted string field to a syncable::Id. Used
+// when interpreting the fields of protocol buffers received from the server.
+syncable::Id SyncableIdFromProto(const std::string& proto_string);
+
+// Converts from a syncable::Id to a formatted std::string. This is useful for
+// populating the fields of a protobuf which will be sent to the server.
+std::string SyncableIdToProto(const syncable::Id& syncable_id);
+
+// Helper function to determine if this SyncEntity's properties indicate that it
+// is a folder.
+bool IsFolder(const sync_pb::SyncEntity& entity);
+
+// Helper function to determine if this SyncEntity's properties indicate that it
+// is the root node.
+bool IsRoot(const sync_pb::SyncEntity& entity);
+
+} // namespace syncer
+
+#endif // SYNCABLE_PROTOCOL_PROTO_UTIL_H_
diff --git a/sync/syncable/syncable_unittest.cc b/sync/syncable/syncable_unittest.cc
index eb08ddb..2518ff5b 100644
--- a/sync/syncable/syncable_unittest.cc
+++ b/sync/syncable/syncable_unittest.cc
@@ -17,7 +17,6 @@
#include "base/test/values_test_util.h"
#include "base/threading/platform_thread.h"
#include "base/values.h"
-#include "sync/engine/syncproto.h"
#include "sync/protocol/bookmark_specifics.pb.h"
#include "sync/syncable/directory_backing_store.h"
#include "sync/syncable/directory_change_delegate.h"
@@ -26,6 +25,7 @@
#include "sync/syncable/mutable_entry.h"
#include "sync/syncable/on_disk_directory_backing_store.h"
#include "sync/syncable/read_transaction.h"
+#include "sync/syncable/syncable_proto_util.h"
#include "sync/syncable/syncable_util.h"
#include "sync/syncable/write_transaction.h"
#include "sync/test/engine/test_id_factory.h"
@@ -1152,19 +1152,19 @@ TEST_F(SyncableDirectoryTest, GetModelType) {
server_item.Put(SERVER_IS_DEL, false);
ASSERT_EQ(datatype, server_item.GetServerModelType());
- syncer::SyncEntity folder_entity;
- folder_entity.set_id(id_factory.NewServerId());
+ sync_pb::SyncEntity folder_entity;
+ folder_entity.set_id_string(SyncableIdToProto(id_factory.NewServerId()));
folder_entity.set_deleted(false);
folder_entity.set_folder(true);
folder_entity.mutable_specifics()->CopyFrom(specifics);
- ASSERT_EQ(datatype, folder_entity.GetModelType());
+ ASSERT_EQ(datatype, GetModelType(folder_entity));
- syncer::SyncEntity item_entity;
- item_entity.set_id(id_factory.NewServerId());
+ sync_pb::SyncEntity item_entity;
+ item_entity.set_id_string(SyncableIdToProto(id_factory.NewServerId()));
item_entity.set_deleted(false);
item_entity.set_folder(false);
item_entity.mutable_specifics()->CopyFrom(specifics);
- ASSERT_EQ(datatype, item_entity.GetModelType());
+ ASSERT_EQ(datatype, GetModelType(item_entity));
}
}
diff --git a/sync/test/engine/mock_connection_manager.cc b/sync/test/engine/mock_connection_manager.cc
index cf5ab20e..58bd0d1 100644
--- a/sync/test/engine/mock_connection_manager.cc
+++ b/sync/test/engine/mock_connection_manager.cc
@@ -19,6 +19,7 @@
using std::map;
using std::string;
+using sync_pb::ClientToServerMessage;
using sync_pb::CommitMessage;
using sync_pb::CommitResponse;
using sync_pb::GetUpdatesMessage;
@@ -81,7 +82,7 @@ bool MockConnectionManager::PostBufferToPath(PostBufferParams* params,
CHECK(post.has_protocol_version());
last_request_.CopyFrom(post);
client_stuck_ = post.sync_problem_detected();
- ClientToServerResponse response;
+ sync_pb::ClientToServerResponse response;
response.Clear();
if (directory_) {