Chromium Code Reviews| 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/file_system_path.h" | 16 #include "webkit/fileapi/file_system_path.h" |
| 17 | 17 |
| 18 namespace fileapi { | 18 namespace fileapi { |
| 19 | 19 |
| 20 class FileSystemOperation; | 20 class FileSystemOperation; |
| 21 class FileSystemOperationContext; | 21 class FileSystemOperationContext; |
| 22 class FileSystemQuotaUtil; | 22 class FileSystemQuotaUtil; |
| 23 class FileWriter; | |
| 23 | 24 |
| 24 class FileWriterDelegate : public net::URLRequest::Delegate { | 25 class FileWriterDelegate : public net::URLRequest::Delegate { |
| 25 public: | 26 public: |
| 26 FileWriterDelegate( | 27 FileWriterDelegate( |
| 27 FileSystemOperation* write_operation, | 28 FileSystemOperation* write_operation, |
|
kinaba
2012/05/21 09:27:00
Can you replace the parameter with const FileSyste
kinuko
2012/05/21 11:20:22
Sounds good, done.
| |
| 28 const FileSystemPath& path, | 29 scoped_ptr<FileWriter> file_writer); |
| 29 int64 offset); | |
| 30 virtual ~FileWriterDelegate(); | 30 virtual ~FileWriterDelegate(); |
| 31 | 31 |
| 32 void Start(base::PlatformFile file, | 32 void Start(scoped_ptr<net::URLRequest> request); |
| 33 scoped_ptr<net::URLRequest> request); | |
| 34 | 33 |
| 35 // Cancels the current write operation. Returns true if it is ok to | 34 // Cancels the current write operation. Returns true if it is ok to |
| 36 // delete this instance immediately. Otherwise this will call | 35 // delete this instance immediately. Otherwise this will call |
| 37 // |write_operation|->DidWrite() with complete=true to let the operation | 36 // |write_operation|->DidWrite() with complete=true to let the operation |
| 38 // perform the final cleanup. | 37 // perform the final cleanup. |
| 39 bool Cancel(); | 38 bool Cancel(); |
| 40 | 39 |
| 41 base::PlatformFile file() const { return file_; } | |
| 42 | |
| 43 virtual void OnReceivedRedirect(net::URLRequest* request, | 40 virtual void OnReceivedRedirect(net::URLRequest* request, |
| 44 const GURL& new_url, | 41 const GURL& new_url, |
| 45 bool* defer_redirect) OVERRIDE; | 42 bool* defer_redirect) OVERRIDE; |
| 46 virtual void OnAuthRequired(net::URLRequest* request, | 43 virtual void OnAuthRequired(net::URLRequest* request, |
| 47 net::AuthChallengeInfo* auth_info) OVERRIDE; | 44 net::AuthChallengeInfo* auth_info) OVERRIDE; |
| 48 virtual void OnCertificateRequested( | 45 virtual void OnCertificateRequested( |
| 49 net::URLRequest* request, | 46 net::URLRequest* request, |
| 50 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; | 47 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; |
| 51 virtual void OnSSLCertificateError(net::URLRequest* request, | 48 virtual void OnSSLCertificateError(net::URLRequest* request, |
| 52 const net::SSLInfo& ssl_info, | 49 const net::SSLInfo& ssl_info, |
| 53 bool fatal) OVERRIDE; | 50 bool fatal) OVERRIDE; |
| 54 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; | 51 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
| 55 virtual void OnReadCompleted(net::URLRequest* request, | 52 virtual void OnReadCompleted(net::URLRequest* request, |
| 56 int bytes_read) OVERRIDE; | 53 int bytes_read) OVERRIDE; |
| 57 | 54 |
| 58 private: | 55 private: |
| 59 void OnGetFileInfoAndStartRequest( | 56 void OnGetFileInfoAndStartRequest( |
| 60 scoped_ptr<net::URLRequest> request, | 57 scoped_ptr<net::URLRequest> request, |
| 61 base::PlatformFileError error, | 58 base::PlatformFileError error, |
| 62 const base::PlatformFileInfo& file_info); | 59 const base::PlatformFileInfo& file_info); |
| 63 void Read(); | 60 void Read(); |
| 64 void OnDataReceived(int bytes_read); | 61 void OnDataReceived(int bytes_read); |
| 65 void Write(); | 62 void Write(); |
| 66 void OnDataWritten(int write_response); | 63 void OnDataWritten(int write_response); |
| 67 void OnError(base::PlatformFileError error); | 64 void OnError(base::PlatformFileError error); |
| 68 void OnProgress(int bytes_read, bool done); | 65 void OnProgress(int bytes_read, bool done); |
| 66 void OnWriteCancelled(int status); | |
| 69 | 67 |
| 70 FileSystemOperationContext* file_system_operation_context() const; | 68 FileSystemOperationContext* file_system_operation_context() const; |
| 71 FileSystemQuotaUtil* quota_util() const; | 69 FileSystemQuotaUtil* quota_util() const; |
| 72 | 70 |
| 73 FileSystemOperation* file_system_operation_; | 71 FileSystemOperation* file_system_operation_; |
| 74 base::PlatformFile file_; | 72 scoped_ptr<FileWriter> file_writer_; |
| 75 FileSystemPath path_; | |
| 76 int64 size_; | |
| 77 int64 offset_; | |
| 78 bool has_pending_write_; | |
| 79 base::Time last_progress_event_time_; | 73 base::Time last_progress_event_time_; |
| 80 int bytes_written_backlog_; | 74 int bytes_written_backlog_; |
| 81 int bytes_written_; | 75 int bytes_written_; |
| 82 int bytes_read_; | 76 int bytes_read_; |
| 83 int64 total_bytes_written_; | |
| 84 int64 allowed_bytes_to_write_; | |
| 85 scoped_refptr<net::IOBufferWithSize> io_buffer_; | 77 scoped_refptr<net::IOBufferWithSize> io_buffer_; |
| 86 scoped_refptr<net::DrainableIOBuffer> cursor_; | 78 scoped_refptr<net::DrainableIOBuffer> cursor_; |
| 87 scoped_ptr<net::FileStream> file_stream_; | |
| 88 scoped_ptr<net::URLRequest> request_; | 79 scoped_ptr<net::URLRequest> request_; |
| 89 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; | 80 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; |
| 90 }; | 81 }; |
| 91 | 82 |
| 92 } // namespace fileapi | 83 } // namespace fileapi |
| 93 | 84 |
| 94 #endif // WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ | 85 #endif // WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| OLD | NEW |