Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Unified Diff: sync/internal_api/public/base/unique_position.cc

Issue 283143002: sync: Improve handling of bad UniquePos (retry) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/internal_api/public/base/unique_position.h ('k') | sync/sync_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/internal_api/public/base/unique_position.cc
diff --git a/sync/internal_api/public/base/unique_position.cc b/sync/internal_api/public/base/unique_position.cc
index 40bab6e175d1de51ede96aa020a4667158140d42..2d41614999c332fc81d371d2a2f6d0d4ae5fa9bf 100644
--- a/sync/internal_api/public/base/unique_position.cc
+++ b/sync/internal_api/public/base/unique_position.cc
@@ -6,6 +6,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/rand_util.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "sync/protocol/unique_position.pb.h"
@@ -21,7 +22,8 @@ bool UniquePosition::IsValidSuffix(const std::string& suffix) {
// The suffix must be exactly the specified length, otherwise unique suffixes
// are not sufficient to guarantee unique positions (because prefix + suffix
// == p + refixsuffix).
- return suffix.length() == kSuffixLength;
+ return suffix.length() == kSuffixLength
+ && suffix[kSuffixLength-1] != 0;
}
// static.
@@ -36,6 +38,13 @@ bool UniquePosition::IsValidBytes(const std::string& bytes) {
}
// static.
+std::string UniquePosition::RandomSuffix() {
+ // Users random data for all but the last byte. The last byte must not be
+ // zero. We arbitrarily set it to 0x7f.
+ return base::RandBytesAsString(kSuffixLength - 1) + "\x7f";
+}
+
+// static.
UniquePosition UniquePosition::CreateInvalid() {
UniquePosition pos;
DCHECK(!pos.IsValid());
« no previous file with comments | « sync/internal_api/public/base/unique_position.h ('k') | sync/sync_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698