| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| 6 #define WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ | 6 #define WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "net/base/file_stream.h" | 13 #include "net/base/file_stream.h" |
| 14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
| 15 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
| 16 #include "webkit/fileapi/fileapi_export.h" | 16 #include "webkit/fileapi/fileapi_export.h" |
| 17 #include "webkit/fileapi/file_system_operation.h" | 17 #include "webkit/fileapi/file_system_operation.h" |
| 18 | 18 |
| 19 namespace fileapi { | 19 namespace fileapi { |
| 20 | 20 |
| 21 class FileStreamWriter; | 21 class FileStreamWriter; |
| 22 class FileSystemOperationContext; | 22 class FileSystemOperationContext; |
| 23 class FileSystemQuotaUtil; | 23 class FileSystemQuotaUtil; |
| 24 | 24 |
| 25 class FILEAPI_EXPORT_PRIVATE FileWriterDelegate | 25 class FILEAPI_EXPORT_PRIVATE FileWriterDelegate |
| 26 : public net::URLRequest::Delegate { | 26 : public net::URLRequest::Delegate { |
| 27 public: | 27 public: |
| 28 enum WriteProgressStatus { |
| 29 SUCCESS_IO_PENDING, |
| 30 SUCCESS_COMPLETED, |
| 31 ERROR_WRITE_STARTED, |
| 32 ERROR_WRITE_NOT_STARTED, |
| 33 }; |
| 34 |
| 35 typedef base::Callback<void( |
| 36 base::PlatformFileError result, |
| 37 int64 bytes, |
| 38 WriteProgressStatus write_status)> DelegateWriteCallback; |
| 39 |
| 28 FileWriterDelegate( | 40 FileWriterDelegate( |
| 29 const FileSystemOperation::WriteCallback& write_callback, | 41 const DelegateWriteCallback& write_callback, |
| 30 scoped_ptr<FileStreamWriter> file_writer); | 42 scoped_ptr<FileStreamWriter> file_writer); |
| 31 virtual ~FileWriterDelegate(); | 43 virtual ~FileWriterDelegate(); |
| 32 | 44 |
| 33 void Start(scoped_ptr<net::URLRequest> request); | 45 void Start(scoped_ptr<net::URLRequest> request); |
| 34 | 46 |
| 35 // Cancels the current write operation. Returns true if it is ok to | 47 // Cancels the current write operation. Returns true if it is ok to |
| 36 // delete this instance immediately. Otherwise this will call | 48 // delete this instance immediately. Otherwise this will call |
| 37 // |write_operation|->DidWrite() with complete=true to let the operation | 49 // |write_operation|->DidWrite() with complete=true to let the operation |
| 38 // perform the final cleanup. | 50 // perform the final cleanup. |
| 39 bool Cancel(); | 51 bool Cancel(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 60 const base::PlatformFileInfo& file_info); | 72 const base::PlatformFileInfo& file_info); |
| 61 void Read(); | 73 void Read(); |
| 62 void OnDataReceived(int bytes_read); | 74 void OnDataReceived(int bytes_read); |
| 63 void Write(); | 75 void Write(); |
| 64 void OnDataWritten(int write_response); | 76 void OnDataWritten(int write_response); |
| 65 void OnError(base::PlatformFileError error); | 77 void OnError(base::PlatformFileError error); |
| 66 void OnProgress(int bytes_read, bool done); | 78 void OnProgress(int bytes_read, bool done); |
| 67 void OnWriteCancelled(int status); | 79 void OnWriteCancelled(int status); |
| 68 | 80 |
| 69 FileSystemQuotaUtil* quota_util() const; | 81 FileSystemQuotaUtil* quota_util() const; |
| 82 WriteProgressStatus GetCompletionStatusOnError() const; |
| 70 | 83 |
| 71 FileSystemOperation::WriteCallback write_callback_; | 84 DelegateWriteCallback write_callback_; |
| 72 scoped_ptr<FileStreamWriter> file_stream_writer_; | 85 scoped_ptr<FileStreamWriter> file_stream_writer_; |
| 73 base::Time last_progress_event_time_; | 86 base::Time last_progress_event_time_; |
| 87 bool writing_started_; |
| 74 int bytes_written_backlog_; | 88 int bytes_written_backlog_; |
| 75 int bytes_written_; | 89 int bytes_written_; |
| 76 int bytes_read_; | 90 int bytes_read_; |
| 77 scoped_refptr<net::IOBufferWithSize> io_buffer_; | 91 scoped_refptr<net::IOBufferWithSize> io_buffer_; |
| 78 scoped_refptr<net::DrainableIOBuffer> cursor_; | 92 scoped_refptr<net::DrainableIOBuffer> cursor_; |
| 79 scoped_ptr<net::URLRequest> request_; | 93 scoped_ptr<net::URLRequest> request_; |
| 80 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; | 94 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; |
| 81 }; | 95 }; |
| 82 | 96 |
| 83 } // namespace fileapi | 97 } // namespace fileapi |
| 84 | 98 |
| 85 #endif // WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ | 99 #endif // WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| OLD | NEW |