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

Side by Side Diff: sync/engine/build_commit_command.cc

Issue 10989063: Changed DB to store node positions as Ordinals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Ordinal default ctor now creates invalid Ordinals Created 8 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "sync/engine/build_commit_command.h" 5 #include "sync/engine/build_commit_command.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "sync/engine/syncer_proto_util.h" 13 #include "sync/engine/syncer_proto_util.h"
14 #include "sync/protocol/bookmark_specifics.pb.h" 14 #include "sync/protocol/bookmark_specifics.pb.h"
15 #include "sync/protocol/sync.pb.h" 15 #include "sync/protocol/sync.pb.h"
16 #include "sync/sessions/ordered_commit_set.h" 16 #include "sync/sessions/ordered_commit_set.h"
17 #include "sync/sessions/sync_session.h" 17 #include "sync/sessions/sync_session.h"
18 #include "sync/syncable/directory.h" 18 #include "sync/syncable/directory.h"
19 #include "sync/syncable/mutable_entry.h" 19 #include "sync/syncable/mutable_entry.h"
20 #include "sync/syncable/syncable_changes_version.h" 20 #include "sync/syncable/syncable_changes_version.h"
21 #include "sync/syncable/syncable_proto_util.h" 21 #include "sync/syncable/syncable_proto_util.h"
22 #include "sync/syncable/write_transaction.h" 22 #include "sync/syncable/write_transaction.h"
23 #include "sync/util/time.h" 23 #include "sync/util/time.h"
24 24
25 //TODO(vishwath): Remove this include after node positions have
akalin 2012/10/05 22:40:27 space after //
vishwath 2012/10/08 20:17:49 Done.
26 // shifted to completely using Ordinals.
27 // See http://crbug.com/145412 .
28 #include "sync/internal_api/public/base/node_ordinal.h"
29
25 using std::set; 30 using std::set;
26 using std::string; 31 using std::string;
27 using std::vector; 32 using std::vector;
28 33
29 namespace syncer { 34 namespace syncer {
30 35
31 using sessions::SyncSession; 36 using sessions::SyncSession;
32 using syncable::Entry; 37 using syncable::Entry;
33 using syncable::IS_DEL; 38 using syncable::IS_DEL;
34 using syncable::SERVER_POSITION_IN_PARENT; 39 using syncable::SERVER_ORDINAL_IN_PARENT;
35 using syncable::IS_UNAPPLIED_UPDATE; 40 using syncable::IS_UNAPPLIED_UPDATE;
36 using syncable::IS_UNSYNCED; 41 using syncable::IS_UNSYNCED;
37 using syncable::Id; 42 using syncable::Id;
38 using syncable::MutableEntry; 43 using syncable::MutableEntry;
39 using syncable::SPECIFICS; 44 using syncable::SPECIFICS;
40 45
41 // static 46 // static
42 int64 BuildCommitCommand::GetFirstPosition() { 47 int64 BuildCommitCommand::GetFirstPosition() {
43 return std::numeric_limits<int64>::min(); 48 return std::numeric_limits<int64>::min();
44 } 49 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 229 }
225 230
226 int64 BuildCommitCommand::FindAnchorPosition(syncable::IdField direction, 231 int64 BuildCommitCommand::FindAnchorPosition(syncable::IdField direction,
227 const syncable::Entry& entry) { 232 const syncable::Entry& entry) {
228 Id next_id = entry.Get(direction); 233 Id next_id = entry.Get(direction);
229 while (!next_id.IsRoot()) { 234 while (!next_id.IsRoot()) {
230 Entry next_entry(entry.trans(), 235 Entry next_entry(entry.trans(),
231 syncable::GET_BY_ID, 236 syncable::GET_BY_ID,
232 next_id); 237 next_id);
233 if (!next_entry.Get(IS_UNSYNCED) && !next_entry.Get(IS_UNAPPLIED_UPDATE)) { 238 if (!next_entry.Get(IS_UNSYNCED) && !next_entry.Get(IS_UNAPPLIED_UPDATE)) {
234 return next_entry.Get(SERVER_POSITION_IN_PARENT); 239 return NodeOrdinalToInt64(next_entry.Get(SERVER_ORDINAL_IN_PARENT));
235 } 240 }
236 next_id = next_entry.Get(direction); 241 next_id = next_entry.Get(direction);
237 } 242 }
238 return 243 return
239 direction == syncable::PREV_ID ? 244 direction == syncable::PREV_ID ?
240 GetFirstPosition() : GetLastPosition(); 245 GetFirstPosition() : GetLastPosition();
241 } 246 }
242 247
243 int64 BuildCommitCommand::InterpolatePosition(const int64 lo, 248 int64 BuildCommitCommand::InterpolatePosition(const int64 lo,
244 const int64 hi) { 249 const int64 hi) {
(...skipping 10 matching lines...) Expand all
255 if (delta <= static_cast<uint64>(GetGap()*2)) 260 if (delta <= static_cast<uint64>(GetGap()*2))
256 return lo + (static_cast<int64>(delta) + 7) / 8; // Interpolate. 261 return lo + (static_cast<int64>(delta) + 7) / 8; // Interpolate.
257 else if (lo == GetFirstPosition()) 262 else if (lo == GetFirstPosition())
258 return hi - GetGap(); // Extend range just before successor. 263 return hi - GetGap(); // Extend range just before successor.
259 else 264 else
260 return lo + GetGap(); // Use or extend range just after predecessor. 265 return lo + GetGap(); // Use or extend range just after predecessor.
261 } 266 }
262 267
263 268
264 } // namespace syncer 269 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | sync/engine/process_commit_response_command.cc » ('j') | sync/engine/process_commit_response_command.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698