Skip to content

Instantly share code, notes, and snippets.

@oyiptong
Created July 2, 2019 09:11
Show Gist options
  • Save oyiptong/b2c43907bab0af0280ddd6eab0128d75 to your computer and use it in GitHub Desktop.
Save oyiptong/b2c43907bab0af0280ddd6eab0128d75 to your computer and use it in GitHub Desktop.
Curring a lambda
// -- snip --
manager()->CreateSwapFileForURL(
url(),
base::BindOnce([](CreateFileWriterCallback callback) {
base::File::Error result,
const storage::FileSystemURL& swap_url) {
// Canned answer for now.
std::move(callback).Run(
NativeFileSystemError::New(base::File::FILE_OK),
nullptr);
}, std::move(callback)));
// -- snip --
// -- snip --
template <typename CallbackArgType>
void NativeFileSystemManagerImpl::CreateSwapFileForURL(
const storage::FileSystemURL& url,
base::OnceCallback<void(CallbackArgType)> callback) {
base::FilePath swap_path = base::GetUniquePath(
base::FilePath(url.path()).AddExtensionASCII(".crswap"));
auto url_and_handle = CreateFileSystemURLFromPath(url.origin(), swap_path);
auto swap_url = url_and_handle.url;
operation_runner()->CreateFile(
swap_url,
/*exclusive*/true,
base::BindOnce(&NativeFileSystemManagerImpl::DidCreateSwapFile,
weak_factory_.GetWeakPtr(),
std::move(swap_url),
std::move(callback)));
}
template <typename CallbackArgType>
void NativeFileSystemManagerImpl::DidCreateSwapFile(
const storage::FileSystemURL& swap_url,
base::OnceCallback<void(CallbackArgType)> callback,
base::File::Error result) {
std::move(callback).Run(std::move(result), std::move(swap_url));
}
// -- snip --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment