OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_STREAM_WRITER_H_ | |
6 #define WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_STREAM_WRITER_H_ | |
7 | |
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/browser/fileapi/file_stream_writer.h" | |
14 #include "webkit/browser/fileapi/file_system_url.h" | |
15 | |
16 namespace net { | |
17 class IOBuffer; | |
18 } | |
19 | |
20 namespace webkit_blob { | |
21 class ShareableFileReference; | |
22 } | |
23 | |
24 namespace fileapi { | |
25 | |
26 class RemoteFileSystemProxyInterface; | |
27 | |
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(); | |
40 | |
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; | |
46 | |
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 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); | |
59 | |
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_; | |
67 | |
68 base::WeakPtrFactory<RemoteFileStreamWriter> weak_factory_; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(RemoteFileStreamWriter); | |
71 }; | |
72 | |
73 } // namespace fileapi | |
74 | |
75 #endif // WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_STREAM_WRITER_H_ | |
OLD | NEW |