This source file includes following definitions.
- RunCloseCallbackAndReplyTask
- WriteOnCacheFileAfterOpenFile
- WriteOnCacheFile
- WriteOnCacheFileAndReply
#include "chrome/browser/chromeos/drive/write_on_cache_file.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chromeos/drive/file_system_interface.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
namespace drive {
namespace {
void RunCloseCallbackAndReplyTask(const base::Closure& close_callback,
const FileOperationCallback& reply,
FileError error) {
if (!close_callback.is_null())
close_callback.Run();
DCHECK(!reply.is_null());
reply.Run(error);
}
void WriteOnCacheFileAfterOpenFile(
const base::FilePath& drive_path,
const WriteOnCacheFileCallback& file_io_task_callback,
const FileOperationCallback& reply,
FileError error,
const base::FilePath& local_cache_path,
const base::Closure& close_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::GetBlockingPool()->PostTaskAndReply(
FROM_HERE,
base::Bind(file_io_task_callback, error, local_cache_path),
base::Bind(&RunCloseCallbackAndReplyTask, close_callback, reply, error));
}
}
void WriteOnCacheFile(FileSystemInterface* file_system,
const base::FilePath& path,
const std::string& mime_type,
const WriteOnCacheFileCallback& callback) {
WriteOnCacheFileAndReply(file_system, path, mime_type, callback,
base::Bind(&util::EmptyFileOperationCallback));
}
void WriteOnCacheFileAndReply(FileSystemInterface* file_system,
const base::FilePath& path,
const std::string& mime_type,
const WriteOnCacheFileCallback& callback,
const FileOperationCallback& reply) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(file_system);
DCHECK(!callback.is_null());
DCHECK(!reply.is_null());
file_system->OpenFile(
path,
OPEN_OR_CREATE_FILE,
mime_type,
base::Bind(&WriteOnCacheFileAfterOpenFile, path, callback, reply));
}
}