Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1998)

Unified Diff: chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.cc

Issue 19596003: Remove CloseFile from FileSystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.cc
diff --git a/chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.cc b/chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.cc
index 94e8e80df20d3a5a9cd75f7e9c9ea9babcf676f2..a01edbac5bf4d48c0aacdbf579de839b1f009dc7 100644
--- a/chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.cc
+++ b/chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.cc
@@ -37,23 +37,8 @@ void CreateWritableSnapshotFile(
base::Bind(&fileapi_internal::CreateWritableSnapshotFile,
drive_path, google_apis::CreateRelayCallback(callback)),
google_apis::CreateRelayCallback(base::Bind(
- callback, base::PLATFORM_FILE_ERROR_FAILED, base::FilePath()))));
-}
-
-// Closes the writable snapshot file opened by CreateWritableSnapshotFile.
-// TODO(hidehiko): Get rid of this function. crbug.com/259184.
-void CloseFile(
- const WebkitFileStreamWriterImpl::FileSystemGetter& file_system_getter,
- const base::FilePath& drive_path) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- base::Bind(&fileapi_internal::RunFileSystemCallback,
- file_system_getter,
- base::Bind(&fileapi_internal::CloseFile, drive_path),
- base::Closure()));
+ callback, base::PLATFORM_FILE_ERROR_FAILED, base::FilePath(),
+ base::Closure()))));
}
} // namespace
@@ -75,7 +60,9 @@ WebkitFileStreamWriterImpl::~WebkitFileStreamWriterImpl() {
// If the file is opened, close it at destructor.
// It is necessary to close the local file in advance.
local_file_writer_.reset();
hashimoto 2013/07/23 11:24:58 nit: How about DCHECK(on_close_file_callback_on_ui
hidehiko 2013/07/23 14:32:24 Done.
- CloseFile(file_system_getter_, file_path_);
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ on_close_file_callback_on_ui_thread_);
}
}
@@ -146,7 +133,8 @@ void WebkitFileStreamWriterImpl::WriteAfterCreateWritableSnapshotFile(
net::IOBuffer* buf,
int buf_len,
base::PlatformFileError open_result,
- const base::FilePath& local_path) {
+ const base::FilePath& local_path,
+ const base::Closure& on_close_file_callback_on_ui_thread) {
DCHECK(!local_file_writer_);
if (!pending_cancel_callback_.is_null()) {
@@ -156,8 +144,10 @@ void WebkitFileStreamWriterImpl::WriteAfterCreateWritableSnapshotFile(
if (open_result == base::PLATFORM_FILE_OK) {
// Here the file is internally created. To revert the operation, close
// the file.
- DCHECK(!local_path.empty());
- CloseFile(file_system_getter_, file_path_);
+ DCHECK(!on_close_file_callback_on_ui_thread.is_null());
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ on_close_file_callback_on_ui_thread);
}
base::ResetAndReturn(&pending_cancel_callback_).Run(net::OK);
@@ -169,10 +159,14 @@ void WebkitFileStreamWriterImpl::WriteAfterCreateWritableSnapshotFile(
const net::CompletionCallback callback =
base::ResetAndReturn(&pending_write_callback_);
if (open_result != base::PLATFORM_FILE_OK) {
+ DCHECK(on_close_file_callback_on_ui_thread.is_null());
callback.Run(net::PlatformFileErrorToNetError(open_result));
return;
}
+ // Keep |on_close_callback| to close the file when the stream is destructed.
+ DCHECK(!on_close_file_callback_on_ui_thread.is_null());
+ on_close_file_callback_on_ui_thread_ = on_close_file_callback_on_ui_thread;
local_file_writer_.reset(new fileapi::LocalFileStreamWriter(
file_task_runner_.get(), local_path, offset_));
int result = local_file_writer_->Write(buf, buf_len, callback);

Powered by Google App Engine
This is Rietveld 408576698