[email protected] | 9f49afb | 2012-02-16 09:59:20 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 5 | #ifndef WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| 6 | #define WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 7 | |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | 9e629ab | 2011-10-20 22:03:43 | [diff] [blame] | 10 | #include "base/memory/weak_ptr.h" |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 11 | #include "base/platform_file.h" |
[email protected] | 0a8ebe1 | 2013-06-28 15:23:23 | [diff] [blame] | 12 | #include "base/time/time.h" |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 13 | #include "net/base/file_stream.h" |
| 14 | #include "net/base/io_buffer.h" |
| 15 | #include "net/url_request/url_request.h" |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 16 | #include "webkit/browser/webkit_storage_browser_export.h" |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 17 | |
| 18 | namespace fileapi { |
| 19 | |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 20 | class FileStreamWriter; |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 21 | |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 22 | class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE FileWriterDelegate |
[email protected] | 53a9741 | 2013-08-09 03:57:14 | [diff] [blame] | 23 | : public net::URLRequest::Delegate { |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 24 | public: |
[email protected] | ca47448 | 2012-09-26 11:21:21 | [diff] [blame] | 25 | enum WriteProgressStatus { |
| 26 | SUCCESS_IO_PENDING, |
| 27 | SUCCESS_COMPLETED, |
| 28 | ERROR_WRITE_STARTED, |
| 29 | ERROR_WRITE_NOT_STARTED, |
| 30 | }; |
| 31 | |
[email protected] | b9566e7c | 2012-10-29 10:57:46 | [diff] [blame] | 32 | typedef base::Callback<void(base::PlatformFileError result, |
| 33 | int64 bytes, |
| 34 | WriteProgressStatus write_status)> |
| 35 | DelegateWriteCallback; |
[email protected] | ca47448 | 2012-09-26 11:21:21 | [diff] [blame] | 36 | |
[email protected] | 7ba1627 | 2013-10-07 09:43:16 | [diff] [blame] | 37 | explicit FileWriterDelegate(scoped_ptr<FileStreamWriter> file_writer); |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 38 | virtual ~FileWriterDelegate(); |
| 39 | |
[email protected] | 1a6e390 | 2013-06-13 07:09:40 | [diff] [blame] | 40 | void Start(scoped_ptr<net::URLRequest> request, |
| 41 | const DelegateWriteCallback& write_callback); |
[email protected] | 8623b0f9 | 2012-05-11 05:31:09 | [diff] [blame] | 42 | |
[email protected] | 2c02c8d | 2013-06-10 17:52:43 | [diff] [blame] | 43 | // Cancels the current write operation. This will synchronously or |
| 44 | // asynchronously call the given write callback (which may result in |
| 45 | // deleting this). |
| 46 | void Cancel(); |
[email protected] | 8623b0f9 | 2012-05-11 05:31:09 | [diff] [blame] | 47 | |
[email protected] | e5624f0 | 2011-09-27 19:43:53 | [diff] [blame] | 48 | virtual void OnReceivedRedirect(net::URLRequest* request, |
| 49 | const GURL& new_url, |
| 50 | bool* defer_redirect) OVERRIDE; |
| 51 | virtual void OnAuthRequired(net::URLRequest* request, |
| 52 | net::AuthChallengeInfo* auth_info) OVERRIDE; |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 53 | virtual void OnCertificateRequested( |
[email protected] | e5624f0 | 2011-09-27 19:43:53 | [diff] [blame] | 54 | net::URLRequest* request, |
| 55 | net::SSLCertRequestInfo* cert_request_info) OVERRIDE; |
| 56 | virtual void OnSSLCertificateError(net::URLRequest* request, |
| 57 | const net::SSLInfo& ssl_info, |
[email protected] | 46d117e | 2012-01-18 01:53:14 | [diff] [blame] | 58 | bool fatal) OVERRIDE; |
[email protected] | e5624f0 | 2011-09-27 19:43:53 | [diff] [blame] | 59 | virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
| 60 | virtual void OnReadCompleted(net::URLRequest* request, |
| 61 | int bytes_read) OVERRIDE; |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 62 | |
| 63 | private: |
[email protected] | 8623b0f9 | 2012-05-11 05:31:09 | [diff] [blame] | 64 | void OnGetFileInfoAndStartRequest( |
| 65 | scoped_ptr<net::URLRequest> request, |
[email protected] | 078c6971a | 2011-04-21 05:04:51 | [diff] [blame] | 66 | base::PlatformFileError error, |
[email protected] | e5006b9 | 2011-05-17 11:53:51 | [diff] [blame] | 67 | const base::PlatformFileInfo& file_info); |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 68 | void Read(); |
| 69 | void OnDataReceived(int bytes_read); |
| 70 | void Write(); |
| 71 | void OnDataWritten(int write_response); |
| 72 | void OnError(base::PlatformFileError error); |
| 73 | void OnProgress(int bytes_read, bool done); |
[email protected] | 397a1f4d | 2012-05-22 09:19:31 | [diff] [blame] | 74 | void OnWriteCancelled(int status); |
[email protected] | a95ce076 | 2012-10-01 05:54:26 | [diff] [blame] | 75 | void FlushForCompletion(base::PlatformFileError error, |
| 76 | int bytes_written, |
| 77 | WriteProgressStatus progress_status); |
| 78 | void OnFlushed(base::PlatformFileError error, |
| 79 | int bytes_written, |
| 80 | WriteProgressStatus progress_status, |
| 81 | int flush_error); |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 82 | |
[email protected] | ca47448 | 2012-09-26 11:21:21 | [diff] [blame] | 83 | WriteProgressStatus GetCompletionStatusOnError() const; |
[email protected] | e5006b9 | 2011-05-17 11:53:51 | [diff] [blame] | 84 | |
[email protected] | ca47448 | 2012-09-26 11:21:21 | [diff] [blame] | 85 | DelegateWriteCallback write_callback_; |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 86 | scoped_ptr<FileStreamWriter> file_stream_writer_; |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 87 | base::Time last_progress_event_time_; |
[email protected] | ca47448 | 2012-09-26 11:21:21 | [diff] [blame] | 88 | bool writing_started_; |
[email protected] | 8bf65df | 2011-05-27 07:26:15 | [diff] [blame] | 89 | int bytes_written_backlog_; |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 90 | int bytes_written_; |
| 91 | int bytes_read_; |
| 92 | scoped_refptr<net::IOBufferWithSize> io_buffer_; |
[email protected] | 9f49afb | 2012-02-16 09:59:20 | [diff] [blame] | 93 | scoped_refptr<net::DrainableIOBuffer> cursor_; |
[email protected] | 8623b0f9 | 2012-05-11 05:31:09 | [diff] [blame] | 94 | scoped_ptr<net::URLRequest> request_; |
[email protected] | 53a9741 | 2013-08-09 03:57:14 | [diff] [blame] | 95 | |
| 96 | base::WeakPtrFactory<FileWriterDelegate> weak_factory_; |
| 97 | |
| 98 | DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); |
[email protected] | bd15238 | 2010-10-07 23:24:38 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | } // namespace fileapi |
| 102 | |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 103 | #endif // WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ |