Update V8 to version 4.5.92.
[chromium-blink-merge.git] / sync / internal_api / change_reorder_buffer.h
blobc1c577d43a751795b9cf8cd4b4ba5ac79e3ac400
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
3 // found in the LICENSE file.
4 //
5 // Defines ChangeReorderBuffer, which can be used to sort a list of item
6 // actions to achieve the ordering constraint required by the SyncObserver
7 // interface of the SyncAPI.
9 #ifndef SYNC_INTERNAL_API_CHANGE_REORDER_BUFFER_H_
10 #define SYNC_INTERNAL_API_CHANGE_REORDER_BUFFER_H_
12 #include <map>
13 #include <vector>
15 #include "base/compiler_specific.h"
16 #include "base/memory/linked_ptr.h"
17 #include "sync/internal_api/public/change_record.h"
18 #include "sync/protocol/sync.pb.h"
20 namespace syncer {
22 class BaseTransaction;
24 // ChangeReorderBuffer is a utility type which accepts an unordered set
25 // of changes (via its Push methods), and yields an ImmutableChangeRecordList
26 // (via the GetAllChangesInTreeOrder method) that are in the order that
27 // the SyncObserver expects them to be. A buffer is initially empty.
29 // The ordering produced by ChangeReorderBuffer is as follows:
30 // (a) All Deleted items appear first.
31 // (b) For Updated and/or Added items, parents appear before their children.
33 // The sibling order is not necessarily preserved.
34 class ChangeReorderBuffer {
35 public:
36 ChangeReorderBuffer();
37 ~ChangeReorderBuffer();
39 // Insert an item, identified by the metahandle |id|, into the reorder buffer.
40 // This item will appear in the output list as an ACTION_ADD ChangeRecord.
41 void PushAddedItem(int64 id);
43 // Insert an item, identified by the metahandle |id|, into the reorder buffer.
44 // This item will appear in the output list as an ACTION_DELETE ChangeRecord.
45 void PushDeletedItem(int64 id);
47 // Insert an item, identified by the metahandle |id|, into the reorder buffer.
48 // This item will appear in the output list as an ACTION_UPDATE ChangeRecord.
49 void PushUpdatedItem(int64 id);
51 void SetExtraDataForId(int64 id, ExtraPasswordChangeRecordData* extra);
53 void SetSpecificsForId(int64 id, const sync_pb::EntitySpecifics& specifics);
55 // Reset the buffer, forgetting any pushed items, so that it can be used again
56 // to reorder a new set of changes.
57 void Clear();
59 bool IsEmpty() const;
61 // Output a reordered list of changes to |changes| using the items
62 // that were pushed into the reorder buffer. |sync_trans| is used to
63 // determine the ordering. Returns true if successful, or false if
64 // an error was encountered.
65 bool GetAllChangesInTreeOrder(
66 const BaseTransaction* sync_trans,
67 ImmutableChangeRecordList* changes) WARN_UNUSED_RESULT;
69 private:
70 class Traversal;
71 typedef std::map<int64, ChangeRecord::Action> OperationMap;
72 typedef std::map<int64, sync_pb::EntitySpecifics> SpecificsMap;
73 typedef std::map<int64, linked_ptr<ExtraPasswordChangeRecordData> >
74 ExtraDataMap;
76 // Stores the items that have been pushed into the buffer, and the type of
77 // operation that was associated with them.
78 OperationMap operations_;
80 // Stores entity-specific ChangeRecord data per-ID.
81 SpecificsMap specifics_;
83 // Stores type-specific extra data per-ID.
84 ExtraDataMap extra_data_;
86 DISALLOW_COPY_AND_ASSIGN(ChangeReorderBuffer);
89 } // namespace syncer
91 #endif // SYNC_INTERNAL_API_CHANGE_REORDER_BUFFER_H_