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/util/path_helpers.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/util/path_helpers.h')
-rw-r--r-- | chrome/browser/sync/util/path_helpers.h | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/chrome/browser/sync/util/path_helpers.h b/chrome/browser/sync/util/path_helpers.h new file mode 100644 index 0000000..d8b4663 --- /dev/null +++ b/chrome/browser/sync/util/path_helpers.h @@ -0,0 +1,105 @@ +// 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_UTIL_PATH_HELPERS_H_ +#define CHROME_BROWSER_SYNC_UTIL_PATH_HELPERS_H_ + +#include <algorithm> +#include <iterator> +#include <string> + +#include "chrome/browser/sync/util/compat-file.h" +#include "chrome/browser/sync/util/sync_types.h" + +template <typename StringType> +class PathSegmentIterator : public std::iterator<std::forward_iterator_tag, + StringType> { + public: + explicit PathSegmentIterator(const StringType& path) : + path_(path), segment_begin_(0), segment_end_(0) { + ++(*this); + } + + PathSegmentIterator() : segment_begin_(0), segment_end_(0) { } + + // Default copy constructors, constructors, etc. will all do the right thing. + PathSegmentIterator& operator ++() { + segment_begin_ = + std::min(path_.size(), + path_.find_first_not_of(kPathSeparator, segment_end_)); + segment_end_ = + std::min(path_.size(), + path_.find_first_of(kPathSeparator, segment_begin_)); + value_.assign(path_, segment_begin_, segment_end_ - segment_begin_); + return *this; + } + + PathSegmentIterator operator ++(int) { + PathSegmentIterator i(*this); + return ++i; + } + + const StringType& operator * () const { + return value_; + } + const StringType* operator -> () const { + return &value_; + } + + // If the current value and remaining path are equal, then we + // call the iterators equal. + bool operator == (const PathSegmentIterator& i) const { + return 0 == path_.compare(segment_begin_, + path_.size() - segment_begin_, + i.path_, i.segment_begin_, i.path_.size() - i.segment_begin_); + } + + bool operator != (const PathSegmentIterator& i) const { + return !(*this == i); + } + + protected: + StringType path_; + typename StringType::size_type segment_begin_; + typename StringType::size_type segment_end_; + StringType value_; +}; + +// NOTE: The functions (Strip)LastPathSegment always return values without a +// trailing slash. +PathString LastPathSegment(const PathString& path); +std::string LastPathSegment(const std::string& path); +PathString AppendSlash(const PathString& path); +PathString GetFullPath(const PathString& path); +PathString LowercasePath(const PathString& path); +PathString ExpandTilde(const PathString& path); + +inline bool HasSuffixPathString(const PathString& str, + const PathString& suffix) { + return str.find(suffix, str.size() - suffix.size()) != PathString::npos; +} + +inline PathString StripSuffixPathString(const PathString& str, + const PathString& suffix) { + PathString ret(str); + if (HasSuffixPathString(str, suffix)) { + ret.resize(str.size() - suffix.size()); + } + return ret; +} + +// Returns a string with length or fewer elements, careful to +// not truncate a string mid-surrogate pair. +PathString TruncatePathString(const PathString& original, int length); + +// Makes a path component legal for your OS, but doesn't handle collisions +// with other files in the same directory. it can do this by removing +// illegal characters and adding ~1 before the first '.' in the filename. +// returns PSTR("") if the name is fine as-is +// on mac/linux we let names stay unicode normalization form C in the system +// and convert to another normal form in fuse handlers. but, if a '/' is in +// a filename, we handle it here. +PathString MakePathComponentOSLegal(const PathString& component); + +#endif // CHROME_BROWSER_SYNC_UTIL_PATH_HELPERS_H_ |