scoped_ptr<LocalFileSyncService> LocalFileSyncService::Create(
Profile* profile) {
- return make_scoped_ptr(new LocalFileSyncService(profile, NULL));
+ return make_scoped_ptr(new LocalFileSyncService(profile, nullptr));
}
scoped_ptr<LocalFileSyncService> LocalFileSyncService::CreateForTesting(
void LocalFileSyncService::Shutdown() {
sync_context_->RemoveOriginChangeObserver(this);
sync_context_->ShutdownOnUIThread();
- profile_ = NULL;
+ profile_ = nullptr;
}
void LocalFileSyncService::MaybeInitializeFileSystemContext(
callback.Run(SYNC_STATUS_NO_CHANGE_TO_SYNC, FileSystemURL());
return;
}
- DCHECK(local_sync_callback_.is_null());
DCHECK(!origin.is_empty());
DCHECK(ContainsKey(origin_to_contexts_, origin));
DVLOG(1) << "Starting ProcessLocalChange";
- local_sync_callback_ = callback;
-
sync_context_->GetFileForLocalSync(
origin_to_contexts_[origin],
base::Bind(&LocalFileSyncService::DidGetFileForLocalSync,
- AsWeakPtr()));
+ AsWeakPtr(), callback));
}
void LocalFileSyncService::SetLocalChangeProcessor(
base::Closure completion_callback =
base::Bind(&InvokeCallbackOnNthInvocation,
- base::Owned(new int(origin_to_contexts_.size())), callback);
+ base::Owned(new int(origin_to_contexts_.size() + 1)),
+ callback);
for (OriginToContext::iterator iter = origin_to_contexts_.begin();
iter != origin_to_contexts_.end(); ++iter)
sync_context_->PromoteDemotedChanges(iter->first, iter->second,
completion_callback);
+ completion_callback.Run();
}
void LocalFileSyncService::GetLocalFileMetadata(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get(),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)
.get())),
- local_change_processor_(NULL) {
+ local_change_processor_(nullptr) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
sync_context_->AddOriginChangeObserver(this);
}
PrepareForProcessRemoteChange(url, callback);
}
-void LocalFileSyncService::RunLocalSyncCallback(
- SyncStatusCode status,
- const FileSystemURL& url) {
- DVLOG(1) << "Local sync is finished with: " << status
- << " on " << url.DebugString();
- DCHECK(!local_sync_callback_.is_null());
- SyncFileCallback callback = local_sync_callback_;
- local_sync_callback_.Reset();
- callback.Run(status, url);
-}
-
void LocalFileSyncService::DidApplyRemoteChange(
const SyncStatusCallback& callback,
SyncStatusCode status) {
}
void LocalFileSyncService::DidGetFileForLocalSync(
+ const SyncFileCallback& callback,
SyncStatusCode status,
const LocalFileSyncInfo& sync_file_info,
storage::ScopedFile snapshot) {
- DCHECK(!local_sync_callback_.is_null());
if (status != SYNC_STATUS_OK) {
- RunLocalSyncCallback(status, sync_file_info.url);
+ callback.Run(status, sync_file_info.url);
return;
}
if (sync_file_info.changes.empty()) {
// There's a slight chance this could happen.
- SyncFileCallback callback = local_sync_callback_;
- local_sync_callback_.Reset();
ProcessLocalChange(callback);
return;
}
sync_file_info.metadata,
sync_file_info.url,
base::Bind(&LocalFileSyncService::ProcessNextChangeForURL,
- AsWeakPtr(), base::Passed(&snapshot), sync_file_info,
+ AsWeakPtr(), callback,
+ base::Passed(&snapshot), sync_file_info,
next_change, sync_file_info.changes.PopAndGetNewList()));
}
void LocalFileSyncService::ProcessNextChangeForURL(
+ const SyncFileCallback& callback,
storage::ScopedFile snapshot,
const LocalFileSyncInfo& sync_file_info,
const FileChange& processed_change,
sync_file_info.metadata,
sync_file_info.url,
base::Bind(&LocalFileSyncService::ProcessNextChangeForURL,
- AsWeakPtr(), base::Passed(&snapshot),
+ AsWeakPtr(), callback, base::Passed(&snapshot),
sync_file_info, processed_change, changes));
return;
}
DCHECK(ContainsKey(origin_to_contexts_, url.origin()));
sync_context_->FinalizeSnapshotSync(
origin_to_contexts_[url.origin()], url, status,
- base::Bind(&LocalFileSyncService::RunLocalSyncCallback,
- AsWeakPtr(), status, url));
+ base::Bind(callback, status, url));
return;
}
sync_file_info.metadata,
url,
base::Bind(&LocalFileSyncService::ProcessNextChangeForURL,
- AsWeakPtr(), base::Passed(&snapshot), sync_file_info,
+ AsWeakPtr(), callback,
+ base::Passed(&snapshot), sync_file_info,
next_change, changes.PopAndGetNewList()));
}