From 5852edc1b6eab234b9e048c41dd0d664ae7fc747 Mon Sep 17 00:00:00 2001 From: "nick@chromium.org" Date: Thu, 10 Sep 2009 06:05:27 +0000 Subject: Initial commit of sync engine code to browser/sync. The code is not built on any platform yet. That will arrive as a subsequent checkin. This is an implementation of the interface exposed earlier through syncapi.h. It is the client side of a sync protocol that lets users sync their browser data (currently, just bookmarks) with their Google Account. Table of contents: browser/sync/ protocol - The protocol definition, and other definitions necessary to connect to the service. syncable/ - defines a data model for syncable objects, and provides a sqlite-based backing store for this model. engine/ - includes the core sync logic, including commiting changes to the server, downloading changes from the server, resolving conflicts, other parts of the sync algorithm. engine/net - parts of the sync engine focused on the business of talking to the server. Some of this is binds a generic "server connection" interface to a concrete implementation provided by Chromium. notifier - the part of the syncer focused on the business of sending and receiving xmpp notifications. Notifications are used instead of polling to achieve very low latency change propagation. util - not necessarily sync specific utility code. Much of this is scaffolding which should either be replaced by, or merged with, the utility code in base/. BUG=none TEST=this code includes its own suite of unit tests. Review URL: http://codereview.chromium.org/194065 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25850 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/sync/engine/syncer_proto_util.h | 73 ++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 chrome/browser/sync/engine/syncer_proto_util.h (limited to 'chrome/browser/sync/engine/syncer_proto_util.h') diff --git a/chrome/browser/sync/engine/syncer_proto_util.h b/chrome/browser/sync/engine/syncer_proto_util.h new file mode 100644 index 0000000..ecee903 --- /dev/null +++ b/chrome/browser/sync/engine/syncer_proto_util.h @@ -0,0 +1,73 @@ +// Copyright (c) 2006-2008 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 CHROME_BROWSER_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_ +#define CHROME_BROWSER_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_ + +#include + +#include "chrome/browser/sync/engine/syncer_session.h" +#include "chrome/browser/sync/util/sync_types.h" +#include "chrome/browser/sync/syncable/blob.h" + +namespace syncable { +class Entry; +class ScopedDirLookup; +class SyncName; +} // namespace syncable + +namespace sync_pb { +class ClientToServerResponse; +} // namespace sync_pb + +namespace browser_sync { + +class ClientToServerMessage; +class SyncerSession; +class SyncEntity; +class CommitResponse_EntryResponse; + +class SyncerProtoUtil { + public: + // Posts the given message and fills the buffer with the returned value. + // Returns true on success. Also handles store birthday verification: + // session->status()->syncer_stuck_ is set true if the birthday is + // incorrect. A false value will always be returned if birthday is bad. + static bool PostClientToServerMessage(ClientToServerMessage* msg, + sync_pb::ClientToServerResponse* response, SyncerSession *session); + + // Compares a syncable Entry to SyncEntity, returns true iff + // the data is identical. + // + // TODO(sync): The places where this function is used are arguable big + // causes of the fragility, because there's a tendency to freak out + // the moment the 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); + + // Utility methods for converting between syncable::Blobs and protobuf + // byte fields. + static void CopyProtoBytesIntoBlob(const std::string& proto_bytes, + syncable::Blob* blob); + static bool ProtoBytesEqualsBlob(const std::string& proto_bytes, + const syncable::Blob& blob); + static void CopyBlobIntoProtoBytes(const syncable::Blob& blob, + std::string* proto_bytes); + + // Extract the name fields from a sync entity. + static syncable::SyncName NameFromSyncEntity( + const SyncEntity& entry); + + // Extract the name fields from a commit entry response. + static syncable::SyncName NameFromCommitEntryResponse( + const CommitResponse_EntryResponse& entry); + + private: + SyncerProtoUtil() {} + DISALLOW_COPY_AND_ASSIGN(SyncerProtoUtil); +}; +} // namespace browser_sync + +#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_ -- cgit v1.1