diff options
author | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 06:05:27 +0000 |
---|---|---|
committer | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 06:05:27 +0000 |
commit | 5852edc1b6eab234b9e048c41dd0d664ae7fc747 (patch) | |
tree | 9e5d8eb4833b76cdb11e66fc3607689e0f5e0122 /chrome/browser/sync/syncable/syncable_id.h | |
parent | f6059e37f8b8ac335ce18a189a13e702974a1c7e (diff) | |
download | chromium_src-5852edc1b6eab234b9e048c41dd0d664ae7fc747.zip chromium_src-5852edc1b6eab234b9e048c41dd0d664ae7fc747.tar.gz chromium_src-5852edc1b6eab234b9e048c41dd0d664ae7fc747.tar.bz2 |
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
Diffstat (limited to 'chrome/browser/sync/syncable/syncable_id.h')
-rw-r--r-- | chrome/browser/sync/syncable/syncable_id.h | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/chrome/browser/sync/syncable/syncable_id.h b/chrome/browser/sync/syncable/syncable_id.h new file mode 100644 index 0000000..5f2a28e --- /dev/null +++ b/chrome/browser/sync/syncable/syncable_id.h @@ -0,0 +1,114 @@ +// Copyright (c) 2009 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_SYNCABLE_SYNCABLE_ID_H_ +#define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ + +#include <iosfwd> +#include <limits> +#include <sstream> +#include <string> + +#include "base/hash_tables.h" +#include "chrome/browser/sync/util/fast_dump.h" +#include "chrome/browser/sync/util/sync_types.h" + +extern "C" { +struct sqlite3; +struct sqlite3_stmt; +} + +namespace syncable { +class Id; +} // namespace syncable + +class MockConnectionManager; + +sqlite3_stmt* BindArg(sqlite3_stmt*, const syncable::Id&, int index); +void GetColumn(sqlite3_stmt*, int index, syncable::Id* value); +std::ostream& operator << (std::ostream& out, const syncable::Id& id); +browser_sync::FastDump& operator << + (browser_sync::FastDump& out, const syncable::Id& id); + +namespace syncable { + +// For historical reasons, 3 concepts got everloaded into the Id: +// 1. A unique, opaque identifier for the object. +// 2. Flag specifing whether server know about this object. +// 3. Flag for root. +// +// We originally wrapped an integer for this information, but now we use a +// string. It will have one of three forms: +// 1. c<client only opaque id> for client items that have not been committed. +// 2. r for the root item. +// 3. s<server provided opaque id> for items that the server knows about. +class Id { + friend sqlite3_stmt* ::BindArg(sqlite3_stmt*, const syncable::Id&, int index); + friend void ::GetColumn(sqlite3_stmt*, int index, syncable::Id* value); + friend std::ostream& ::operator << (std::ostream& out, + const syncable::Id& id); + friend browser_sync::FastDump& ::operator << + (browser_sync::FastDump& out, const syncable::Id& id); + friend class MockConnectionManager; + friend class SyncableIdTest; + public: + // This constructor will be handy even when we move away from + // int64s, just for unit tests. + inline Id() : s_("r") { } + inline Id(const Id& that) { + Copy(that); + } + inline Id& operator = (const Id& that) { + Copy(that); + return *this; + } + inline void Copy(const Id& that) { + this->s_ = that.s_; + } + inline bool IsRoot() const { + return "r" == s_; + } + inline bool ServerKnows() const { + return s_[0] == 's' || s_ == "r"; + } + + // TODO(sync): We could use null here, but to ease conversion we use "r". + // fix this, this is madness :) + inline bool IsNull() const { + return IsRoot(); + } + inline void Clear() { + s_ = "r"; + } + std::string AsQueryParam() const; + // Must never allow id == 0 or id < 0 to compile. + inline bool operator == (const Id& that) const { + return s_ == that.s_; + } + inline bool operator != (const Id& that) const { + return s_ != that.s_; + } + inline bool operator < (const Id& that) const { + return s_ < that.s_; + } + inline bool operator > (const Id& that) const { + return s_ > that.s_; + } + + public: + // Three functions used to work with our proto buffers. + std::string GetServerId() const; + static Id CreateFromServerId(const std::string& server_id); + // This should only be used if you get back a reference to a local + // id from the server. Returns a client only opaque id. + static Id CreateFromClientString(const std::string& local_id); + protected: + std::string s_; +}; + +extern const Id kNullId; + +} // namespace syncable + +#endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ |