| OLD | NEW |
| (Empty) |
| 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. | |
| 8 | |
| 9 #ifndef COMPONENTS_SYNC_CORE_IMPL_CHANGE_REORDER_BUFFER_H_ | |
| 10 #define COMPONENTS_SYNC_CORE_IMPL_CHANGE_REORDER_BUFFER_H_ | |
| 11 | |
| 12 #include <stdint.h> | |
| 13 | |
| 14 #include <map> | |
| 15 #include <vector> | |
| 16 | |
| 17 #include "base/compiler_specific.h" | |
| 18 #include "base/macros.h" | |
| 19 #include "base/memory/linked_ptr.h" | |
| 20 #include "components/sync/core/change_record.h" | |
| 21 #include "components/sync/protocol/sync.pb.h" | |
| 22 | |
| 23 namespace syncer { | |
| 24 | |
| 25 class BaseTransaction; | |
| 26 | |
| 27 // ChangeReorderBuffer is a utility type which accepts an unordered set | |
| 28 // of changes (via its Push methods), and yields an ImmutableChangeRecordList | |
| 29 // (via the GetAllChangesInTreeOrder method) that are in the order that | |
| 30 // the SyncObserver expects them to be. A buffer is initially empty. | |
| 31 // | |
| 32 // The ordering produced by ChangeReorderBuffer is as follows: | |
| 33 // (a) All Deleted items appear first. | |
| 34 // (b) For Updated and/or Added items, parents appear before their children. | |
| 35 // | |
| 36 // The sibling order is not necessarily preserved. | |
| 37 class ChangeReorderBuffer { | |
| 38 public: | |
| 39 ChangeReorderBuffer(); | |
| 40 ~ChangeReorderBuffer(); | |
| 41 | |
| 42 // Insert an item, identified by the metahandle |id|, into the reorder buffer. | |
| 43 // This item will appear in the output list as an ACTION_ADD ChangeRecord. | |
| 44 void PushAddedItem(int64_t id); | |
| 45 | |
| 46 // Insert an item, identified by the metahandle |id|, into the reorder buffer. | |
| 47 // This item will appear in the output list as an ACTION_DELETE ChangeRecord. | |
| 48 void PushDeletedItem(int64_t id); | |
| 49 | |
| 50 // Insert an item, identified by the metahandle |id|, into the reorder buffer. | |
| 51 // This item will appear in the output list as an ACTION_UPDATE ChangeRecord. | |
| 52 void PushUpdatedItem(int64_t id); | |
| 53 | |
| 54 void SetExtraDataForId(int64_t id, ExtraPasswordChangeRecordData* extra); | |
| 55 | |
| 56 void SetSpecificsForId(int64_t id, const sync_pb::EntitySpecifics& specifics); | |
| 57 | |
| 58 // Reset the buffer, forgetting any pushed items, so that it can be used again | |
| 59 // to reorder a new set of changes. | |
| 60 void Clear(); | |
| 61 | |
| 62 bool IsEmpty() const; | |
| 63 | |
| 64 // Output a reordered list of changes to |changes| using the items | |
| 65 // that were pushed into the reorder buffer. |sync_trans| is used to | |
| 66 // determine the ordering. Returns true if successful, or false if | |
| 67 // an error was encountered. | |
| 68 bool GetAllChangesInTreeOrder(const BaseTransaction* sync_trans, | |
| 69 ImmutableChangeRecordList* changes) | |
| 70 WARN_UNUSED_RESULT; | |
| 71 | |
| 72 private: | |
| 73 class Traversal; | |
| 74 typedef std::map<int64_t, ChangeRecord::Action> OperationMap; | |
| 75 typedef std::map<int64_t, sync_pb::EntitySpecifics> SpecificsMap; | |
| 76 typedef std::map<int64_t, linked_ptr<ExtraPasswordChangeRecordData>> | |
| 77 ExtraDataMap; | |
| 78 | |
| 79 // Stores the items that have been pushed into the buffer, and the type of | |
| 80 // operation that was associated with them. | |
| 81 OperationMap operations_; | |
| 82 | |
| 83 // Stores entity-specific ChangeRecord data per-ID. | |
| 84 SpecificsMap specifics_; | |
| 85 | |
| 86 // Stores type-specific extra data per-ID. | |
| 87 ExtraDataMap extra_data_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(ChangeReorderBuffer); | |
| 90 }; | |
| 91 | |
| 92 } // namespace syncer | |
| 93 | |
| 94 #endif // COMPONENTS_SYNC_CORE_IMPL_CHANGE_REORDER_BUFFER_H_ | |
| OLD | NEW |