OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_ |
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_ |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| 11 #include "base/time.h" |
11 #include "webkit/fileapi/file_system_url.h" | 12 #include "webkit/fileapi/file_system_url.h" |
| 13 #include "webkit/fileapi/fileapi_export.h" |
12 #include "webkit/blob/file_stream_reader.h" | 14 #include "webkit/blob/file_stream_reader.h" |
13 #include "webkit/blob/shareable_file_reference.h" | 15 #include "webkit/blob/shareable_file_reference.h" |
14 | 16 |
15 class FilePath; | 17 class FilePath; |
16 | 18 |
17 namespace base { | 19 namespace base { |
18 class SequencedTaskRunner; | 20 class SequencedTaskRunner; |
19 } | 21 } |
20 | 22 |
21 namespace webkit_blob { | 23 namespace webkit_blob { |
22 class LocalFileStreamReader; | 24 class LocalFileStreamReader; |
23 } | 25 } |
24 | 26 |
25 namespace fileapi { | 27 namespace fileapi { |
26 | 28 |
27 class FileSystemContext; | 29 class FileSystemContext; |
28 | 30 |
29 // TODO(kinaba,satorux): This generic implementation would work for any | 31 // TODO(kinaba,satorux): This generic implementation would work for any |
30 // filesystems but remote filesystem should implement its own reader | 32 // filesystems but remote filesystem should implement its own reader |
31 // rather than relying on FileSystemOperation::GetSnapshotFile() which | 33 // rather than relying on FileSystemOperation::GetSnapshotFile() which |
32 // may force downloading the entire contents for remote files. | 34 // may force downloading the entire contents for remote files. |
33 class FileSystemFileStreamReader : public webkit_blob::FileStreamReader { | 35 class FILEAPI_EXPORT_PRIVATE FileSystemFileStreamReader |
| 36 : public webkit_blob::FileStreamReader { |
34 public: | 37 public: |
35 // Creates a new FileReader for a filesystem URL |url| form |initial_offset|. | 38 // Creates a new FileReader for a filesystem URL |url| form |initial_offset|. |
| 39 // |expected_modification_time| specifies the expected last modification if |
| 40 // the value is non-null, the reader will check the underlying file's actual |
| 41 // modification time to see if the file has been modified, and if it does any |
| 42 // succeeding read operations should fail with ERR_UPLOAD_FILE_CHANGED error. |
36 FileSystemFileStreamReader(FileSystemContext* file_system_context, | 43 FileSystemFileStreamReader(FileSystemContext* file_system_context, |
37 const FileSystemURL& url, | 44 const FileSystemURL& url, |
38 int64 initial_offset); | 45 int64 initial_offset, |
| 46 const base::Time& expected_modification_time); |
39 virtual ~FileSystemFileStreamReader(); | 47 virtual ~FileSystemFileStreamReader(); |
40 | 48 |
41 // FileStreamReader overrides. | 49 // FileStreamReader overrides. |
42 virtual int Read(net::IOBuffer* buf, int buf_len, | 50 virtual int Read(net::IOBuffer* buf, int buf_len, |
43 const net::CompletionCallback& callback) OVERRIDE; | 51 const net::CompletionCallback& callback) OVERRIDE; |
44 virtual int GetLength( | 52 virtual int GetLength( |
45 const net::Int64CompletionCallback& callback) OVERRIDE; | 53 const net::Int64CompletionCallback& callback) OVERRIDE; |
46 | 54 |
47 private: | 55 private: |
48 int CreateSnapshot(const base::Closure& callback, | 56 int CreateSnapshot(const base::Closure& callback, |
49 const net::CompletionCallback& error_callback); | 57 const net::CompletionCallback& error_callback); |
50 void DidCreateSnapshot( | 58 void DidCreateSnapshot( |
51 const base::Closure& callback, | 59 const base::Closure& callback, |
52 const net::CompletionCallback& error_callback, | 60 const net::CompletionCallback& error_callback, |
53 base::PlatformFileError file_error, | 61 base::PlatformFileError file_error, |
54 const base::PlatformFileInfo& file_info, | 62 const base::PlatformFileInfo& file_info, |
55 const FilePath& platform_path, | 63 const FilePath& platform_path, |
56 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | 64 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); |
57 | 65 |
58 scoped_refptr<FileSystemContext> file_system_context_; | 66 scoped_refptr<FileSystemContext> file_system_context_; |
59 FileSystemURL url_; | 67 FileSystemURL url_; |
60 const int64 initial_offset_; | 68 const int64 initial_offset_; |
| 69 const base::Time expected_modification_time_; |
61 scoped_ptr<webkit_blob::LocalFileStreamReader> local_file_reader_; | 70 scoped_ptr<webkit_blob::LocalFileStreamReader> local_file_reader_; |
62 scoped_refptr<webkit_blob::ShareableFileReference> snapshot_ref_; | 71 scoped_refptr<webkit_blob::ShareableFileReference> snapshot_ref_; |
63 bool has_pending_create_snapshot_; | 72 bool has_pending_create_snapshot_; |
64 base::WeakPtrFactory<FileSystemFileStreamReader> weak_factory_; | 73 base::WeakPtrFactory<FileSystemFileStreamReader> weak_factory_; |
65 | 74 |
66 DISALLOW_COPY_AND_ASSIGN(FileSystemFileStreamReader); | 75 DISALLOW_COPY_AND_ASSIGN(FileSystemFileStreamReader); |
67 }; | 76 }; |
68 | 77 |
69 } // namespace fileapi | 78 } // namespace fileapi |
70 | 79 |
71 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_ | 80 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_ |
OLD | NEW |