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_CHROMEOS_FILEAPI_REMOTE_FILE_STREAM_WRITER_H_
6 #define WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_STREAM_WRITER_H_
8 #include "base/basictypes.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/platform_file.h"
13 #include "webkit/fileapi/file_stream_writer.h"
14 #include "webkit/fileapi/file_system_url.h"
20 namespace webkit_blob
{
21 class ShareableFileReference
;
26 class RemoteFileSystemProxyInterface
;
28 // FileStreamWriter interface for writing to a file on remote file system.
29 class RemoteFileStreamWriter
: public fileapi::FileStreamWriter
{
31 // Creates a writer for a file on |remote_filesystem| with path url |url|
32 // (like "filesystem:chrome-extension://id/external/special/drive/...") that
33 // starts writing from |offset|. When invalid parameters are set, the first
34 // call to Write() method fails.
35 RemoteFileStreamWriter(
36 const scoped_refptr
<RemoteFileSystemProxyInterface
>& remote_filesystem
,
37 const FileSystemURL
& url
,
39 virtual ~RemoteFileStreamWriter();
41 // FileWriter override.
42 virtual int Write(net::IOBuffer
* buf
, int buf_len
,
43 const net::CompletionCallback
& callback
) OVERRIDE
;
44 virtual int Cancel(const net::CompletionCallback
& callback
) OVERRIDE
;
45 virtual int Flush(const net::CompletionCallback
& callback
) OVERRIDE
;
48 // Callback function to do the continuation of the work of the first Write()
49 // call, which tries to open the local copy of the file before writing.
53 const net::CompletionCallback
& callback
,
54 base::PlatformFileError open_result
,
55 const base::FilePath
& local_path
,
56 const scoped_refptr
<webkit_blob::ShareableFileReference
>& file_ref
);
57 // Calls |pending_cancel_callback_|, assuming it is non-null.
58 void InvokePendingCancelCallback(int result
);
60 scoped_refptr
<RemoteFileSystemProxyInterface
> remote_filesystem_
;
61 const FileSystemURL url_
;
62 const int64 initial_offset_
;
63 scoped_ptr
<fileapi::FileStreamWriter
> local_file_writer_
;
64 scoped_refptr
<webkit_blob::ShareableFileReference
> file_ref_
;
65 bool has_pending_create_snapshot_
;
66 net::CompletionCallback pending_cancel_callback_
;
68 base::WeakPtrFactory
<RemoteFileStreamWriter
> weak_factory_
;
70 DISALLOW_COPY_AND_ASSIGN(RemoteFileStreamWriter
);
73 } // namespace fileapi
75 #endif // WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_STREAM_WRITER_H_