OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Defines ChangeReorderBuffer, which can be used to sort a list of item | 5 // Defines ChangeReorderBuffer, which can be used to sort a list of item |
6 // actions to achieve the ordering constraint required by the SyncObserver | 6 // actions to achieve the ordering constraint required by the SyncObserver |
7 // interface of the SyncAPI. | 7 // interface of the SyncAPI. |
8 | 8 |
9 #ifndef CHROME_BROWSER_SYNC_INTERNAL_API_CHANGE_REORDER_BUFFER_H_ | 9 #ifndef CHROME_BROWSER_SYNC_INTERNAL_API_CHANGE_REORDER_BUFFER_H_ |
10 #define CHROME_BROWSER_SYNC_INTERNAL_API_CHANGE_REORDER_BUFFER_H_ | 10 #define CHROME_BROWSER_SYNC_INTERNAL_API_CHANGE_REORDER_BUFFER_H_ |
11 #pragma once | 11 #pragma once |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
| 16 #include "base/compiler_specific.h" |
16 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
17 #include "chrome/browser/sync/internal_api/base_transaction.h" | 18 #include "chrome/browser/sync/internal_api/base_transaction.h" |
18 #include "chrome/browser/sync/internal_api/change_record.h" | 19 #include "chrome/browser/sync/internal_api/change_record.h" |
19 #include "chrome/browser/sync/protocol/sync.pb.h" | 20 #include "chrome/browser/sync/protocol/sync.pb.h" |
20 | 21 |
21 namespace sync_api { | 22 namespace sync_api { |
22 | 23 |
23 // ChangeReorderBuffer is a utility type which accepts an unordered set | 24 // ChangeReorderBuffer is a utility type which accepts an unordered set |
24 // of changes (via its Push methods), and yields an ImmutableChangeRecordList | 25 // of changes (via its Push methods), and yields an ImmutableChangeRecordList |
25 // (via the GetAllChangesInTreeOrder method) that are in the order that | 26 // (via the GetAllChangesInTreeOrder method) that are in the order that |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // Reset the buffer, forgetting any pushed items, so that it can be used | 78 // Reset the buffer, forgetting any pushed items, so that it can be used |
78 // again to reorder a new set of changes. | 79 // again to reorder a new set of changes. |
79 void Clear() { | 80 void Clear() { |
80 operations_.clear(); | 81 operations_.clear(); |
81 } | 82 } |
82 | 83 |
83 bool IsEmpty() const { | 84 bool IsEmpty() const { |
84 return operations_.empty(); | 85 return operations_.empty(); |
85 } | 86 } |
86 | 87 |
87 // Output a reordered list of changes to |changelist| using the items that | 88 // Output a reordered list of changes to |changes| using the items |
88 // were pushed into the reorder buffer. |sync_trans| is used to determine the | 89 // that were pushed into the reorder buffer. |sync_trans| is used to |
89 // ordering. | 90 // determine the ordering. Returns true if successful, or false if |
90 ImmutableChangeRecordList | 91 // an error was encountered. |
91 GetAllChangesInTreeOrder(const BaseTransaction* sync_trans); | 92 bool GetAllChangesInTreeOrder( |
| 93 const BaseTransaction* sync_trans, |
| 94 ImmutableChangeRecordList* changes) WARN_UNUSED_RESULT; |
92 | 95 |
93 private: | 96 private: |
94 class Traversal; | 97 class Traversal; |
95 enum Operation { | 98 enum Operation { |
96 OP_ADD, // AddedItem. | 99 OP_ADD, // AddedItem. |
97 OP_DELETE, // DeletedItem. | 100 OP_DELETE, // DeletedItem. |
98 OP_UPDATE_PROPERTIES_ONLY, // UpdatedItem with position_changed=0. | 101 OP_UPDATE_PROPERTIES_ONLY, // UpdatedItem with position_changed=0. |
99 OP_UPDATE_POSITION_AND_PROPERTIES, // UpdatedItem with position_changed=1. | 102 OP_UPDATE_POSITION_AND_PROPERTIES, // UpdatedItem with position_changed=1. |
100 }; | 103 }; |
101 typedef std::map<int64, Operation> OperationMap; | 104 typedef std::map<int64, Operation> OperationMap; |
(...skipping 10 matching lines...) Expand all Loading... |
112 | 115 |
113 // Stores type-specific extra data per-ID. | 116 // Stores type-specific extra data per-ID. |
114 ExtraDataMap extra_data_; | 117 ExtraDataMap extra_data_; |
115 | 118 |
116 DISALLOW_COPY_AND_ASSIGN(ChangeReorderBuffer); | 119 DISALLOW_COPY_AND_ASSIGN(ChangeReorderBuffer); |
117 }; | 120 }; |
118 | 121 |
119 } // namespace sync_api | 122 } // namespace sync_api |
120 | 123 |
121 #endif // CHROME_BROWSER_SYNC_INTERNAL_API_CHANGE_REORDER_BUFFER_H_ | 124 #endif // CHROME_BROWSER_SYNC_INTERNAL_API_CHANGE_REORDER_BUFFER_H_ |
OLD | NEW |