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()); |