OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ | |
6 #define WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ | |
7 | |
8 #include "base/files/file_path.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "base/platform_file.h" | |
12 #include "base/time.h" | |
13 #include "net/base/file_stream.h" | |
14 #include "net/base/io_buffer.h" | |
15 #include "net/url_request/url_request.h" | |
16 #include "webkit/fileapi/file_system_operation.h" | |
17 #include "webkit/storage/webkit_storage_export.h" | |
18 | |
19 namespace fileapi { | |
20 | |
21 class FileStreamWriter; | |
22 class FileSystemOperationContext; | |
23 class FileSystemQuotaUtil; | |
24 | |
25 class WEBKIT_STORAGE_EXPORT_PRIVATE FileWriterDelegate | |
26 : public net::URLRequest::Delegate { | |
27 public: | |
28 enum WriteProgressStatus { | |
29 SUCCESS_IO_PENDING, | |
30 SUCCESS_COMPLETED, | |
31 ERROR_WRITE_STARTED, | |
32 ERROR_WRITE_NOT_STARTED, | |
33 }; | |
34 | |
35 typedef base::Callback<void(base::PlatformFileError result, | |
36 int64 bytes, | |
37 WriteProgressStatus write_status)> | |
38 DelegateWriteCallback; | |
39 | |
40 FileWriterDelegate( | |
41 const DelegateWriteCallback& write_callback, | |
42 scoped_ptr<FileStreamWriter> file_writer); | |
43 virtual ~FileWriterDelegate(); | |
44 | |
45 void Start(scoped_ptr<net::URLRequest> request); | |
46 | |
47 // Cancels the current write operation. Returns true if it is ok to | |
48 // delete this instance immediately. Otherwise this will call | |
49 // |write_operation|->DidWrite() with complete=true to let the operation | |
50 // perform the final cleanup. | |
51 bool Cancel(); | |
52 | |
53 virtual void OnReceivedRedirect(net::URLRequest* request, | |
54 const GURL& new_url, | |
55 bool* defer_redirect) OVERRIDE; | |
56 virtual void OnAuthRequired(net::URLRequest* request, | |
57 net::AuthChallengeInfo* auth_info) OVERRIDE; | |
58 virtual void OnCertificateRequested( | |
59 net::URLRequest* request, | |
60 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; | |
61 virtual void OnSSLCertificateError(net::URLRequest* request, | |
62 const net::SSLInfo& ssl_info, | |
63 bool fatal) OVERRIDE; | |
64 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; | |
65 virtual void OnReadCompleted(net::URLRequest* request, | |
66 int bytes_read) OVERRIDE; | |
67 | |
68 private: | |
69 void OnGetFileInfoAndStartRequest( | |
70 scoped_ptr<net::URLRequest> request, | |
71 base::PlatformFileError error, | |
72 const base::PlatformFileInfo& file_info); | |
73 void Read(); | |
74 void OnDataReceived(int bytes_read); | |
75 void Write(); | |
76 void OnDataWritten(int write_response); | |
77 void OnError(base::PlatformFileError error); | |
78 void OnProgress(int bytes_read, bool done); | |
79 void OnWriteCancelled(int status); | |
80 void FlushForCompletion(base::PlatformFileError error, | |
81 int bytes_written, | |
82 WriteProgressStatus progress_status); | |
83 void OnFlushed(base::PlatformFileError error, | |
84 int bytes_written, | |
85 WriteProgressStatus progress_status, | |
86 int flush_error); | |
87 | |
88 FileSystemQuotaUtil* quota_util() const; | |
89 WriteProgressStatus GetCompletionStatusOnError() const; | |
90 | |
91 DelegateWriteCallback write_callback_; | |
92 scoped_ptr<FileStreamWriter> file_stream_writer_; | |
93 base::Time last_progress_event_time_; | |
94 bool writing_started_; | |
95 int bytes_written_backlog_; | |
96 int bytes_written_; | |
97 int bytes_read_; | |
98 scoped_refptr<net::IOBufferWithSize> io_buffer_; | |
99 scoped_refptr<net::DrainableIOBuffer> cursor_; | |
100 scoped_ptr<net::URLRequest> request_; | |
101 base::WeakPtrFactory<FileWriterDelegate> weak_factory_; | |
102 }; | |
103 | |
104 } // namespace fileapi | |
105 | |
106 #endif // WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ | |
OLD | NEW |