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

Side by Side Diff: chrome/browser/sync_file_system/local/local_file_change_tracker.cc

Issue 386373002: [SyncFS] Add per-URL promote of demoted changes in LocalFileChangeTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync_file_system/local/local_file_change_tracker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/sync_file_system/local/local_file_change_tracker.h" 5 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 SYNC_FILE_TYPE_DIRECTORY)); 124 SYNC_FILE_TYPE_DIRECTORY));
125 } 125 }
126 126
127 void LocalFileChangeTracker::OnRemoveDirectory(const FileSystemURL& url) { 127 void LocalFileChangeTracker::OnRemoveDirectory(const FileSystemURL& url) {
128 RecordChange(url, FileChange(FileChange::FILE_CHANGE_DELETE, 128 RecordChange(url, FileChange(FileChange::FILE_CHANGE_DELETE,
129 SYNC_FILE_TYPE_DIRECTORY)); 129 SYNC_FILE_TYPE_DIRECTORY));
130 } 130 }
131 131
132 void LocalFileChangeTracker::GetNextChangedURLs( 132 void LocalFileChangeTracker::GetNextChangedURLs(
133 std::deque<FileSystemURL>* urls, int max_urls) { 133 std::deque<FileSystemURL>* urls, int max_urls) {
134 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
134 DCHECK(urls); 135 DCHECK(urls);
135 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
136 urls->clear(); 136 urls->clear();
137 // Mildly prioritizes the URLs that older changes and have not been updated 137 // Mildly prioritizes the URLs that older changes and have not been updated
138 // for a while. 138 // for a while.
139 for (ChangeSeqMap::iterator iter = change_seqs_.begin(); 139 for (ChangeSeqMap::iterator iter = change_seqs_.begin();
140 iter != change_seqs_.end() && 140 iter != change_seqs_.end() &&
141 (max_urls == 0 || urls->size() < static_cast<size_t>(max_urls)); 141 (max_urls == 0 || urls->size() < static_cast<size_t>(max_urls));
142 ++iter) { 142 ++iter) {
143 urls->push_back(iter->second); 143 urls->push_back(iter->second);
144 } 144 }
145 } 145 }
(...skipping 20 matching lines...) Expand all
166 FileChangeMap::iterator found = changes_.find(url); 166 FileChangeMap::iterator found = changes_.find(url);
167 if (found == changes_.end()) 167 if (found == changes_.end())
168 return; 168 return;
169 change_seqs_.erase(found->second.change_seq); 169 change_seqs_.erase(found->second.change_seq);
170 changes_.erase(found); 170 changes_.erase(found);
171 UpdateNumChanges(); 171 UpdateNumChanges();
172 } 172 }
173 173
174 void LocalFileChangeTracker::CreateFreshMirrorForURL( 174 void LocalFileChangeTracker::CreateFreshMirrorForURL(
175 const fileapi::FileSystemURL& url) { 175 const fileapi::FileSystemURL& url) {
176 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
176 DCHECK(!ContainsKey(mirror_changes_, url)); 177 DCHECK(!ContainsKey(mirror_changes_, url));
177 mirror_changes_[url] = ChangeInfo(); 178 mirror_changes_[url] = ChangeInfo();
178 } 179 }
179 180
180 void LocalFileChangeTracker::RemoveMirrorAndCommitChangesForURL( 181 void LocalFileChangeTracker::RemoveMirrorAndCommitChangesForURL(
181 const fileapi::FileSystemURL& url) { 182 const fileapi::FileSystemURL& url) {
183 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
182 FileChangeMap::iterator found = mirror_changes_.find(url); 184 FileChangeMap::iterator found = mirror_changes_.find(url);
183 if (found == mirror_changes_.end()) 185 if (found == mirror_changes_.end())
184 return; 186 return;
185 mirror_changes_.erase(found); 187 mirror_changes_.erase(found);
186 188
187 if (ContainsKey(changes_, url)) 189 if (ContainsKey(changes_, url))
188 MarkDirtyOnDatabase(url); 190 MarkDirtyOnDatabase(url);
189 else 191 else
190 ClearDirtyOnDatabase(url); 192 ClearDirtyOnDatabase(url);
191 UpdateNumChanges(); 193 UpdateNumChanges();
192 } 194 }
193 195
194 void LocalFileChangeTracker::ResetToMirrorAndCommitChangesForURL( 196 void LocalFileChangeTracker::ResetToMirrorAndCommitChangesForURL(
195 const fileapi::FileSystemURL& url) { 197 const fileapi::FileSystemURL& url) {
198 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
196 FileChangeMap::iterator found = mirror_changes_.find(url); 199 FileChangeMap::iterator found = mirror_changes_.find(url);
197 if (found == mirror_changes_.end() || found->second.change_list.empty()) { 200 if (found == mirror_changes_.end() || found->second.change_list.empty()) {
198 ClearChangesForURL(url); 201 ClearChangesForURL(url);
199 return; 202 return;
200 } 203 }
201 const ChangeInfo& info = found->second; 204 const ChangeInfo& info = found->second;
202 change_seqs_[info.change_seq] = url; 205 change_seqs_[info.change_seq] = url;
203 changes_[url] = info; 206 changes_[url] = info;
204 RemoveMirrorAndCommitChangesForURL(url); 207 RemoveMirrorAndCommitChangesForURL(url);
205 } 208 }
206 209
207 void LocalFileChangeTracker::DemoteChangesForURL( 210 void LocalFileChangeTracker::DemoteChangesForURL(
208 const fileapi::FileSystemURL& url) { 211 const fileapi::FileSystemURL& url) {
212 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
209 FileChangeMap::iterator found = changes_.find(url); 213 FileChangeMap::iterator found = changes_.find(url);
210 if (found == changes_.end()) 214 if (found == changes_.end())
211 return; 215 return;
212 FileChangeList changes = found->second.change_list; 216 FileChangeList changes = found->second.change_list;
213 217
214 mirror_changes_.erase(url); 218 mirror_changes_.erase(url);
215 change_seqs_.erase(found->second.change_seq); 219 change_seqs_.erase(found->second.change_seq);
216 changes_.erase(found); 220 changes_.erase(found);
217 221
218 FileChangeList::List change_list = changes.list(); 222 FileChangeList::List change_list = changes.list();
219 while (!change_list.empty()) { 223 while (!change_list.empty()) {
220 RecordChangeToChangeMaps(url, change_list.front(), 0, 224 RecordChangeToChangeMaps(url, change_list.front(), 0,
221 &demoted_changes_, NULL); 225 &demoted_changes_, NULL);
222 change_list.pop_front(); 226 change_list.pop_front();
223 } 227 }
224 } 228 }
225 229
230 void LocalFileChangeTracker::PromoteDemotedChangesForURL(
231 const fileapi::FileSystemURL& url) {
232 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
233
234 FileChangeMap::iterator iter = demoted_changes_.find(url);
235 if (iter == demoted_changes_.end())
236 return;
237
238 FileChangeList::List change_list = iter->second.change_list.list();
239 // Make sure that this URL is in no queues.
240 DCHECK(!ContainsKey(changes_, url));
241 DCHECK(!ContainsKey(demoted_changes_, url));
peria 2014/07/14 07:55:32 This DCHECK must fail. |url| is found from |demote
tzik 2014/07/14 08:03:49 Done.
242 DCHECK(!ContainsKey(mirror_changes_, url));
243
244 while (!change_list.empty()) {
245 RecordChange(url, change_list.front());
246 change_list.pop_front();
247 }
248
249 demoted_changes_.erase(iter);
250 }
251
226 bool LocalFileChangeTracker::PromoteDemotedChanges() { 252 bool LocalFileChangeTracker::PromoteDemotedChanges() {
253 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
227 if (demoted_changes_.empty()) 254 if (demoted_changes_.empty())
228 return false; 255 return false;
229 for (FileChangeMap::iterator iter = demoted_changes_.begin(); 256 while (!demoted_changes_.empty())
230 iter != demoted_changes_.end();) { 257 PromoteDemotedChangesForURL(demoted_changes_.begin()->first);
231 fileapi::FileSystemURL url = iter->first;
232 FileChangeList::List change_list = iter->second.change_list.list();
233 demoted_changes_.erase(iter++);
234
235 // Make sure that this URL is in no queues.
236 DCHECK(!ContainsKey(changes_, url));
237 DCHECK(!ContainsKey(demoted_changes_, url));
238 DCHECK(!ContainsKey(mirror_changes_, url));
239
240 while (!change_list.empty()) {
241 RecordChange(url, change_list.front());
242 change_list.pop_front();
243 }
244 }
245 demoted_changes_.clear();
246 return true; 258 return true;
247 } 259 }
248 260
249 SyncStatusCode LocalFileChangeTracker::Initialize( 261 SyncStatusCode LocalFileChangeTracker::Initialize(
250 FileSystemContext* file_system_context) { 262 FileSystemContext* file_system_context) {
251 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); 263 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
252 DCHECK(!initialized_); 264 DCHECK(!initialized_);
253 DCHECK(file_system_context); 265 DCHECK(file_system_context);
254 266
255 SyncStatusCode status = CollectLastDirtyChanges(file_system_context); 267 SyncStatusCode status = CollectLastDirtyChanges(file_system_context);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 tracker_db_->WriteBatch(batch.Pass()); 301 tracker_db_->WriteBatch(batch.Pass());
290 UpdateNumChanges(); 302 UpdateNumChanges();
291 } 303 }
292 304
293 void LocalFileChangeTracker::UpdateNumChanges() { 305 void LocalFileChangeTracker::UpdateNumChanges() {
294 base::AutoLock lock(num_changes_lock_); 306 base::AutoLock lock(num_changes_lock_);
295 num_changes_ = static_cast<int64>(change_seqs_.size()); 307 num_changes_ = static_cast<int64>(change_seqs_.size());
296 } 308 }
297 309
298 void LocalFileChangeTracker::GetAllChangedURLs(FileSystemURLSet* urls) { 310 void LocalFileChangeTracker::GetAllChangedURLs(FileSystemURLSet* urls) {
311 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
299 std::deque<FileSystemURL> url_deque; 312 std::deque<FileSystemURL> url_deque;
300 GetNextChangedURLs(&url_deque, 0); 313 GetNextChangedURLs(&url_deque, 0);
301 urls->clear(); 314 urls->clear();
302 urls->insert(url_deque.begin(), url_deque.end()); 315 urls->insert(url_deque.begin(), url_deque.end());
303 } 316 }
304 317
305 void LocalFileChangeTracker::DropAllChanges() { 318 void LocalFileChangeTracker::DropAllChanges() {
319 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
306 changes_.clear(); 320 changes_.clear();
307 change_seqs_.clear(); 321 change_seqs_.clear();
308 mirror_changes_.clear(); 322 mirror_changes_.clear();
309 } 323 }
310 324
311 SyncStatusCode LocalFileChangeTracker::MarkDirtyOnDatabase( 325 SyncStatusCode LocalFileChangeTracker::MarkDirtyOnDatabase(
312 const FileSystemURL& url) { 326 const FileSystemURL& url) {
313 std::string serialized_url; 327 std::string serialized_url;
314 if (!SerializeSyncableFileSystemURL(url, &serialized_url)) 328 if (!SerializeSyncableFileSystemURL(url, &serialized_url))
315 return SYNC_FILE_ERROR_INVALID_URL; 329 return SYNC_FILE_ERROR_INVALID_URL;
316 330
317 return tracker_db_->MarkDirty(serialized_url); 331 return tracker_db_->MarkDirty(serialized_url);
318 } 332 }
319 333
320 SyncStatusCode LocalFileChangeTracker::ClearDirtyOnDatabase( 334 SyncStatusCode LocalFileChangeTracker::ClearDirtyOnDatabase(
321 const FileSystemURL& url) { 335 const FileSystemURL& url) {
336 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
322 std::string serialized_url; 337 std::string serialized_url;
323 if (!SerializeSyncableFileSystemURL(url, &serialized_url)) 338 if (!SerializeSyncableFileSystemURL(url, &serialized_url))
324 return SYNC_FILE_ERROR_INVALID_URL; 339 return SYNC_FILE_ERROR_INVALID_URL;
325 340
326 return tracker_db_->ClearDirty(serialized_url); 341 return tracker_db_->ClearDirty(serialized_url);
327 } 342 }
328 343
329 SyncStatusCode LocalFileChangeTracker::CollectLastDirtyChanges( 344 SyncStatusCode LocalFileChangeTracker::CollectLastDirtyChanges(
330 FileSystemContext* file_system_context) { 345 FileSystemContext* file_system_context) {
331 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); 346 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 RecordChangeToChangeMaps(url, change, 0, &demoted_changes_, NULL); 415 RecordChangeToChangeMaps(url, change, 0, &demoted_changes_, NULL);
401 return; 416 return;
402 } 417 }
403 int change_seq = current_change_seq_++; 418 int change_seq = current_change_seq_++;
404 RecordChangeToChangeMaps(url, change, change_seq, &changes_, &change_seqs_); 419 RecordChangeToChangeMaps(url, change, change_seq, &changes_, &change_seqs_);
405 if (ContainsKey(mirror_changes_, url)) 420 if (ContainsKey(mirror_changes_, url))
406 RecordChangeToChangeMaps(url, change, change_seq, &mirror_changes_, NULL); 421 RecordChangeToChangeMaps(url, change, change_seq, &mirror_changes_, NULL);
407 UpdateNumChanges(); 422 UpdateNumChanges();
408 } 423 }
409 424
425 // static
410 void LocalFileChangeTracker::RecordChangeToChangeMaps( 426 void LocalFileChangeTracker::RecordChangeToChangeMaps(
411 const FileSystemURL& url, 427 const FileSystemURL& url,
412 const FileChange& change, 428 const FileChange& change,
413 int new_change_seq, 429 int new_change_seq,
414 FileChangeMap* changes, 430 FileChangeMap* changes,
415 ChangeSeqMap* change_seqs) { 431 ChangeSeqMap* change_seqs) {
416 ChangeInfo& info = (*changes)[url]; 432 ChangeInfo& info = (*changes)[url];
417 if (info.change_seq >= 0 && change_seqs) 433 if (info.change_seq >= 0 && change_seqs)
418 change_seqs->erase(info.change_seq); 434 change_seqs->erase(info.change_seq);
419 info.change_list.Update(change); 435 info.change_list.Update(change);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 if (!status.ok() && !status.IsNotFound()) { 589 if (!status.ok() && !status.IsNotFound()) {
574 HandleError(FROM_HERE, status); 590 HandleError(FROM_HERE, status);
575 db_status_ = LevelDBStatusToSyncStatusCode(status); 591 db_status_ = LevelDBStatusToSyncStatusCode(status);
576 db_.reset(); 592 db_.reset();
577 return db_status_; 593 return db_status_;
578 } 594 }
579 return SYNC_STATUS_OK; 595 return SYNC_STATUS_OK;
580 } 596 }
581 597
582 } // namespace sync_file_system 598 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/local/local_file_change_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698