Skip to content

Commit

Permalink
[SyncFS] Interface clean up around LocalfileSyncContext::GetFileForLo…
Browse files Browse the repository at this point in the history
…calSync

BUG=344769

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282940 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tzik@chromium.org committed Jul 14, 2014
1 parent 7b6d21c commit 15c7939
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
32 changes: 15 additions & 17 deletions chrome/browser/sync_file_system/local/local_file_sync_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,13 @@ void LocalFileSyncContext::GetFileForLocalSync(
DCHECK(file_system_context);
DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());

std::deque<FileSystemURL>* urls = new std::deque<FileSystemURL>;
file_system_context->default_file_task_runner()->PostTaskAndReply(
base::PostTaskAndReplyWithResult(
file_system_context->default_file_task_runner(),
FROM_HERE,
base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread,
this, make_scoped_refptr(file_system_context),
base::Unretained(urls)),
this, make_scoped_refptr(file_system_context)),
base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync,
this, make_scoped_refptr(file_system_context),
base::Owned(urls), callback));
this, make_scoped_refptr(file_system_context), callback));
}

void LocalFileSyncContext::ClearChangesForURL(
Expand Down Expand Up @@ -763,24 +761,26 @@ void LocalFileSyncContext::DidInitialize(
pending_initialize_callbacks_.erase(file_system_context);
}

void LocalFileSyncContext::GetNextURLsForSyncOnFileThread(
FileSystemContext* file_system_context,
std::deque<FileSystemURL>* urls) {
scoped_ptr<LocalFileSyncContext::FileSystemURLQueue>
LocalFileSyncContext::GetNextURLsForSyncOnFileThread(
FileSystemContext* file_system_context) {
DCHECK(file_system_context);
DCHECK(file_system_context->default_file_task_runner()->
RunsTasksOnCurrentThread());
SyncFileSystemBackend* backend =
SyncFileSystemBackend::GetBackend(file_system_context);
DCHECK(backend);
DCHECK(backend->change_tracker());
scoped_ptr<FileSystemURLQueue> urls(new FileSystemURLQueue);
backend->change_tracker()->GetNextChangedURLs(
urls, kMaxURLsToFetchForLocalSync);
urls.get(), kMaxURLsToFetchForLocalSync);
return urls.Pass();
}

void LocalFileSyncContext::TryPrepareForLocalSync(
FileSystemContext* file_system_context,
std::deque<FileSystemURL>* urls,
const LocalFileSyncInfoCallback& callback) {
const LocalFileSyncInfoCallback& callback,
scoped_ptr<FileSystemURLQueue> urls) {
DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
DCHECK(urls);

Expand All @@ -798,19 +798,17 @@ void LocalFileSyncContext::TryPrepareForLocalSync(

const FileSystemURL url = urls->front();
urls->pop_front();
std::deque<FileSystemURL>* remaining = new std::deque<FileSystemURL>;
remaining->swap(*urls);

PrepareForSync(
file_system_context, url, SYNC_SNAPSHOT,
base::Bind(&LocalFileSyncContext::DidTryPrepareForLocalSync,
this, make_scoped_refptr(file_system_context),
base::Owned(remaining), callback));
base::Passed(&urls), callback));
}

void LocalFileSyncContext::DidTryPrepareForLocalSync(
FileSystemContext* file_system_context,
std::deque<FileSystemURL>* remaining_urls,
scoped_ptr<FileSystemURLQueue> remaining_urls,
const LocalFileSyncInfoCallback& callback,
SyncStatusCode status,
const LocalFileSyncInfo& sync_file_info,
Expand All @@ -821,7 +819,7 @@ void LocalFileSyncContext::DidTryPrepareForLocalSync(
return;
}
// Recursively call TryPrepareForLocalSync with remaining_urls.
TryPrepareForLocalSync(file_system_context, remaining_urls, callback);
TryPrepareForLocalSync(file_system_context, callback, remaining_urls.Pass());
}

void LocalFileSyncContext::DidGetWritingStatusForSync(
Expand Down
12 changes: 6 additions & 6 deletions chrome/browser/sync_file_system/local/local_file_sync_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class LocalFileSyncContext
private:
typedef base::Callback<void(base::File::Error result)> StatusCallback;
typedef std::deque<SyncStatusCallback> StatusCallbackQueue;
typedef std::deque<fileapi::FileSystemURL> FileSystemURLQueue;
friend class base::RefCountedThreadSafe<LocalFileSyncContext>;
friend class CannedSyncableFileSystem;

Expand Down Expand Up @@ -257,16 +258,15 @@ class LocalFileSyncContext
SyncStatusCode status);

// Helper routines for GetFileForLocalSync.
void GetNextURLsForSyncOnFileThread(
fileapi::FileSystemContext* file_system_context,
std::deque<fileapi::FileSystemURL>* urls);
scoped_ptr<FileSystemURLQueue> GetNextURLsForSyncOnFileThread(
fileapi::FileSystemContext* file_system_context);
void TryPrepareForLocalSync(
fileapi::FileSystemContext* file_system_context,
std::deque<fileapi::FileSystemURL>* urls,
const LocalFileSyncInfoCallback& callback);
const LocalFileSyncInfoCallback& callback,
scoped_ptr<FileSystemURLQueue> urls);
void DidTryPrepareForLocalSync(
fileapi::FileSystemContext* file_system_context,
std::deque<fileapi::FileSystemURL>* remaining_urls,
scoped_ptr<FileSystemURLQueue> remaining_urls,
const LocalFileSyncInfoCallback& callback,
SyncStatusCode status,
const LocalFileSyncInfo& sync_file_info,
Expand Down

0 comments on commit 15c7939

Please sign in to comment.