OLD | NEW |
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 "webkit/browser/fileapi/file_system_operation_impl.h" | 5 #include "webkit/browser/fileapi/file_system_operation_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 DCHECK(SetPendingOperationType(kOperationTouchFile)); | 192 DCHECK(SetPendingOperationType(kOperationTouchFile)); |
193 async_file_util_->Touch( | 193 async_file_util_->Touch( |
194 operation_context_.Pass(), url, | 194 operation_context_.Pass(), url, |
195 last_access_time, last_modified_time, | 195 last_access_time, last_modified_time, |
196 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 196 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
197 weak_factory_.GetWeakPtr(), callback)); | 197 weak_factory_.GetWeakPtr(), callback)); |
198 } | 198 } |
199 | 199 |
200 void FileSystemOperationImpl::OpenFile(const FileSystemURL& url, | 200 void FileSystemOperationImpl::OpenFile(const FileSystemURL& url, |
201 int file_flags, | 201 int file_flags, |
202 base::ProcessHandle peer_handle, | |
203 const OpenFileCallback& callback) { | 202 const OpenFileCallback& callback) { |
204 DCHECK(SetPendingOperationType(kOperationOpenFile)); | 203 DCHECK(SetPendingOperationType(kOperationOpenFile)); |
205 peer_handle_ = peer_handle; | |
206 | 204 |
207 if (file_flags & | 205 if (file_flags & |
208 (base::PLATFORM_FILE_TEMPORARY | base::PLATFORM_FILE_HIDDEN)) { | 206 (base::PLATFORM_FILE_TEMPORARY | base::PLATFORM_FILE_HIDDEN)) { |
209 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, | 207 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, |
210 base::kInvalidPlatformFileValue, | 208 base::kInvalidPlatformFileValue, |
211 base::Closure(), | 209 base::Closure()); |
212 base::kNullProcessHandle); | |
213 return; | 210 return; |
214 } | 211 } |
215 GetUsageAndQuotaThenRunTask( | 212 GetUsageAndQuotaThenRunTask( |
216 url, | 213 url, |
217 base::Bind(&FileSystemOperationImpl::DoOpenFile, | 214 base::Bind(&FileSystemOperationImpl::DoOpenFile, |
218 weak_factory_.GetWeakPtr(), | 215 weak_factory_.GetWeakPtr(), |
219 url, callback, file_flags), | 216 url, callback, file_flags), |
220 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, | 217 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, |
221 base::kInvalidPlatformFileValue, | 218 base::kInvalidPlatformFileValue, |
222 base::Closure(), | 219 base::Closure())); |
223 base::kNullProcessHandle)); | |
224 } | 220 } |
225 | 221 |
226 // We can only get here on a write or truncate that's not yet completed. | 222 // We can only get here on a write or truncate that's not yet completed. |
227 // We don't support cancelling any other operation at this time. | 223 // We don't support cancelling any other operation at this time. |
228 void FileSystemOperationImpl::Cancel(const StatusCallback& cancel_callback) { | 224 void FileSystemOperationImpl::Cancel(const StatusCallback& cancel_callback) { |
229 DCHECK(cancel_callback_.is_null()); | 225 DCHECK(cancel_callback_.is_null()); |
230 cancel_callback_ = cancel_callback; | 226 cancel_callback_ = cancel_callback; |
231 | 227 |
232 if (file_writer_delegate_.get()) { | 228 if (file_writer_delegate_.get()) { |
233 DCHECK_EQ(kOperationWrite, pending_operation_); | 229 DCHECK_EQ(kOperationWrite, pending_operation_); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 return base::PLATFORM_FILE_OK; | 324 return base::PLATFORM_FILE_OK; |
329 } | 325 } |
330 | 326 |
331 FileSystemOperationImpl::FileSystemOperationImpl( | 327 FileSystemOperationImpl::FileSystemOperationImpl( |
332 const FileSystemURL& url, | 328 const FileSystemURL& url, |
333 FileSystemContext* file_system_context, | 329 FileSystemContext* file_system_context, |
334 scoped_ptr<FileSystemOperationContext> operation_context) | 330 scoped_ptr<FileSystemOperationContext> operation_context) |
335 : file_system_context_(file_system_context), | 331 : file_system_context_(file_system_context), |
336 operation_context_(operation_context.Pass()), | 332 operation_context_(operation_context.Pass()), |
337 async_file_util_(NULL), | 333 async_file_util_(NULL), |
338 peer_handle_(base::kNullProcessHandle), | |
339 pending_operation_(kOperationNone), | 334 pending_operation_(kOperationNone), |
340 weak_factory_(this) { | 335 weak_factory_(this) { |
341 DCHECK(operation_context_.get()); | 336 DCHECK(operation_context_.get()); |
342 operation_context_->DetachUserDataThread(); | 337 operation_context_->DetachUserDataThread(); |
343 async_file_util_ = file_system_context_->GetAsyncFileUtil(url.type()); | 338 async_file_util_ = file_system_context_->GetAsyncFileUtil(url.type()); |
344 DCHECK(async_file_util_); | 339 DCHECK(async_file_util_); |
345 } | 340 } |
346 | 341 |
347 void FileSystemOperationImpl::GetUsageAndQuotaThenRunTask( | 342 void FileSystemOperationImpl::GetUsageAndQuotaThenRunTask( |
348 const FileSystemURL& url, | 343 const FileSystemURL& url, |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 write_callback.Run(rv, bytes, complete); | 541 write_callback.Run(rv, bytes, complete); |
547 if (!cancel_callback.is_null()) | 542 if (!cancel_callback.is_null()) |
548 cancel_callback.Run(base::PLATFORM_FILE_OK); | 543 cancel_callback.Run(base::PLATFORM_FILE_OK); |
549 } | 544 } |
550 | 545 |
551 void FileSystemOperationImpl::DidOpenFile( | 546 void FileSystemOperationImpl::DidOpenFile( |
552 const OpenFileCallback& callback, | 547 const OpenFileCallback& callback, |
553 base::PlatformFileError rv, | 548 base::PlatformFileError rv, |
554 base::PassPlatformFile file, | 549 base::PassPlatformFile file, |
555 const base::Closure& on_close_callback) { | 550 const base::Closure& on_close_callback) { |
556 if (rv == base::PLATFORM_FILE_OK) | 551 callback.Run(rv, file.ReleaseValue(), on_close_callback); |
557 CHECK_NE(base::kNullProcessHandle, peer_handle_); | |
558 callback.Run(rv, file.ReleaseValue(), on_close_callback, peer_handle_); | |
559 } | 552 } |
560 | 553 |
561 bool FileSystemOperationImpl::SetPendingOperationType(OperationType type) { | 554 bool FileSystemOperationImpl::SetPendingOperationType(OperationType type) { |
562 if (pending_operation_ != kOperationNone) | 555 if (pending_operation_ != kOperationNone) |
563 return false; | 556 return false; |
564 pending_operation_ = type; | 557 pending_operation_ = type; |
565 return true; | 558 return true; |
566 } | 559 } |
567 | 560 |
568 } // namespace fileapi | 561 } // namespace fileapi |
OLD | NEW |