| 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_path.h" | 8 #include "base/files/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/browser/fileapi/file_system_operation.h" | |
| 17 #include "webkit/storage/webkit_storage_export.h" | 16 #include "webkit/storage/webkit_storage_export.h" |
| 18 | 17 |
| 19 namespace fileapi { | 18 namespace fileapi { |
| 20 | 19 |
| 21 class FileStreamWriter; | 20 class FileStreamWriter; |
| 22 class FileSystemOperationContext; | |
| 23 class FileSystemQuotaUtil; | |
| 24 | 21 |
| 25 class WEBKIT_STORAGE_EXPORT_PRIVATE FileWriterDelegate | 22 class WEBKIT_STORAGE_EXPORT_PRIVATE FileWriterDelegate |
| 26 : public net::URLRequest::Delegate { | 23 : public net::URLRequest::Delegate, |
| 24 public base::SupportsWeakPtr<FileWriterDelegate> { |
| 27 public: | 25 public: |
| 28 enum WriteProgressStatus { | 26 enum WriteProgressStatus { |
| 29 SUCCESS_IO_PENDING, | 27 SUCCESS_IO_PENDING, |
| 30 SUCCESS_COMPLETED, | 28 SUCCESS_COMPLETED, |
| 31 ERROR_WRITE_STARTED, | 29 ERROR_WRITE_STARTED, |
| 32 ERROR_WRITE_NOT_STARTED, | 30 ERROR_WRITE_NOT_STARTED, |
| 33 }; | 31 }; |
| 34 | 32 |
| 35 typedef base::Callback<void(base::PlatformFileError result, | 33 typedef base::Callback<void(base::PlatformFileError result, |
| 36 int64 bytes, | 34 int64 bytes, |
| 37 WriteProgressStatus write_status)> | 35 WriteProgressStatus write_status)> |
| 38 DelegateWriteCallback; | 36 DelegateWriteCallback; |
| 39 | 37 |
| 40 FileWriterDelegate( | 38 FileWriterDelegate( |
| 41 const DelegateWriteCallback& write_callback, | 39 const DelegateWriteCallback& write_callback, |
| 42 scoped_ptr<FileStreamWriter> file_writer); | 40 scoped_ptr<FileStreamWriter> file_writer); |
| 43 virtual ~FileWriterDelegate(); | 41 virtual ~FileWriterDelegate(); |
| 44 | 42 |
| 45 void Start(scoped_ptr<net::URLRequest> request); | 43 void Start(scoped_ptr<net::URLRequest> request); |
| 46 | 44 |
| 47 // Cancels the current write operation. Returns true if it is ok to | 45 // Cancels the current write operation. This will synchronously or |
| 48 // delete this instance immediately. Otherwise this will call | 46 // asynchronously call the given write callback (which may result in |
| 49 // |write_operation|->DidWrite() with complete=true to let the operation | 47 // deleting this). |
| 50 // perform the final cleanup. | 48 void Cancel(); |
| 51 bool Cancel(); | |
| 52 | 49 |
| 53 virtual void OnReceivedRedirect(net::URLRequest* request, | 50 virtual void OnReceivedRedirect(net::URLRequest* request, |
| 54 const GURL& new_url, | 51 const GURL& new_url, |
| 55 bool* defer_redirect) OVERRIDE; | 52 bool* defer_redirect) OVERRIDE; |
| 56 virtual void OnAuthRequired(net::URLRequest* request, | 53 virtual void OnAuthRequired(net::URLRequest* request, |
| 57 net::AuthChallengeInfo* auth_info) OVERRIDE; | 54 net::AuthChallengeInfo* auth_info) OVERRIDE; |
| 58 virtual void OnCertificateRequested( | 55 virtual void OnCertificateRequested( |
| 59 net::URLRequest* request, | 56 net::URLRequest* request, |
| 60 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; | 57 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; |
| 61 virtual void OnSSLCertificateError(net::URLRequest* request, | 58 virtual void OnSSLCertificateError(net::URLRequest* request, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 78 void OnProgress(int bytes_read, bool done); | 75 void OnProgress(int bytes_read, bool done); |
| 79 void OnWriteCancelled(int status); | 76 void OnWriteCancelled(int status); |
| 80 void FlushForCompletion(base::PlatformFileError error, | 77 void FlushForCompletion(base::PlatformFileError error, |
| 81 int bytes_written, | 78 int bytes_written, |
| 82 WriteProgressStatus progress_status); | 79 WriteProgressStatus progress_status); |
| 83 void OnFlushed(base::PlatformFileError error, | 80 void OnFlushed(base::PlatformFileError error, |
| 84 int bytes_written, | 81 int bytes_written, |
| 85 WriteProgressStatus progress_status, | 82 WriteProgressStatus progress_status, |
| 86 int flush_error); | 83 int flush_error); |
| 87 | 84 |
| 88 FileSystemQuotaUtil* quota_util() const; | |
| 89 WriteProgressStatus GetCompletionStatusOnError() const; | 85 WriteProgressStatus GetCompletionStatusOnError() const; |
| 90 | 86 |
| 91 DelegateWriteCallback write_callback_; | 87 DelegateWriteCallback write_callback_; |
| 92 scoped_ptr<FileStreamWriter> file_stream_writer_; | 88 scoped_ptr<FileStreamWriter> file_stream_writer_; |
| 93 base::Time last_progress_event_time_; | 89 base::Time last_progress_event_time_; |
| 94 bool writing_started_; | 90 bool writing_started_; |
| 95 int bytes_written_backlog_; | 91 int bytes_written_backlog_; |
| 96 int bytes_written_; | 92 int bytes_written_; |
| 97 int bytes_read_; | 93 int bytes_read_; |
| 98 scoped_refptr<net::IOBufferWithSize> io_buffer_; | 94 scoped_refptr<net::IOBufferWithSize> io_buffer_; |
| 99 scoped_refptr<net::DrainableIOBuffer> cursor_; | 95 scoped_refptr<net::DrainableIOBuffer> cursor_; |
| 100 scoped_ptr<net::URLRequest> request_; | 96 scoped_ptr<net::URLRequest> request_; |
| 101 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; | |
| 102 }; | 97 }; |
| 103 | 98 |
| 104 } // namespace fileapi | 99 } // namespace fileapi |
| 105 | 100 |
| 106 #endif // WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ | 101 #endif // WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| OLD | NEW |