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

Side by Side Diff: chrome/browser/sync/engine/get_commit_ids_command.h

Issue 386030: Relieve SyncerSession,SyncCycleState, SyncProcessState, SyncerSession, Syncer... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ 5 #ifndef CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_
6 #define CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ 6 #define CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_
7 7
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "chrome/browser/sync/engine/syncer_command.h" 11 #include "chrome/browser/sync/engine/syncer_command.h"
12 #include "chrome/browser/sync/engine/syncer_session.h"
13 #include "chrome/browser/sync/engine/syncer_util.h" 12 #include "chrome/browser/sync/engine/syncer_util.h"
13 #include "chrome/browser/sync/sessions/sync_session.h"
14 #include "chrome/browser/sync/util/sync_types.h" 14 #include "chrome/browser/sync/util/sync_types.h"
15 15
16 using std::pair; 16 using std::pair;
17 using std::vector; 17 using std::vector;
18 18
19 namespace browser_sync { 19 namespace browser_sync {
20 20
21 class GetCommitIdsCommand : public SyncerCommand { 21 class GetCommitIdsCommand : public SyncerCommand {
22 friend class SyncerTest; 22 friend class SyncerTest;
23 23
24 public: 24 public:
25 explicit GetCommitIdsCommand(int commit_batch_size); 25 explicit GetCommitIdsCommand(int commit_batch_size);
26 virtual ~GetCommitIdsCommand(); 26 virtual ~GetCommitIdsCommand();
27 27
28 virtual void ExecuteImpl(SyncerSession* session); 28 // SyncerCommand implementation.
29 virtual void ExecuteImpl(sessions::SyncSession* session);
29 30
30 // Returns a vector of IDs that should be committed. 31 // Builds a vector of IDs that should be committed.
31 void BuildCommitIds(SyncerSession *session); 32 void BuildCommitIds(const vector<int64>& unsynced_handles,
33 syncable::WriteTransaction* write_transaction);
32 34
33 // These classes are public for testing. 35 // These classes are public for testing.
34 // TODO(ncarter): This code is more generic than just Commit and can 36 // TODO(ncarter): This code is more generic than just Commit and can
35 // be reused elsewhere (e.g. ChangeReorderBuffer do similar things). Merge 37 // be reused elsewhere (e.g. ChangeReorderBuffer do similar things). Merge
36 // all these implementations. 38 // all these implementations.
37 class OrderedCommitSet { 39 class OrderedCommitSet {
38 public: 40 public:
39 // TODO(chron): Reserve space according to batch size? 41 // TODO(chron): Reserve space according to batch size?
40 OrderedCommitSet() {} 42 OrderedCommitSet() {}
41 ~OrderedCommitSet() {} 43 ~OrderedCommitSet() {}
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 }; 96 };
95 97
96 98
97 // TODO(chron): Remove writes from this iterator. As a warning, this 99 // TODO(chron): Remove writes from this iterator. As a warning, this
98 // iterator causes writes to entries and so isn't a pure iterator. 100 // iterator causes writes to entries and so isn't a pure iterator.
99 // It will do Put(IS_UNSYNCED). Refactor this out later. 101 // It will do Put(IS_UNSYNCED). Refactor this out later.
100 class CommitMetahandleIterator { 102 class CommitMetahandleIterator {
101 public: 103 public:
102 // TODO(chron): Cache ValidateCommitEntry responses across iterators to save 104 // TODO(chron): Cache ValidateCommitEntry responses across iterators to save
103 // UTF8 conversion and filename checking 105 // UTF8 conversion and filename checking
104 CommitMetahandleIterator(SyncerSession* session, 106 CommitMetahandleIterator(const vector<int64>& unsynced_handles,
107 syncable::WriteTransaction* write_transaction,
105 OrderedCommitSet* commit_set) 108 OrderedCommitSet* commit_set)
106 : session_(session), 109 : write_transaction_(write_transaction),
110 handle_iterator_(unsynced_handles.begin()),
111 unsynced_handles_end_(unsynced_handles.end()),
107 commit_set_(commit_set) { 112 commit_set_(commit_set) {
108 handle_iterator_ = session->unsynced_handles().begin();
109 113
110 // TODO(chron): Remove writes from this iterator. 114 // TODO(chron): Remove writes from this iterator.
111 DCHECK(session->has_open_write_transaction()); 115 DCHECK(write_transaction_);
112 116
113 if (Valid() && !ValidateMetahandleForCommit(*handle_iterator_)) 117 if (Valid() && !ValidateMetahandleForCommit(*handle_iterator_))
114 Increment(); 118 Increment();
115 } 119 }
116 ~CommitMetahandleIterator() {} 120 ~CommitMetahandleIterator() {}
117 121
118 int64 Current() const { 122 int64 Current() const {
119 DCHECK(Valid()); 123 DCHECK(Valid());
120 return *handle_iterator_; 124 return *handle_iterator_;
121 } 125 }
122 126
123 bool Increment() { 127 bool Increment() {
124 if (!Valid()) 128 if (!Valid())
125 return false; 129 return false;
126 130
127 for (++handle_iterator_; 131 for (++handle_iterator_;
128 handle_iterator_ != session_->unsynced_handles().end(); 132 handle_iterator_ != unsynced_handles_end_;
129 ++handle_iterator_) { 133 ++handle_iterator_) {
130 if (ValidateMetahandleForCommit(*handle_iterator_)) 134 if (ValidateMetahandleForCommit(*handle_iterator_))
131 return true; 135 return true;
132 } 136 }
133 137
134 return false; 138 return false;
135 } 139 }
136 140
137 bool Valid() const { 141 bool Valid() const {
138 return !(handle_iterator_ == session_->unsynced_handles().end()); 142 return !(handle_iterator_ == unsynced_handles_end_);
139 } 143 }
140 144
141 private: 145 private:
142 bool ValidateMetahandleForCommit(int64 metahandle) { 146 bool ValidateMetahandleForCommit(int64 metahandle) {
143 if (commit_set_->HaveCommitItem(metahandle)) 147 if (commit_set_->HaveCommitItem(metahandle))
144 return false; 148 return false;
145 149
146 // We should really not WRITE in this iterator, but we can fix that 150 // We should really not WRITE in this iterator, but we can fix that
147 // later. ValidateCommitEntry writes to the DB, and we add the blocked 151 // later. We should move that somewhere else later.
148 // items. We should move that somewhere else later. 152 syncable::MutableEntry entry(write_transaction_,
149 syncable::MutableEntry entry(session_->write_transaction(),
150 syncable::GET_BY_HANDLE, metahandle); 153 syncable::GET_BY_HANDLE, metahandle);
151 VerifyCommitResult verify_result = 154 VerifyCommitResult verify_result =
152 SyncerUtil::ValidateCommitEntry(&entry); 155 SyncerUtil::ValidateCommitEntry(&entry);
153 if (verify_result == VERIFY_UNSYNCABLE) { 156 if (verify_result == VERIFY_UNSYNCABLE) {
154 // Drop unsyncable entries. 157 // Drop unsyncable entries.
155 entry.Put(syncable::IS_UNSYNCED, false); 158 entry.Put(syncable::IS_UNSYNCED, false);
156 } 159 }
157 return verify_result == VERIFY_OK; 160 return verify_result == VERIFY_OK;
158 } 161 }
159 162
160 SyncerSession* session_; 163 syncable::WriteTransaction* const write_transaction_;
161 vector<int64>::const_iterator handle_iterator_; 164 vector<int64>::const_iterator handle_iterator_;
165 vector<int64>::const_iterator unsynced_handles_end_;
162 OrderedCommitSet* commit_set_; 166 OrderedCommitSet* commit_set_;
163 167
164 DISALLOW_COPY_AND_ASSIGN(CommitMetahandleIterator); 168 DISALLOW_COPY_AND_ASSIGN(CommitMetahandleIterator);
165 }; 169 };
166 170
167 private: 171 private:
168 void AddUncommittedParentsAndTheirPredecessors( 172 void AddUncommittedParentsAndTheirPredecessors(
169 syncable::BaseTransaction* trans, 173 syncable::BaseTransaction* trans,
170 syncable::Id parent_id); 174 syncable::Id parent_id);
171 175
172 // OrderedCommitSet helpers for adding predecessors in order. 176 // OrderedCommitSet helpers for adding predecessors in order.
173 // TODO(ncarter): Refactor these so that the |result| parameter goes away, 177 // TODO(ncarter): Refactor these so that the |result| parameter goes away,
174 // and AddItem doesn't need to consider two OrderedCommitSets. 178 // and AddItem doesn't need to consider two OrderedCommitSets.
175 bool AddItem(syncable::Entry* item, OrderedCommitSet* result); 179 bool AddItem(syncable::Entry* item, OrderedCommitSet* result);
176 bool AddItemThenPredecessors(syncable::BaseTransaction* trans, 180 bool AddItemThenPredecessors(syncable::BaseTransaction* trans,
177 syncable::Entry* item, 181 syncable::Entry* item,
178 syncable::IndexedBitField inclusion_filter, 182 syncable::IndexedBitField inclusion_filter,
179 OrderedCommitSet* result); 183 OrderedCommitSet* result);
180 void AddPredecessorsThenItem(syncable::BaseTransaction* trans, 184 void AddPredecessorsThenItem(syncable::BaseTransaction* trans,
181 syncable::Entry* item, 185 syncable::Entry* item,
182 syncable::IndexedBitField inclusion_filter); 186 syncable::IndexedBitField inclusion_filter);
183 187
184 bool IsCommitBatchFull(); 188 bool IsCommitBatchFull();
185 189
186 void AddCreatesAndMoves(SyncerSession* session); 190 void AddCreatesAndMoves(const vector<int64>& unsynced_handles,
191 syncable::WriteTransaction* write_transaction);
187 192
188 void AddDeletes(SyncerSession* session); 193 void AddDeletes(const vector<int64>& unsynced_handles,
194 syncable::WriteTransaction* write_transaction);
189 195
190 OrderedCommitSet ordered_commit_set_; 196 OrderedCommitSet ordered_commit_set_;
191 197
192 int requested_commit_batch_size_; 198 int requested_commit_batch_size_;
193 199
194 DISALLOW_COPY_AND_ASSIGN(GetCommitIdsCommand); 200 DISALLOW_COPY_AND_ASSIGN(GetCommitIdsCommand);
195 }; 201 };
196 202
197 } // namespace browser_sync 203 } // namespace browser_sync
198 204
199 #endif // CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ 205 #endif // CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/download_updates_command.cc ('k') | chrome/browser/sync/engine/get_commit_ids_command.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698