| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 class FileWriterDelegate : public net::URLRequest::Delegate { | 25 class FileWriterDelegate : public net::URLRequest::Delegate { |
| 26 public: | 26 public: |
| 27 FileWriterDelegate( | 27 FileWriterDelegate( |
| 28 FileSystemOperation* write_operation, | 28 FileSystemOperation* write_operation, |
| 29 const FileSystemPath& path, | 29 const FileSystemPath& path, |
| 30 int64 offset, | 30 int64 offset, |
| 31 scoped_refptr<base::MessageLoopProxy> proxy); | 31 scoped_refptr<base::MessageLoopProxy> proxy); |
| 32 virtual ~FileWriterDelegate(); | 32 virtual ~FileWriterDelegate(); |
| 33 | 33 |
| 34 void Start(base::PlatformFile file, | 34 void Start(base::PlatformFile file, |
| 35 net::URLRequest* request); | 35 scoped_ptr<net::URLRequest> request); |
| 36 base::PlatformFile file() { | 36 void Cancel(); |
| 37 return file_; | 37 |
| 38 } | 38 base::PlatformFile file() const { return file_; } |
| 39 | 39 |
| 40 virtual void OnReceivedRedirect(net::URLRequest* request, | 40 virtual void OnReceivedRedirect(net::URLRequest* request, |
| 41 const GURL& new_url, | 41 const GURL& new_url, |
| 42 bool* defer_redirect) OVERRIDE; | 42 bool* defer_redirect) OVERRIDE; |
| 43 virtual void OnAuthRequired(net::URLRequest* request, | 43 virtual void OnAuthRequired(net::URLRequest* request, |
| 44 net::AuthChallengeInfo* auth_info) OVERRIDE; | 44 net::AuthChallengeInfo* auth_info) OVERRIDE; |
| 45 virtual void OnCertificateRequested( | 45 virtual void OnCertificateRequested( |
| 46 net::URLRequest* request, | 46 net::URLRequest* request, |
| 47 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; | 47 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; |
| 48 virtual void OnSSLCertificateError(net::URLRequest* request, | 48 virtual void OnSSLCertificateError(net::URLRequest* request, |
| 49 const net::SSLInfo& ssl_info, | 49 const net::SSLInfo& ssl_info, |
| 50 bool fatal) OVERRIDE; | 50 bool fatal) OVERRIDE; |
| 51 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; | 51 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
| 52 virtual void OnReadCompleted(net::URLRequest* request, | 52 virtual void OnReadCompleted(net::URLRequest* request, |
| 53 int bytes_read) OVERRIDE; | 53 int bytes_read) OVERRIDE; |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 enum State { |
| 57 FILE_WRITER_STATE_CREATED, |
| 58 FILE_WRITER_STATE_REQUEST_STARTED, |
| 59 FILE_WRITER_STATE_CANCELED, |
| 60 }; |
| 61 |
| 56 void OnGetFileInfoAndCallStartUpdate( | 62 void OnGetFileInfoAndCallStartUpdate( |
| 57 base::PlatformFileError error, | 63 base::PlatformFileError error, |
| 58 const base::PlatformFileInfo& file_info); | 64 const base::PlatformFileInfo& file_info); |
| 59 void Read(); | 65 void Read(); |
| 60 void OnDataReceived(int bytes_read); | 66 void OnDataReceived(int bytes_read); |
| 61 void Write(); | 67 void Write(); |
| 62 void OnDataWritten(int write_response); | 68 void OnDataWritten(int write_response); |
| 63 void OnError(base::PlatformFileError error); | 69 void OnError(base::PlatformFileError error); |
| 64 void OnProgress(int bytes_read, bool done); | 70 void OnProgress(int bytes_read, bool done); |
| 65 | 71 |
| 66 FileSystemOperationContext* file_system_operation_context() const; | 72 FileSystemOperationContext* file_system_operation_context() const; |
| 67 FileSystemQuotaUtil* quota_util() const; | 73 FileSystemQuotaUtil* quota_util() const; |
| 68 | 74 |
| 69 FileSystemOperation* file_system_operation_; | 75 FileSystemOperation* file_system_operation_; |
| 76 State state_; |
| 70 base::PlatformFile file_; | 77 base::PlatformFile file_; |
| 71 FileSystemPath path_; | 78 FileSystemPath path_; |
| 72 int64 size_; | 79 int64 size_; |
| 73 int64 offset_; | 80 int64 offset_; |
| 74 scoped_refptr<base::MessageLoopProxy> proxy_; | 81 scoped_refptr<base::MessageLoopProxy> proxy_; |
| 75 base::Time last_progress_event_time_; | 82 base::Time last_progress_event_time_; |
| 76 int bytes_written_backlog_; | 83 int bytes_written_backlog_; |
| 77 int bytes_written_; | 84 int bytes_written_; |
| 78 int bytes_read_; | 85 int bytes_read_; |
| 79 int64 total_bytes_written_; | 86 int64 total_bytes_written_; |
| 80 int64 allowed_bytes_to_write_; | 87 int64 allowed_bytes_to_write_; |
| 81 scoped_refptr<net::IOBufferWithSize> io_buffer_; | 88 scoped_refptr<net::IOBufferWithSize> io_buffer_; |
| 82 scoped_refptr<net::DrainableIOBuffer> cursor_; | 89 scoped_refptr<net::DrainableIOBuffer> cursor_; |
| 83 scoped_ptr<net::FileStream> file_stream_; | 90 scoped_ptr<net::FileStream> file_stream_; |
| 84 net::URLRequest* request_; | 91 scoped_ptr<net::URLRequest> request_; |
| 85 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; | 92 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; |
| 86 }; | 93 }; |
| 87 | 94 |
| 88 } // namespace fileapi | 95 } // namespace fileapi |
| 89 | 96 |
| 90 #endif // WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ | 97 #endif // WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ |
| OLD | NEW |