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

Side by Side Diff: chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.h" 5 #include "chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "chrome/browser/chromeos/drive/file_system_util.h" 9 #include "chrome/browser/chromeos/drive/file_system_util.h"
10 #include "chrome/browser/chromeos/drive/fileapi_worker.h" 10 #include "chrome/browser/chromeos/drive/fileapi_worker.h"
(...skipping 18 matching lines...) Expand all
29 29
30 BrowserThread::PostTask( 30 BrowserThread::PostTask(
31 BrowserThread::UI, 31 BrowserThread::UI,
32 FROM_HERE, 32 FROM_HERE,
33 base::Bind( 33 base::Bind(
34 &fileapi_internal::RunFileSystemCallback, 34 &fileapi_internal::RunFileSystemCallback,
35 file_system_getter, 35 file_system_getter,
36 base::Bind(&fileapi_internal::CreateWritableSnapshotFile, 36 base::Bind(&fileapi_internal::CreateWritableSnapshotFile,
37 drive_path, google_apis::CreateRelayCallback(callback)), 37 drive_path, google_apis::CreateRelayCallback(callback)),
38 google_apis::CreateRelayCallback(base::Bind( 38 google_apis::CreateRelayCallback(base::Bind(
39 callback, base::PLATFORM_FILE_ERROR_FAILED, base::FilePath(), 39 callback, base::File::FILE_ERROR_FAILED, base::FilePath(),
40 base::Closure())))); 40 base::Closure()))));
41 } 41 }
42 42
43 } // namespace 43 } // namespace
44 44
45 WebkitFileStreamWriterImpl::WebkitFileStreamWriterImpl( 45 WebkitFileStreamWriterImpl::WebkitFileStreamWriterImpl(
46 const FileSystemGetter& file_system_getter, 46 const FileSystemGetter& file_system_getter,
47 base::TaskRunner* file_task_runner, 47 base::TaskRunner* file_task_runner,
48 const base::FilePath& file_path, 48 const base::FilePath& file_path,
49 int64 offset) 49 int64 offset)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 // Here is the case Flush() is called before any Write() invocation. 126 // Here is the case Flush() is called before any Write() invocation.
127 // Do nothing. 127 // Do nothing.
128 // Synchronization to the remote server is not done until the file is closed. 128 // Synchronization to the remote server is not done until the file is closed.
129 return net::OK; 129 return net::OK;
130 } 130 }
131 131
132 void WebkitFileStreamWriterImpl::WriteAfterCreateWritableSnapshotFile( 132 void WebkitFileStreamWriterImpl::WriteAfterCreateWritableSnapshotFile(
133 net::IOBuffer* buf, 133 net::IOBuffer* buf,
134 int buf_len, 134 int buf_len,
135 base::PlatformFileError open_result, 135 base::File::Error open_result,
136 const base::FilePath& local_path, 136 const base::FilePath& local_path,
137 const base::Closure& close_callback_on_ui_thread) { 137 const base::Closure& close_callback_on_ui_thread) {
138 DCHECK(!local_file_writer_); 138 DCHECK(!local_file_writer_);
139 139
140 if (!pending_cancel_callback_.is_null()) { 140 if (!pending_cancel_callback_.is_null()) {
141 DCHECK(pending_write_callback_.is_null()); 141 DCHECK(pending_write_callback_.is_null());
142 // Cancel() is called during the creation of the snapshot file. 142 // Cancel() is called during the creation of the snapshot file.
143 // Don't write to the file. 143 // Don't write to the file.
144 if (open_result == base::PLATFORM_FILE_OK) { 144 if (open_result == base::File::FILE_OK) {
145 // Here the file is internally created. To revert the operation, close 145 // Here the file is internally created. To revert the operation, close
146 // the file. 146 // the file.
147 DCHECK(!close_callback_on_ui_thread.is_null()); 147 DCHECK(!close_callback_on_ui_thread.is_null());
148 BrowserThread::PostTask(BrowserThread::UI, 148 BrowserThread::PostTask(BrowserThread::UI,
149 FROM_HERE, 149 FROM_HERE,
150 close_callback_on_ui_thread); 150 close_callback_on_ui_thread);
151 } 151 }
152 152
153 base::ResetAndReturn(&pending_cancel_callback_).Run(net::OK); 153 base::ResetAndReturn(&pending_cancel_callback_).Run(net::OK);
154 return; 154 return;
155 } 155 }
156 156
157 DCHECK(!pending_write_callback_.is_null()); 157 DCHECK(!pending_write_callback_.is_null());
158 158
159 const net::CompletionCallback callback = 159 const net::CompletionCallback callback =
160 base::ResetAndReturn(&pending_write_callback_); 160 base::ResetAndReturn(&pending_write_callback_);
161 if (open_result != base::PLATFORM_FILE_OK) { 161 if (open_result != base::File::FILE_OK) {
162 DCHECK(close_callback_on_ui_thread.is_null()); 162 DCHECK(close_callback_on_ui_thread.is_null());
163 callback.Run(net::PlatformFileErrorToNetError(open_result)); 163 callback.Run(
164 net::FileErrorToNetError(open_result));
164 return; 165 return;
165 } 166 }
166 167
167 // Keep |close_callback| to close the file when the stream is destructed. 168 // Keep |close_callback| to close the file when the stream is destructed.
168 DCHECK(!close_callback_on_ui_thread.is_null()); 169 DCHECK(!close_callback_on_ui_thread.is_null());
169 close_callback_on_ui_thread_ = close_callback_on_ui_thread; 170 close_callback_on_ui_thread_ = close_callback_on_ui_thread;
170 local_file_writer_.reset(fileapi::FileStreamWriter::CreateForLocalFile( 171 local_file_writer_.reset(fileapi::FileStreamWriter::CreateForLocalFile(
171 file_task_runner_.get(), local_path, offset_)); 172 file_task_runner_.get(), local_path, offset_));
172 int result = local_file_writer_->Write(buf, buf_len, callback); 173 int result = local_file_writer_->Write(buf, buf_len, callback);
173 if (result != net::ERR_IO_PENDING) 174 if (result != net::ERR_IO_PENDING)
174 callback.Run(result); 175 callback.Run(result);
175 } 176 }
176 177
177 } // namespace internal 178 } // namespace internal
178 } // namespace drive 179 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698