We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / storage / browser / fileapi / sandbox_file_stream_writer.h
blob61375b11b37e00b2a65c011e40fc146a890302bc
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.
5 #ifndef STORAGE_BROWSER_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_
6 #define STORAGE_BROWSER_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_
8 #include "base/files/file.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "storage/browser/blob/shareable_file_reference.h"
12 #include "storage/browser/fileapi/file_stream_writer.h"
13 #include "storage/browser/fileapi/file_system_url.h"
14 #include "storage/browser/fileapi/task_runner_bound_observer_list.h"
15 #include "storage/browser/storage_browser_export.h"
16 #include "storage/common/fileapi/file_system_types.h"
17 #include "storage/common/quota/quota_types.h"
18 #include "url/gurl.h"
20 namespace storage {
22 class FileSystemContext;
23 class FileSystemQuotaUtil;
24 class FileStreamWriter;
26 class STORAGE_EXPORT_PRIVATE SandboxFileStreamWriter
27 : public NON_EXPORTED_BASE(FileStreamWriter) {
28 public:
29 SandboxFileStreamWriter(FileSystemContext* file_system_context,
30 const FileSystemURL& url,
31 int64 initial_offset,
32 const UpdateObserverList& observers);
33 ~SandboxFileStreamWriter() override;
35 // FileStreamWriter overrides.
36 int Write(net::IOBuffer* buf,
37 int buf_len,
38 const net::CompletionCallback& callback) override;
39 int Cancel(const net::CompletionCallback& callback) override;
40 int Flush(const net::CompletionCallback& callback) override;
42 // Used only by tests.
43 void set_default_quota(int64 quota) {
44 default_quota_ = quota;
47 private:
48 // Performs quota calculation and calls local_file_writer_->Write().
49 int WriteInternal(net::IOBuffer* buf, int buf_len,
50 const net::CompletionCallback& callback);
52 // Callbacks that are chained for the first write. This eventually calls
53 // WriteInternal.
54 void DidCreateSnapshotFile(
55 const net::CompletionCallback& callback,
56 base::File::Error file_error,
57 const base::File::Info& file_info,
58 const base::FilePath& platform_path,
59 const scoped_refptr<storage::ShareableFileReference>& file_ref);
60 void DidGetUsageAndQuota(const net::CompletionCallback& callback,
61 storage::QuotaStatusCode status,
62 int64 usage,
63 int64 quota);
64 void DidInitializeForWrite(net::IOBuffer* buf, int buf_len,
65 const net::CompletionCallback& callback,
66 int init_status);
68 void DidWrite(const net::CompletionCallback& callback, int write_response);
70 // Stops the in-flight operation, calls |cancel_callback_| and returns true
71 // if there's a pending cancel request.
72 bool CancelIfRequested();
74 scoped_refptr<FileSystemContext> file_system_context_;
75 FileSystemURL url_;
76 int64 initial_offset_;
77 scoped_ptr<FileStreamWriter> local_file_writer_;
78 net::CompletionCallback cancel_callback_;
80 UpdateObserverList observers_;
82 base::FilePath file_path_;
83 int64 file_size_;
84 int64 total_bytes_written_;
85 int64 allowed_bytes_to_write_;
86 bool has_pending_operation_;
88 int64 default_quota_;
90 base::WeakPtrFactory<SandboxFileStreamWriter> weak_factory_;
92 DISALLOW_COPY_AND_ASSIGN(SandboxFileStreamWriter);
95 } // namespace storage
97 #endif // STORAGE_BROWSER_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_