| 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_path.h" | 9 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "base/platform_file.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 WriteProgressStatus { | 25 enum WriteProgressStatus { |
| 26 SUCCESS_IO_PENDING, | 26 SUCCESS_IO_PENDING, |
| 27 SUCCESS_COMPLETED, | 27 SUCCESS_COMPLETED, |
| 28 ERROR_WRITE_STARTED, | 28 ERROR_WRITE_STARTED, |
| 29 ERROR_WRITE_NOT_STARTED, | 29 ERROR_WRITE_NOT_STARTED, |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 typedef base::Callback<void(base::PlatformFileError result, | 32 typedef base::Callback<void(base::File::Error result, |
| 33 int64 bytes, | 33 int64 bytes, |
| 34 WriteProgressStatus write_status)> | 34 WriteProgressStatus write_status)> |
| 35 DelegateWriteCallback; | 35 DelegateWriteCallback; |
| 36 | 36 |
| 37 explicit FileWriterDelegate(scoped_ptr<FileStreamWriter> file_writer); | 37 explicit FileWriterDelegate(scoped_ptr<FileStreamWriter> file_writer); |
| 38 virtual ~FileWriterDelegate(); | 38 virtual ~FileWriterDelegate(); |
| 39 | 39 |
| 40 void Start(scoped_ptr<net::URLRequest> request, | 40 void Start(scoped_ptr<net::URLRequest> request, |
| 41 const DelegateWriteCallback& write_callback); | 41 const DelegateWriteCallback& write_callback); |
| 42 | 42 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 56 virtual void OnSSLCertificateError(net::URLRequest* request, | 56 virtual void OnSSLCertificateError(net::URLRequest* request, |
| 57 const net::SSLInfo& ssl_info, | 57 const net::SSLInfo& ssl_info, |
| 58 bool fatal) OVERRIDE; | 58 bool fatal) OVERRIDE; |
| 59 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; | 59 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
| 60 virtual void OnReadCompleted(net::URLRequest* request, | 60 virtual void OnReadCompleted(net::URLRequest* request, |
| 61 int bytes_read) OVERRIDE; | 61 int bytes_read) OVERRIDE; |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 void OnGetFileInfoAndStartRequest( | 64 void OnGetFileInfoAndStartRequest( |
| 65 scoped_ptr<net::URLRequest> request, | 65 scoped_ptr<net::URLRequest> request, |
| 66 base::PlatformFileError error, | 66 base::File::Error error, |
| 67 const base::PlatformFileInfo& file_info); | 67 const base::File::Info& file_info); |
| 68 void Read(); | 68 void Read(); |
| 69 void OnDataReceived(int bytes_read); | 69 void OnDataReceived(int bytes_read); |
| 70 void Write(); | 70 void Write(); |
| 71 void OnDataWritten(int write_response); | 71 void OnDataWritten(int write_response); |
| 72 void OnError(base::PlatformFileError error); | 72 void OnError(base::File::Error error); |
| 73 void OnProgress(int bytes_read, bool done); | 73 void OnProgress(int bytes_read, bool done); |
| 74 void OnWriteCancelled(int status); | 74 void OnWriteCancelled(int status); |
| 75 void FlushForCompletion(base::PlatformFileError error, | 75 void FlushForCompletion(base::File::Error error, |
| 76 int bytes_written, | 76 int bytes_written, |
| 77 WriteProgressStatus progress_status); | 77 WriteProgressStatus progress_status); |
| 78 void OnFlushed(base::PlatformFileError error, | 78 void OnFlushed(base::File::Error error, |
| 79 int bytes_written, | 79 int bytes_written, |
| 80 WriteProgressStatus progress_status, | 80 WriteProgressStatus progress_status, |
| 81 int flush_error); | 81 int flush_error); |
| 82 | 82 |
| 83 WriteProgressStatus GetCompletionStatusOnError() const; | 83 WriteProgressStatus GetCompletionStatusOnError() const; |
| 84 | 84 |
| 85 DelegateWriteCallback write_callback_; | 85 DelegateWriteCallback write_callback_; |
| 86 scoped_ptr<FileStreamWriter> file_stream_writer_; | 86 scoped_ptr<FileStreamWriter> file_stream_writer_; |
| 87 base::Time last_progress_event_time_; | 87 base::Time last_progress_event_time_; |
| 88 bool writing_started_; | 88 bool writing_started_; |
| 89 int bytes_written_backlog_; | 89 int bytes_written_backlog_; |
| 90 int bytes_written_; | 90 int bytes_written_; |
| 91 int bytes_read_; | 91 int bytes_read_; |
| 92 scoped_refptr<net::IOBufferWithSize> io_buffer_; | 92 scoped_refptr<net::IOBufferWithSize> io_buffer_; |
| 93 scoped_refptr<net::DrainableIOBuffer> cursor_; | 93 scoped_refptr<net::DrainableIOBuffer> cursor_; |
| 94 scoped_ptr<net::URLRequest> request_; | 94 scoped_ptr<net::URLRequest> request_; |
| 95 | 95 |
| 96 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; | 96 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; |
| 97 | 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); | 98 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 } // namespace fileapi | 101 } // namespace fileapi |
| 102 | 102 |
| 103 #endif // WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ | 103 #endif // WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| OLD | NEW |