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