Don't allow path traversal paths on the base file helpers
[chromium-blink-merge.git] / webkit / chromeos / fileapi / remote_file_stream_writer.h
blobcf341bd3347806e210c94f8a1b944dc74a81db8c
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/file_path.h"
10 #include "base/platform_file.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "webkit/fileapi/file_stream_writer.h"
14 #include "webkit/fileapi/file_system_url.h"
16 namespace net {
17 class IOBuffer;
20 namespace webkit_blob {
21 class ShareableFileReference;
24 namespace fileapi {
26 class RemoteFileSystemProxyInterface;
28 // FileStreamWriter interface for writing to a file on remote file system.
29 class RemoteFileStreamWriter : public fileapi::FileStreamWriter {
30 public:
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,
38 int64 offset);
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;
47 private:
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.
50 void OnFileOpened(
51 net::IOBuffer* buf,
52 int buf_len,
53 const net::CompletionCallback& callback,
54 base::PlatformFileError open_result,
55 const 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_