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_BLOB_LOCAL_FILE_STREAM_READER_H_ | |
6 #define WEBKIT_BLOB_LOCAL_FILE_STREAM_READER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/compiler_specific.h" | |
10 #include "base/files/file_path.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/platform_file.h" | |
13 #include "base/time.h" | |
14 #include "webkit/blob/file_stream_reader.h" | |
15 #include "webkit/storage/webkit_storage_export.h" | |
16 | |
17 namespace base { | |
18 class TaskRunner; | |
19 } | |
20 | |
21 namespace net { | |
22 class FileStream; | |
23 } | |
24 | |
25 namespace webkit_blob { | |
26 | |
27 // A thin wrapper of net::FileStream with range support for sliced file | |
28 // handling. | |
29 class WEBKIT_STORAGE_EXPORT LocalFileStreamReader : public FileStreamReader { | |
30 public: | |
31 // Creates a new FileReader for a local file |file_path|. | |
32 // |initial_offset| specifies the offset in the file where the first read | |
33 // should start. If the given offset is out of the file range any | |
34 // read operation may error out with net::ERR_REQUEST_RANGE_NOT_SATISFIABLE. | |
35 // | |
36 // |expected_modification_time| specifies the expected last modification | |
37 // If the value is non-null, the reader will check the underlying file's | |
38 // actual modification time to see if the file has been modified, and if | |
39 // it does any succeeding read operations should fail with | |
40 // ERR_UPLOAD_FILE_CHANGED error. | |
41 LocalFileStreamReader(base::TaskRunner* task_runner, | |
42 const base::FilePath& file_path, | |
43 int64 initial_offset, | |
44 const base::Time& expected_modification_time); | |
45 virtual ~LocalFileStreamReader(); | |
46 | |
47 // FileStreamReader overrides. | |
48 virtual int Read(net::IOBuffer* buf, int buf_len, | |
49 const net::CompletionCallback& callback) OVERRIDE; | |
50 virtual int64 GetLength( | |
51 const net::Int64CompletionCallback& callback) OVERRIDE; | |
52 | |
53 private: | |
54 int Open(const net::CompletionCallback& callback); | |
55 | |
56 // Callbacks that are chained from Open for Read. | |
57 void DidVerifyForOpen(const net::CompletionCallback& callback, | |
58 int64 get_length_result); | |
59 void DidOpenFileStream(const net::CompletionCallback& callback, | |
60 int result); | |
61 void DidSeekFileStream(const net::CompletionCallback& callback, | |
62 int64 seek_result); | |
63 void DidOpenForRead(net::IOBuffer* buf, | |
64 int buf_len, | |
65 const net::CompletionCallback& callback, | |
66 int open_result); | |
67 | |
68 void DidGetFileInfoForGetLength(const net::Int64CompletionCallback& callback, | |
69 base::PlatformFileError error, | |
70 const base::PlatformFileInfo& file_info); | |
71 | |
72 scoped_refptr<base::TaskRunner> task_runner_; | |
73 scoped_ptr<net::FileStream> stream_impl_; | |
74 const base::FilePath file_path_; | |
75 const int64 initial_offset_; | |
76 const base::Time expected_modification_time_; | |
77 bool has_pending_open_; | |
78 base::WeakPtrFactory<LocalFileStreamReader> weak_factory_; | |
79 }; | |
80 | |
81 } // namespace webkit_blob | |
82 | |
83 #endif // WEBKIT_BLOB_LOCAL_FILE_STREAM_READER_H_ | |
OLD | NEW |