blob: 49a2360c1f76f3f3faf918e9e6da29d9b2200daf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_STREAM_WRITER_H_
#define WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_STREAM_WRITER_H_
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/platform_file.h"
#include "webkit/fileapi/file_stream_writer.h"
#include "webkit/fileapi/file_system_url.h"
namespace net {
class IOBuffer;
}
namespace webkit_blob {
class ShareableFileReference;
}
namespace fileapi {
class RemoteFileSystemProxyInterface;
// FileStreamWriter interface for writing to a file on remote file system.
class RemoteFileStreamWriter : public fileapi::FileStreamWriter {
public:
// Creates a writer for a file on |remote_filesystem| with path url |url|
// (like "filesystem:chrome-extension://id/external/special/drive/...") that
// starts writing from |offset|. When invalid parameters are set, the first
// call to Write() method fails.
RemoteFileStreamWriter(
const scoped_refptr<RemoteFileSystemProxyInterface>& remote_filesystem,
const FileSystemURL& url,
int64 offset);
virtual ~RemoteFileStreamWriter();
// FileWriter override.
virtual int Write(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;
virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE;
virtual int Flush(const net::CompletionCallback& callback) OVERRIDE;
private:
// Callback function to do the continuation of the work of the first Write()
// call, which tries to open the local copy of the file before writing.
void OnFileOpened(
net::IOBuffer* buf,
int buf_len,
const net::CompletionCallback& callback,
base::PlatformFileError open_result,
const base::FilePath& local_path,
const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref);
// Calls |pending_cancel_callback_|, assuming it is non-null.
void InvokePendingCancelCallback(int result);
scoped_refptr<RemoteFileSystemProxyInterface> remote_filesystem_;
const FileSystemURL url_;
const int64 initial_offset_;
scoped_ptr<fileapi::FileStreamWriter> local_file_writer_;
scoped_refptr<webkit_blob::ShareableFileReference> file_ref_;
bool has_pending_create_snapshot_;
net::CompletionCallback pending_cancel_callback_;
base::WeakPtrFactory<RemoteFileStreamWriter> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(RemoteFileStreamWriter);
};
} // namespace fileapi
#endif // WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_STREAM_WRITER_H_
|