Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: storage/browser/blob/file_stream_reader.h

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_BLOB_FILE_STREAM_READER_H_ 5 #ifndef WEBKIT_BLOB_FILE_STREAM_READER_H_
6 #define WEBKIT_BLOB_FILE_STREAM_READER_H_ 6 #define WEBKIT_BLOB_FILE_STREAM_READER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "net/base/completion_callback.h" 11 #include "net/base/completion_callback.h"
12 #include "webkit/browser/webkit_storage_browser_export.h" 12 #include "storage/common/storage_export.h"
13 13
14 namespace base { 14 namespace base {
15 class FilePath; 15 class FilePath;
16 class TaskRunner; 16 class TaskRunner;
17 class Time; 17 class Time;
18 } 18 }
19 19
20 namespace net { 20 namespace net {
21 class IOBuffer; 21 class IOBuffer;
22 } 22 }
23 23
24 namespace fileapi { 24 namespace storage {
25 class FileSystemContext; 25 class FileSystemContext;
26 class FileSystemURL; 26 class FileSystemURL;
27 } 27 }
28 28
29 namespace webkit_blob { 29 namespace storage {
30 30
31 // A generic interface for reading a file-like object. 31 // A generic interface for reading a file-like object.
32 class FileStreamReader { 32 class FileStreamReader {
33 public: 33 public:
34 // Creates a new FileReader for a local file |file_path|. 34 // Creates a new FileReader for a local file |file_path|.
35 // |initial_offset| specifies the offset in the file where the first read 35 // |initial_offset| specifies the offset in the file where the first read
36 // should start. If the given offset is out of the file range any 36 // should start. If the given offset is out of the file range any
37 // read operation may error out with net::ERR_REQUEST_RANGE_NOT_SATISFIABLE. 37 // read operation may error out with net::ERR_REQUEST_RANGE_NOT_SATISFIABLE.
38 // |expected_modification_time| specifies the expected last modification 38 // |expected_modification_time| specifies the expected last modification
39 // If the value is non-null, the reader will check the underlying file's 39 // If the value is non-null, the reader will check the underlying file's
40 // actual modification time to see if the file has been modified, and if 40 // actual modification time to see if the file has been modified, and if
41 // it does any succeeding read operations should fail with 41 // it does any succeeding read operations should fail with
42 // ERR_UPLOAD_FILE_CHANGED error. 42 // ERR_UPLOAD_FILE_CHANGED error.
43 WEBKIT_STORAGE_BROWSER_EXPORT static FileStreamReader* 43 STORAGE_EXPORT static FileStreamReader* CreateForLocalFile(
44 CreateForLocalFile(base::TaskRunner* task_runner, 44 base::TaskRunner* task_runner,
45 const base::FilePath& file_path, 45 const base::FilePath& file_path,
46 int64 initial_offset, 46 int64 initial_offset,
47 const base::Time& expected_modification_time); 47 const base::Time& expected_modification_time);
48 48
49 // Creates a new reader for a filesystem URL |url| form |initial_offset|. 49 // Creates a new reader for a filesystem URL |url| form |initial_offset|.
50 // |expected_modification_time| specifies the expected last modification if 50 // |expected_modification_time| specifies the expected last modification if
51 // the value is non-null, the reader will check the underlying file's actual 51 // the value is non-null, the reader will check the underlying file's actual
52 // modification time to see if the file has been modified, and if it does any 52 // modification time to see if the file has been modified, and if it does any
53 // succeeding read operations should fail with ERR_UPLOAD_FILE_CHANGED error. 53 // succeeding read operations should fail with ERR_UPLOAD_FILE_CHANGED error.
54 WEBKIT_STORAGE_BROWSER_EXPORT static FileStreamReader* 54 STORAGE_EXPORT static FileStreamReader* CreateForFileSystemFile(
55 CreateForFileSystemFile(fileapi::FileSystemContext* context, 55 storage::FileSystemContext* context,
56 const fileapi::FileSystemURL& url, 56 const storage::FileSystemURL& url,
57 int64 initial_offset, 57 int64 initial_offset,
58 const base::Time& expected_modification_time); 58 const base::Time& expected_modification_time);
59 59
60 // Verify if the underlying file has not been modified. 60 // Verify if the underlying file has not been modified.
61 WEBKIT_STORAGE_BROWSER_EXPORT static bool VerifySnapshotTime( 61 STORAGE_EXPORT static bool VerifySnapshotTime(
62 const base::Time& expected_modification_time, 62 const base::Time& expected_modification_time,
63 const base::File::Info& file_info); 63 const base::File::Info& file_info);
64 64
65 // It is valid to delete the reader at any time. If the stream is deleted 65 // It is valid to delete the reader at any time. If the stream is deleted
66 // while it has a pending read, its callback will not be called. 66 // while it has a pending read, its callback will not be called.
67 virtual ~FileStreamReader() {} 67 virtual ~FileStreamReader() {}
68 68
69 // Reads from the current cursor position asynchronously. 69 // Reads from the current cursor position asynchronously.
70 // 70 //
71 // Up to buf_len bytes will be copied into buf. (In other words, partial 71 // Up to buf_len bytes will be copied into buf. (In other words, partial
72 // reads are allowed.) Returns the number of bytes copied, 0 if at 72 // reads are allowed.) Returns the number of bytes copied, 0 if at
73 // end-of-file, or an error code if the operation could not be performed. 73 // end-of-file, or an error code if the operation could not be performed.
74 // If the read could not complete synchronously, then ERR_IO_PENDING is 74 // If the read could not complete synchronously, then ERR_IO_PENDING is
75 // returned, and the callback will be run on the thread where Read() 75 // returned, and the callback will be run on the thread where Read()
76 // was called, when the read has completed. 76 // was called, when the read has completed.
77 // 77 //
78 // It is invalid to call Read while there is an in-flight Read operation. 78 // It is invalid to call Read while there is an in-flight Read operation.
79 // 79 //
80 // If the stream is deleted while it has an in-flight Read operation 80 // If the stream is deleted while it has an in-flight Read operation
81 // |callback| will not be called. 81 // |callback| will not be called.
82 virtual int Read(net::IOBuffer* buf, int buf_len, 82 virtual int Read(net::IOBuffer* buf,
83 int buf_len,
83 const net::CompletionCallback& callback) = 0; 84 const net::CompletionCallback& callback) = 0;
84 85
85 // Returns the length of the file if it could successfully retrieve the 86 // Returns the length of the file if it could successfully retrieve the
86 // file info *and* its last modification time equals to 87 // file info *and* its last modification time equals to
87 // expected modification time (rv >= 0 cases). 88 // expected modification time (rv >= 0 cases).
88 // Otherwise, a negative error code is returned (rv < 0 cases). 89 // Otherwise, a negative error code is returned (rv < 0 cases).
89 // If the stream is deleted while it has an in-flight GetLength operation 90 // If the stream is deleted while it has an in-flight GetLength operation
90 // |callback| will not be called. 91 // |callback| will not be called.
91 // Note that the return type is int64 to return a larger file's size (a file 92 // Note that the return type is int64 to return a larger file's size (a file
92 // larger than 2G) but an error code should fit in the int range (may be 93 // larger than 2G) but an error code should fit in the int range (may be
93 // smaller than int64 range). 94 // smaller than int64 range).
94 virtual int64 GetLength(const net::Int64CompletionCallback& callback) = 0; 95 virtual int64 GetLength(const net::Int64CompletionCallback& callback) = 0;
95 }; 96 };
96 97
97 } // namespace webkit_blob 98 } // namespace storage
98 99
99 #endif // WEBKIT_BLOB_FILE_STREAM_READER_H_ 100 #endif // WEBKIT_BLOB_FILE_STREAM_READER_H_
OLDNEW
« no previous file with comments | « storage/browser/blob/blob_url_request_job_factory.cc ('k') | storage/browser/blob/file_stream_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698