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

Side by Side Diff: sync/syncable/syncable_id.h

Issue 805633004: Enable Null Syncable ID which is different than Root ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed some dependencies on SERVER_PARENT_ID Created 6 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SYNC_SYNCABLE_SYNCABLE_ID_H_ 5 #ifndef SYNC_SYNCABLE_SYNCABLE_ID_H_
6 #define SYNC_SYNCABLE_SYNCABLE_ID_H_ 6 #define SYNC_SYNCABLE_SYNCABLE_ID_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <limits> 9 #include <limits>
10 #include <sstream> 10 #include <sstream>
(...skipping 25 matching lines...) Expand all
36 // 2. Flag specifing whether server know about this object. 36 // 2. Flag specifing whether server know about this object.
37 // 3. Flag for root. 37 // 3. Flag for root.
38 // 38 //
39 // We originally wrapped an integer for this information, but now we use a 39 // We originally wrapped an integer for this information, but now we use a
40 // string. It will have one of three forms: 40 // string. It will have one of three forms:
41 // 1. c<client only opaque id> for client items that have not been committed. 41 // 1. c<client only opaque id> for client items that have not been committed.
42 // 2. r for the root item. 42 // 2. r for the root item.
43 // 3. s<server provided opaque id> for items that the server knows about. 43 // 3. s<server provided opaque id> for items that the server knows about.
44 class SYNC_EXPORT Id { 44 class SYNC_EXPORT Id {
45 public: 45 public:
46 // This constructor will be handy even when we move away from int64s, just 46 inline Id() : s_("") {}
pavely 2014/12/22 21:38:09 Did you write s_("") to make it more explicit and
stanisc 2014/12/22 21:56:01 You are right. s_ would auto-initialize to an empt
stanisc 2014/12/22 22:44:20 Done.
47 // for unit tests.
48 inline Id() : s_("r") { }
49 inline Id(const Id& that) { 47 inline Id(const Id& that) {
50 Copy(that); 48 Copy(that);
51 } 49 }
52 inline Id& operator = (const Id& that) { 50 inline Id& operator = (const Id& that) {
53 Copy(that); 51 Copy(that);
54 return *this; 52 return *this;
55 } 53 }
56 inline void Copy(const Id& that) { 54 inline void Copy(const Id& that) {
57 this->s_ = that.s_; 55 this->s_ = that.s_;
58 } 56 }
59 inline bool IsRoot() const { 57 inline bool IsRoot() const {
60 return "r" == s_; 58 return "r" == s_;
61 } 59 }
62 inline bool ServerKnows() const { 60 inline bool ServerKnows() const {
63 return s_[0] == 's' || s_ == "r"; 61 return s_[0] == 's' || s_ == "r";
64 } 62 }
65 63
66 // TODO(sync): We could use null here, but to ease conversion we use "r". 64 inline bool IsNull() const { return s_.size() == 0; }
pavely 2014/12/22 21:38:09 nit: replace "s_.size() == 0" with "s_.empty()" O
stanisc 2014/12/22 22:44:20 Done.
67 // fix this, this is madness :) 65 inline void Clear() { s_ = ""; }
68 inline bool IsNull() const {
69 return IsRoot();
70 }
71 inline void Clear() {
72 s_ = "r";
73 }
74 inline int compare(const Id& that) const { 66 inline int compare(const Id& that) const {
75 return s_.compare(that.s_); 67 return s_.compare(that.s_);
76 } 68 }
77 inline bool operator == (const Id& that) const { 69 inline bool operator == (const Id& that) const {
78 return s_ == that.s_; 70 return s_ == that.s_;
79 } 71 }
80 inline bool operator != (const Id& that) const { 72 inline bool operator != (const Id& that) const {
81 return s_ != that.s_; 73 return s_ != that.s_;
82 } 74 }
83 inline bool operator < (const Id& that) const { 75 inline bool operator < (const Id& that) const {
(...skipping 21 matching lines...) Expand all
105 static Id CreateFromServerId(const std::string& server_id); 97 static Id CreateFromServerId(const std::string& server_id);
106 // This should only be used if you get back a reference to a local 98 // This should only be used if you get back a reference to a local
107 // id from the server. Returns a client only opaque id. 99 // id from the server. Returns a client only opaque id.
108 static Id CreateFromClientString(const std::string& local_id); 100 static Id CreateFromClientString(const std::string& local_id);
109 101
110 // This method returns an ID that will compare less than any valid ID. 102 // This method returns an ID that will compare less than any valid ID.
111 // The returned ID is not a valid ID itself. This is useful for 103 // The returned ID is not a valid ID itself. This is useful for
112 // computing lower bounds on std::sets that are ordered by operator<. 104 // computing lower bounds on std::sets that are ordered by operator<.
113 static Id GetLeastIdForLexicographicComparison(); 105 static Id GetLeastIdForLexicographicComparison();
114 106
107 // Gets root ID.
108 static Id GetRoot();
109
115 private: 110 private:
116 friend scoped_ptr<EntryKernel> UnpackEntry(sql::Statement* statement); 111 friend scoped_ptr<EntryKernel> UnpackEntry(sql::Statement* statement);
117 friend void BindFields(const EntryKernel& entry, 112 friend void BindFields(const EntryKernel& entry,
118 sql::Statement* statement); 113 sql::Statement* statement);
119 SYNC_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& out, 114 SYNC_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& out,
120 const Id& id); 115 const Id& id);
121 friend class MockConnectionManager; 116 friend class MockConnectionManager;
122 friend class SyncableIdTest; 117 friend class SyncableIdTest;
123 118
124 std::string s_; 119 std::string s_;
125 }; 120 };
126 121
127 SYNC_EXPORT_PRIVATE Id GetNullId();
128
129 } // namespace syncable 122 } // namespace syncable
130 } // namespace syncer 123 } // namespace syncer
131 124
132 #endif // SYNC_SYNCABLE_SYNCABLE_ID_H_ 125 #endif // SYNC_SYNCABLE_SYNCABLE_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698