Commit 4027dfc6 authored by tzik@chromium.org's avatar tzik@chromium.org

[SyncFS] Demote local file changes before local-to-remote sync

This prevents a task to pick a file to sync while another task is syncing it.

BUG=344769
TEST=unit_tests --gtest_filter='LocalFileSyncContextTest.*'

Review URL: https://codereview.chromium.org/390283002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287312 0039d316-1c4b-4281-b951-d872f2087c98
parent 673bc9aa
...@@ -339,6 +339,9 @@ class DriveBackendSyncTest : public testing::Test, ...@@ -339,6 +339,9 @@ class DriveBackendSyncTest : public testing::Test,
SyncStatusCode local_sync_status; SyncStatusCode local_sync_status;
SyncStatusCode remote_sync_status; SyncStatusCode remote_sync_status;
while (true) { while (true) {
base::RunLoop().RunUntilIdle();
WaitForIdleWorker();
if (!task_limit--) if (!task_limit--)
return SYNC_STATUS_ABORT; return SYNC_STATUS_ABORT;
......
...@@ -243,6 +243,7 @@ void LocalFileChangeTracker::PromoteDemotedChangesForURL( ...@@ -243,6 +243,7 @@ void LocalFileChangeTracker::PromoteDemotedChangesForURL(
change_seqs_[iter->second.change_seq] = url; change_seqs_[iter->second.change_seq] = url;
changes_.insert(*iter); changes_.insert(*iter);
demoted_changes_.erase(iter); demoted_changes_.erase(iter);
UpdateNumChanges();
} }
bool LocalFileChangeTracker::PromoteDemotedChanges() { bool LocalFileChangeTracker::PromoteDemotedChanges() {
......
...@@ -173,8 +173,6 @@ void LocalFileSyncContext::FinalizeSnapshotSync( ...@@ -173,8 +173,6 @@ void LocalFileSyncContext::FinalizeSnapshotSync(
} else { } else {
// Abort in-memory mirror change. // Abort in-memory mirror change.
backend->change_tracker()->RemoveMirrorAndCommitChangesForURL(url); backend->change_tracker()->RemoveMirrorAndCommitChangesForURL(url);
if (sync_finish_status == SYNC_STATUS_FILE_BUSY)
backend->change_tracker()->DemoteChangesForURL(url);
} }
// We've been keeping it in writing mode, so clear the writing counter // We've been keeping it in writing mode, so clear the writing counter
...@@ -697,9 +695,9 @@ SyncStatusCode LocalFileSyncContext::InitializeChangeTrackerOnFileThread( ...@@ -697,9 +695,9 @@ SyncStatusCode LocalFileSyncContext::InitializeChangeTrackerOnFileThread(
return status; return status;
// Get all origins that have pending changes. // Get all origins that have pending changes.
std::deque<FileSystemURL> urls; FileSystemURLQueue urls;
(*tracker_ptr)->GetNextChangedURLs(&urls, 0); (*tracker_ptr)->GetNextChangedURLs(&urls, 0);
for (std::deque<FileSystemURL>::iterator iter = urls.begin(); for (FileSystemURLQueue::iterator iter = urls.begin();
iter != urls.end(); ++iter) { iter != urls.end(); ++iter) {
origins_with_changes->insert(iter->origin()); origins_with_changes->insert(iter->origin());
} }
...@@ -785,6 +783,10 @@ LocalFileSyncContext::GetNextURLsForSyncOnFileThread( ...@@ -785,6 +783,10 @@ LocalFileSyncContext::GetNextURLsForSyncOnFileThread(
scoped_ptr<FileSystemURLQueue> urls(new FileSystemURLQueue); scoped_ptr<FileSystemURLQueue> urls(new FileSystemURLQueue);
backend->change_tracker()->GetNextChangedURLs( backend->change_tracker()->GetNextChangedURLs(
urls.get(), kMaxURLsToFetchForLocalSync); urls.get(), kMaxURLsToFetchForLocalSync);
for (FileSystemURLQueue::iterator iter = urls->begin();
iter != urls->end(); ++iter)
backend->change_tracker()->DemoteChangesForURL(*iter);
return urls.Pass(); return urls.Pass();
} }
...@@ -826,13 +828,63 @@ void LocalFileSyncContext::DidTryPrepareForLocalSync( ...@@ -826,13 +828,63 @@ void LocalFileSyncContext::DidTryPrepareForLocalSync(
webkit_blob::ScopedFile snapshot) { webkit_blob::ScopedFile snapshot) {
DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
if (status != SYNC_STATUS_FILE_BUSY) { if (status != SYNC_STATUS_FILE_BUSY) {
PromoteDemotedChangesForURLs(file_system_context,
remaining_urls.Pass());
callback.Run(status, sync_file_info, snapshot.Pass()); callback.Run(status, sync_file_info, snapshot.Pass());
return; return;
} }
PromoteDemotedChangesForURL(file_system_context, sync_file_info.url);
// Recursively call TryPrepareForLocalSync with remaining_urls. // Recursively call TryPrepareForLocalSync with remaining_urls.
TryPrepareForLocalSync(file_system_context, callback, remaining_urls.Pass()); TryPrepareForLocalSync(file_system_context, callback, remaining_urls.Pass());
} }
void LocalFileSyncContext::PromoteDemotedChangesForURL(
FileSystemContext* file_system_context,
const FileSystemURL& url) {
DCHECK(file_system_context);
if (!file_system_context->default_file_task_runner()->
RunsTasksOnCurrentThread()) {
DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
if (shutdown_on_ui_)
return;
file_system_context->default_file_task_runner()->PostTask(
FROM_HERE,
base::Bind(&LocalFileSyncContext::PromoteDemotedChangesForURL,
this, make_scoped_refptr(file_system_context), url));
return;
}
SyncFileSystemBackend* backend =
SyncFileSystemBackend::GetBackend(file_system_context);
DCHECK(backend);
DCHECK(backend->change_tracker());
backend->change_tracker()->PromoteDemotedChangesForURL(url);
}
void LocalFileSyncContext::PromoteDemotedChangesForURLs(
FileSystemContext* file_system_context,
scoped_ptr<FileSystemURLQueue> urls) {
DCHECK(file_system_context);
if (!file_system_context->default_file_task_runner()->
RunsTasksOnCurrentThread()) {
DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
if (shutdown_on_ui_)
return;
file_system_context->default_file_task_runner()->PostTask(
FROM_HERE,
base::Bind(&LocalFileSyncContext::PromoteDemotedChangesForURLs,
this, make_scoped_refptr(file_system_context),
base::Passed(&urls)));
return;
}
for (FileSystemURLQueue::iterator iter = urls->begin();
iter != urls->end(); ++iter)
PromoteDemotedChangesForURL(file_system_context, *iter);
}
void LocalFileSyncContext::DidGetWritingStatusForSync( void LocalFileSyncContext::DidGetWritingStatusForSync(
FileSystemContext* file_system_context, FileSystemContext* file_system_context,
SyncStatusCode status, SyncStatusCode status,
......
...@@ -274,6 +274,12 @@ class LocalFileSyncContext ...@@ -274,6 +274,12 @@ class LocalFileSyncContext
SyncStatusCode status, SyncStatusCode status,
const LocalFileSyncInfo& sync_file_info, const LocalFileSyncInfo& sync_file_info,
webkit_blob::ScopedFile snapshot); webkit_blob::ScopedFile snapshot);
void PromoteDemotedChangesForURL(
fileapi::FileSystemContext* file_system_context,
const fileapi::FileSystemURL& url);
void PromoteDemotedChangesForURLs(
fileapi::FileSystemContext* file_system_context,
scoped_ptr<FileSystemURLQueue> url);
// Callback routine for PrepareForSync and GetFileForLocalSync. // Callback routine for PrepareForSync and GetFileForLocalSync.
void DidGetWritingStatusForSync( void DidGetWritingStatusForSync(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment