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

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
« no previous file with comments | « chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.h ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..33633408e4ed335d1ad0d37a7ae898c928c3820a 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,10 @@ 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();
- CloseFile(file_system_getter_, file_path_);
+ DCHECK(!close_callback_on_ui_thread_.is_null());
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ close_callback_on_ui_thread_);
}
}
@@ -146,7 +134,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& close_callback_on_ui_thread) {
DCHECK(!local_file_writer_);
if (!pending_cancel_callback_.is_null()) {
@@ -156,8 +145,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(!close_callback_on_ui_thread.is_null());
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ close_callback_on_ui_thread);
}
base::ResetAndReturn(&pending_cancel_callback_).Run(net::OK);
@@ -169,10 +160,14 @@ void WebkitFileStreamWriterImpl::WriteAfterCreateWritableSnapshotFile(
const net::CompletionCallback callback =
base::ResetAndReturn(&pending_write_callback_);
if (open_result != base::PLATFORM_FILE_OK) {
+ DCHECK(close_callback_on_ui_thread.is_null());
callback.Run(net::PlatformFileErrorToNetError(open_result));
return;
}
+ // Keep |close_callback| to close the file when the stream is destructed.
+ DCHECK(!close_callback_on_ui_thread.is_null());
+ close_callback_on_ui_thread_ = close_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);
« no previous file with comments | « chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.h ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698