blob: f7ce16dfb6fdf2f0e3f32614674452345e1c837b [file] [log] [blame]
[email protected]9f49afb2012-02-16 09:59:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]bd152382010-10-07 23:24:382// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]c6f9203a2013-05-28 02:08:075#ifndef WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_
6#define WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_
[email protected]bd152382010-10-07 23:24:387
[email protected]57999812013-02-24 05:40:528#include "base/files/file_path.h"
[email protected]3b63f8f42011-03-28 01:54:159#include "base/memory/scoped_ptr.h"
[email protected]9e629ab2011-10-20 22:03:4310#include "base/memory/weak_ptr.h"
[email protected]bd152382010-10-07 23:24:3811#include "base/platform_file.h"
[email protected]0a8ebe12013-06-28 15:23:2312#include "base/time/time.h"
[email protected]bd152382010-10-07 23:24:3813#include "net/base/file_stream.h"
14#include "net/base/io_buffer.h"
15#include "net/url_request/url_request.h"
[email protected]e5bf2fd2013-06-13 02:59:1816#include "webkit/browser/webkit_storage_browser_export.h"
[email protected]bd152382010-10-07 23:24:3817
18namespace fileapi {
19
[email protected]7e836a3d2012-05-31 05:14:5920class FileStreamWriter;
[email protected]bd152382010-10-07 23:24:3821
[email protected]e5bf2fd2013-06-13 02:59:1822class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE FileWriterDelegate
[email protected]53a97412013-08-09 03:57:1423 : public net::URLRequest::Delegate {
[email protected]bd152382010-10-07 23:24:3824 public:
[email protected]ca474482012-09-26 11:21:2125 enum WriteProgressStatus {
26 SUCCESS_IO_PENDING,
27 SUCCESS_COMPLETED,
28 ERROR_WRITE_STARTED,
29 ERROR_WRITE_NOT_STARTED,
30 };
31
[email protected]b9566e7c2012-10-29 10:57:4632 typedef base::Callback<void(base::PlatformFileError result,
33 int64 bytes,
34 WriteProgressStatus write_status)>
35 DelegateWriteCallback;
[email protected]ca474482012-09-26 11:21:2136
[email protected]7ba16272013-10-07 09:43:1637 explicit FileWriterDelegate(scoped_ptr<FileStreamWriter> file_writer);
[email protected]bd152382010-10-07 23:24:3838 virtual ~FileWriterDelegate();
39
[email protected]1a6e3902013-06-13 07:09:4040 void Start(scoped_ptr<net::URLRequest> request,
41 const DelegateWriteCallback& write_callback);
[email protected]8623b0f92012-05-11 05:31:0942
[email protected]2c02c8d2013-06-10 17:52:4343 // Cancels the current write operation. This will synchronously or
44 // asynchronously call the given write callback (which may result in
45 // deleting this).
46 void Cancel();
[email protected]8623b0f92012-05-11 05:31:0947
[email protected]e5624f02011-09-27 19:43:5348 virtual void OnReceivedRedirect(net::URLRequest* request,
49 const GURL& new_url,
50 bool* defer_redirect) OVERRIDE;
51 virtual void OnAuthRequired(net::URLRequest* request,
52 net::AuthChallengeInfo* auth_info) OVERRIDE;
[email protected]bd152382010-10-07 23:24:3853 virtual void OnCertificateRequested(
[email protected]e5624f02011-09-27 19:43:5354 net::URLRequest* request,
55 net::SSLCertRequestInfo* cert_request_info) OVERRIDE;
56 virtual void OnSSLCertificateError(net::URLRequest* request,
57 const net::SSLInfo& ssl_info,
[email protected]46d117e2012-01-18 01:53:1458 bool fatal) OVERRIDE;
[email protected]e5624f02011-09-27 19:43:5359 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE;
60 virtual void OnReadCompleted(net::URLRequest* request,
61 int bytes_read) OVERRIDE;
[email protected]bd152382010-10-07 23:24:3862
63 private:
[email protected]8623b0f92012-05-11 05:31:0964 void OnGetFileInfoAndStartRequest(
65 scoped_ptr<net::URLRequest> request,
[email protected]078c6971a2011-04-21 05:04:5166 base::PlatformFileError error,
[email protected]e5006b92011-05-17 11:53:5167 const base::PlatformFileInfo& file_info);
[email protected]bd152382010-10-07 23:24:3868 void Read();
69 void OnDataReceived(int bytes_read);
70 void Write();
71 void OnDataWritten(int write_response);
72 void OnError(base::PlatformFileError error);
73 void OnProgress(int bytes_read, bool done);
[email protected]397a1f4d2012-05-22 09:19:3174 void OnWriteCancelled(int status);
[email protected]a95ce0762012-10-01 05:54:2675 void FlushForCompletion(base::PlatformFileError error,
76 int bytes_written,
77 WriteProgressStatus progress_status);
78 void OnFlushed(base::PlatformFileError error,
79 int bytes_written,
80 WriteProgressStatus progress_status,
81 int flush_error);
[email protected]bd152382010-10-07 23:24:3882
[email protected]ca474482012-09-26 11:21:2183 WriteProgressStatus GetCompletionStatusOnError() const;
[email protected]e5006b92011-05-17 11:53:5184
[email protected]ca474482012-09-26 11:21:2185 DelegateWriteCallback write_callback_;
[email protected]7e836a3d2012-05-31 05:14:5986 scoped_ptr<FileStreamWriter> file_stream_writer_;
[email protected]bd152382010-10-07 23:24:3887 base::Time last_progress_event_time_;
[email protected]ca474482012-09-26 11:21:2188 bool writing_started_;
[email protected]8bf65df2011-05-27 07:26:1589 int bytes_written_backlog_;
[email protected]bd152382010-10-07 23:24:3890 int bytes_written_;
91 int bytes_read_;
92 scoped_refptr<net::IOBufferWithSize> io_buffer_;
[email protected]9f49afb2012-02-16 09:59:2093 scoped_refptr<net::DrainableIOBuffer> cursor_;
[email protected]8623b0f92012-05-11 05:31:0994 scoped_ptr<net::URLRequest> request_;
[email protected]53a97412013-08-09 03:57:1495
96 base::WeakPtrFactory<FileWriterDelegate> weak_factory_;
97
98 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate);
[email protected]bd152382010-10-07 23:24:3899};
100
101} // namespace fileapi
102
[email protected]c6f9203a2013-05-28 02:08:07103#endif // WEBKIT_BROWSER_FILEAPI_FILE_WRITER_DELEGATE_H_