| 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_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| 7 | 7 |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/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/browser/webkit_storage_browser_export.h" | 16 #include "webkit/browser/webkit_storage_browser_export.h" |
| 17 | 17 |
| 18 namespace fileapi { | 18 namespace fileapi { |
| 19 | 19 |
| 20 class FileStreamWriter; | 20 class FileStreamWriter; |
| 21 | 21 |
| 22 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE FileWriterDelegate | 22 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE FileWriterDelegate |
| 23 : public net::URLRequest::Delegate { | 23 : public net::URLRequest::Delegate { |
| 24 public: | 24 public: |
| 25 enum FlushPolicy { |
| 26 FLUSH_ON_COMPLETION, |
| 27 NO_FLUSH_ON_COMPLETION, |
| 28 }; |
| 29 |
| 25 enum WriteProgressStatus { | 30 enum WriteProgressStatus { |
| 26 SUCCESS_IO_PENDING, | 31 SUCCESS_IO_PENDING, |
| 27 SUCCESS_COMPLETED, | 32 SUCCESS_COMPLETED, |
| 28 ERROR_WRITE_STARTED, | 33 ERROR_WRITE_STARTED, |
| 29 ERROR_WRITE_NOT_STARTED, | 34 ERROR_WRITE_NOT_STARTED, |
| 30 }; | 35 }; |
| 31 | 36 |
| 32 typedef base::Callback<void(base::File::Error result, | 37 typedef base::Callback<void(base::File::Error result, |
| 33 int64 bytes, | 38 int64 bytes, |
| 34 WriteProgressStatus write_status)> | 39 WriteProgressStatus write_status)> |
| 35 DelegateWriteCallback; | 40 DelegateWriteCallback; |
| 36 | 41 |
| 37 explicit FileWriterDelegate(scoped_ptr<FileStreamWriter> file_writer); | 42 FileWriterDelegate(scoped_ptr<FileStreamWriter> file_writer, |
| 43 FlushPolicy flush_policy); |
| 38 virtual ~FileWriterDelegate(); | 44 virtual ~FileWriterDelegate(); |
| 39 | 45 |
| 40 void Start(scoped_ptr<net::URLRequest> request, | 46 void Start(scoped_ptr<net::URLRequest> request, |
| 41 const DelegateWriteCallback& write_callback); | 47 const DelegateWriteCallback& write_callback); |
| 42 | 48 |
| 43 // Cancels the current write operation. This will synchronously or | 49 // Cancels the current write operation. This will synchronously or |
| 44 // asynchronously call the given write callback (which may result in | 50 // asynchronously call the given write callback (which may result in |
| 45 // deleting this). | 51 // deleting this). |
| 46 void Cancel(); | 52 void Cancel(); |
| 47 | 53 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 65 scoped_ptr<net::URLRequest> request, | 71 scoped_ptr<net::URLRequest> request, |
| 66 base::File::Error error, | 72 base::File::Error error, |
| 67 const base::File::Info& file_info); | 73 const base::File::Info& file_info); |
| 68 void Read(); | 74 void Read(); |
| 69 void OnDataReceived(int bytes_read); | 75 void OnDataReceived(int bytes_read); |
| 70 void Write(); | 76 void Write(); |
| 71 void OnDataWritten(int write_response); | 77 void OnDataWritten(int write_response); |
| 72 void OnError(base::File::Error error); | 78 void OnError(base::File::Error error); |
| 73 void OnProgress(int bytes_read, bool done); | 79 void OnProgress(int bytes_read, bool done); |
| 74 void OnWriteCancelled(int status); | 80 void OnWriteCancelled(int status); |
| 75 void FlushForCompletion(base::File::Error error, | 81 void MaybeFlushForCompletion(base::File::Error error, |
| 76 int bytes_written, | 82 int bytes_written, |
| 77 WriteProgressStatus progress_status); | 83 WriteProgressStatus progress_status); |
| 78 void OnFlushed(base::File::Error error, | 84 void OnFlushed(base::File::Error error, |
| 79 int bytes_written, | 85 int bytes_written, |
| 80 WriteProgressStatus progress_status, | 86 WriteProgressStatus progress_status, |
| 81 int flush_error); | 87 int flush_error); |
| 82 | 88 |
| 83 WriteProgressStatus GetCompletionStatusOnError() const; | 89 WriteProgressStatus GetCompletionStatusOnError() const; |
| 84 | 90 |
| 85 DelegateWriteCallback write_callback_; | 91 DelegateWriteCallback write_callback_; |
| 86 scoped_ptr<FileStreamWriter> file_stream_writer_; | 92 scoped_ptr<FileStreamWriter> file_stream_writer_; |
| 87 base::Time last_progress_event_time_; | 93 base::Time last_progress_event_time_; |
| 88 bool writing_started_; | 94 bool writing_started_; |
| 95 FlushPolicy flush_policy_; |
| 89 int bytes_written_backlog_; | 96 int bytes_written_backlog_; |
| 90 int bytes_written_; | 97 int bytes_written_; |
| 91 int bytes_read_; | 98 int bytes_read_; |
| 92 scoped_refptr<net::IOBufferWithSize> io_buffer_; | 99 scoped_refptr<net::IOBufferWithSize> io_buffer_; |
| 93 scoped_refptr<net::DrainableIOBuffer> cursor_; | 100 scoped_refptr<net::DrainableIOBuffer> cursor_; |
| 94 scoped_ptr<net::URLRequest> request_; | 101 scoped_ptr<net::URLRequest> request_; |
| 95 | 102 |
| 96 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; | 103 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; |
| 97 | 104 |
| 98 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); | 105 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); |
| 99 }; | 106 }; |
| 100 | 107 |
| 101 } // namespace fileapi | 108 } // namespace fileapi |
| 102 | 109 |
| 103 #endif // WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ | 110 #endif // WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| OLD | NEW |