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 WEBKIT_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_
6 #define WEBKIT_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_
8 #include "base/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/platform_file.h"
11 #include "googleurl/src/gurl.h"
12 #include "webkit/fileapi/file_stream_writer.h"
13 #include "webkit/fileapi/file_system_types.h"
14 #include "webkit/fileapi/file_system_url.h"
15 #include "webkit/fileapi/fileapi_export.h"
16 #include "webkit/fileapi/task_runner_bound_observer_list.h"
17 #include "webkit/quota/quota_types.h"
21 class FileSystemContext
;
22 class FileSystemQuotaUtil
;
23 class LocalFileStreamWriter
;
25 class FILEAPI_EXPORT_PRIVATE SandboxFileStreamWriter
: public FileStreamWriter
{
27 SandboxFileStreamWriter(FileSystemContext
* file_system_context
,
28 const FileSystemURL
& url
,
30 const UpdateObserverList
& observers
);
31 virtual ~SandboxFileStreamWriter();
33 // FileStreamWriter overrides.
34 virtual int Write(net::IOBuffer
* buf
, int buf_len
,
35 const net::CompletionCallback
& callback
) OVERRIDE
;
36 virtual int Cancel(const net::CompletionCallback
& callback
) OVERRIDE
;
38 // Used only by tests.
39 void set_default_quota(int64 quota
) {
40 default_quota_
= quota
;
44 // Performs quota calculation and calls local_file_writer_->Write().
45 int WriteInternal(net::IOBuffer
* buf
, int buf_len
,
46 const net::CompletionCallback
& callback
);
48 // Callbacks that are chained for the first write. This eventually calls
50 void DidGetFileInfo(const net::CompletionCallback
& callback
,
51 base::PlatformFileError file_error
,
52 const base::PlatformFileInfo
& file_info
,
53 const FilePath
& platform_path
);
54 void DidGetUsageAndQuota(const net::CompletionCallback
& callback
,
55 quota::QuotaStatusCode status
,
56 int64 usage
, int64 quota
);
57 void DidInitializeForWrite(net::IOBuffer
* buf
, int buf_len
,
58 const net::CompletionCallback
& callback
,
61 void DidWrite(const net::CompletionCallback
& callback
, int write_response
);
63 // Stops the in-flight operation, calls |cancel_callback_| and returns true
64 // if there's a pending cancel request.
65 bool CancelIfRequested();
67 scoped_refptr
<FileSystemContext
> file_system_context_
;
69 int64 initial_offset_
;
70 scoped_ptr
<LocalFileStreamWriter
> local_file_writer_
;
71 net::CompletionCallback cancel_callback_
;
73 UpdateObserverList observers_
;
77 int64 total_bytes_written_
;
78 int64 allowed_bytes_to_write_
;
79 bool has_pending_operation_
;
83 base::WeakPtrFactory
<SandboxFileStreamWriter
> weak_factory_
;
85 DISALLOW_COPY_AND_ASSIGN(SandboxFileStreamWriter
);
88 } // namespace fileapi
90 #endif // WEBKIT_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_