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_FILE_SYSTEM_FILE_STREAM_READER_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_
9 #include "base/memory/ref_counted.h"
10 #include "base/platform_file.h"
11 #include "webkit/fileapi/file_system_url.h"
12 #include "webkit/blob/file_stream_reader.h"
13 #include "webkit/blob/shareable_file_reference.h"
18 class SequencedTaskRunner
;
21 namespace webkit_blob
{
22 class LocalFileStreamReader
;
27 class FileSystemContext
;
29 // TODO(kinaba,satorux): This generic implementation would work for any
30 // filesystems but remote filesystem should implement its own reader
31 // rather than relying on FileSystemOperation::GetSnapshotFile() which
32 // may force downloading the entire contents for remote files.
33 class FileSystemFileStreamReader
: public webkit_blob::FileStreamReader
{
35 // Creates a new FileReader for a filesystem URL |url| form |initial_offset|.
36 FileSystemFileStreamReader(FileSystemContext
* file_system_context
,
37 const FileSystemURL
& url
,
38 int64 initial_offset
);
39 virtual ~FileSystemFileStreamReader();
41 // FileReader override.
42 virtual int Read(net::IOBuffer
* buf
, int buf_len
,
43 const net::CompletionCallback
& callback
) OVERRIDE
;
46 void DidCreateSnapshot(
47 const base::Closure
& read_closure
,
48 const net::CompletionCallback
& callback
,
49 base::PlatformFileError file_error
,
50 const base::PlatformFileInfo
& file_info
,
51 const FilePath
& platform_path
,
52 const scoped_refptr
<webkit_blob::ShareableFileReference
>& file_ref
);
54 scoped_refptr
<FileSystemContext
> file_system_context_
;
56 const int64 initial_offset_
;
57 scoped_ptr
<webkit_blob::LocalFileStreamReader
> local_file_reader_
;
58 scoped_refptr
<webkit_blob::ShareableFileReference
> snapshot_ref_
;
59 bool has_pending_create_snapshot_
;
60 base::WeakPtrFactory
<FileSystemFileStreamReader
> weak_factory_
;
62 DISALLOW_COPY_AND_ASSIGN(FileSystemFileStreamReader
);
65 } // namespace fileapi
67 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_