OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_FILE_STREAM_READER_ H_ | |
6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_FILE_STREAM_READER_ H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/files/file_path.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "webkit/browser/blob/file_stream_reader.h" | |
12 #include "webkit/browser/fileapi/file_system_url.h" | |
13 | |
14 namespace fileapi { | |
15 class AsyncFileUtil; | |
16 } // namespace fileapi | |
17 | |
18 namespace chromeos { | |
19 namespace file_system_provider { | |
20 | |
21 class ProvidedFileSystemInterface; | |
22 | |
23 // Implements a streamed file reader. It is lazily initialized by the first call | |
24 // to Read(). | |
25 class FileStreamReader : public webkit_blob::FileStreamReader { | |
26 public: | |
27 typedef base::Callback< | |
28 void(base::WeakPtr<ProvidedFileSystemInterface> file_system, | |
29 const base::FilePath& file_path, | |
30 int file_handle, | |
31 base::File::Error result)> InitializeCompletedCallback; | |
32 | |
33 FileStreamReader(fileapi::FileSystemContext* context, | |
34 const fileapi::FileSystemURL& url, | |
35 int64 initial_offset, | |
36 const base::Time& expected_modification_time); | |
37 | |
38 virtual ~FileStreamReader(); | |
39 | |
40 // webkit_blob::FileStreamReader overrides. | |
41 virtual int Read(net::IOBuffer* buf, | |
42 int buf_len, | |
43 const net::CompletionCallback& callback) OVERRIDE; | |
44 virtual int64 GetLength( | |
45 const net::Int64CompletionCallback& callback) OVERRIDE; | |
46 | |
47 private: | |
48 // Initializes the reader by opening the file. When completed with success, | |
49 // runs the |pending_closure|. Otherwise, calls the |error_callback|. | |
50 void Initialize(const base::Closure& pending_closure, | |
51 const net::Int64CompletionCallback& error_callback); | |
52 | |
53 // Called when initializing is completed with either a success or an error. | |
54 void OnInitializeCompleted( | |
55 const base::Closure& pending_closure, | |
56 const net::Int64CompletionCallback& error_callback, | |
57 base::WeakPtr<ProvidedFileSystemInterface> file_system, | |
58 const base::FilePath& file_path, | |
59 int file_handle, | |
60 base::File::Error result); | |
61 | |
62 // Called when a file system provider returns chunk of read data. Note, that | |
63 // this may be called multiple times per single Read() call, as long as | |
64 // |has_next| is set to true. |result| is set to success only if reading is | |
65 // successful, and the file has not changed while reading. | |
66 void OnReadChunkReceived(const net::CompletionCallback& callback, | |
67 int chunk_length, | |
68 bool has_next, | |
69 base::File::Error result); | |
70 | |
71 // Called when fetching length of the file is completed with either a success | |
72 // or an error. | |
73 void OnGetMetadataForGetLengthReceived( | |
74 const net::Int64CompletionCallback& callback, | |
75 base::File::Error result, | |
76 const base::File::Info& file_info); | |
77 | |
78 // Same as Read(), but called after initializing is completed. | |
79 void ReadAfterInitialized(net::IOBuffer* buffer, | |
80 int buffer_length, | |
81 const net::CompletionCallback& callback); | |
82 | |
83 // Same as GetLength(), but called after initializing is completed. | |
84 void GetLengthAfterInitialized(const net::Int64CompletionCallback& callback); | |
85 | |
86 fileapi::FileSystemContext* context_; | |
kinaba
2014/05/16 07:58:00
Will this be used in future patches?
mtomasz
2014/05/16 09:18:20
Nope. Removed.
| |
87 fileapi::FileSystemURL url_; | |
88 int64 current_offset_; | |
89 int64 current_length_; | |
90 base::Time expected_modification_time_; | |
91 | |
92 // Set during initialization (in case of a success). | |
93 base::WeakPtr<ProvidedFileSystemInterface> file_system_; | |
94 base::FilePath file_path_; | |
95 int file_handle_; | |
96 | |
97 base::WeakPtrFactory<FileStreamReader> weak_ptr_factory_; | |
98 DISALLOW_COPY_AND_ASSIGN(FileStreamReader); | |
99 }; | |
100 | |
101 } // namespace file_system_provider | |
102 } // namespace chromeos | |
103 | |
104 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_FILE_STREAM_READ ER_H_ | |
OLD | NEW |