| 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_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 "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| 11 #include "webkit/browser/webkit_storage_browser_export.h" | 11 #include "webkit/browser/webkit_storage_browser_export.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 class FilePath; | 14 class FilePath; |
| 15 class TaskRunner; | 15 class TaskRunner; |
| 16 class Time; | 16 class Time; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 class IOBuffer; | 20 class IOBuffer; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace fileapi { | 23 namespace fileapi { |
| 24 class FileSystemContext; | 24 class FileSystemContext; |
| 25 class FileSystemURL; | 25 class FileSystemURL; |
| 26 } | 26 } |
| 27 | 27 |
| 28 #if defined(OS_ANDROID) |
| 29 class GURL; |
| 30 #endif |
| 31 |
| 28 namespace webkit_blob { | 32 namespace webkit_blob { |
| 29 | 33 |
| 30 // A generic interface for reading a file-like object. | 34 // A generic interface for reading a file-like object. |
| 31 class FileStreamReader { | 35 class FileStreamReader { |
| 32 public: | 36 public: |
| 33 // Creates a new FileReader for a local file |file_path|. | 37 // Creates a new FileReader for a local file |file_path|. |
| 34 // |initial_offset| specifies the offset in the file where the first read | 38 // |initial_offset| specifies the offset in the file where the first read |
| 35 // should start. If the given offset is out of the file range any | 39 // should start. If the given offset is out of the file range any |
| 36 // read operation may error out with net::ERR_REQUEST_RANGE_NOT_SATISFIABLE. | 40 // read operation may error out with net::ERR_REQUEST_RANGE_NOT_SATISFIABLE. |
| 37 // |expected_modification_time| specifies the expected last modification | 41 // |expected_modification_time| specifies the expected last modification |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 // |expected_modification_time| specifies the expected last modification if | 53 // |expected_modification_time| specifies the expected last modification if |
| 50 // the value is non-null, the reader will check the underlying file's actual | 54 // the value is non-null, the reader will check the underlying file's actual |
| 51 // modification time to see if the file has been modified, and if it does any | 55 // modification time to see if the file has been modified, and if it does any |
| 52 // succeeding read operations should fail with ERR_UPLOAD_FILE_CHANGED error. | 56 // succeeding read operations should fail with ERR_UPLOAD_FILE_CHANGED error. |
| 53 WEBKIT_STORAGE_BROWSER_EXPORT static FileStreamReader* | 57 WEBKIT_STORAGE_BROWSER_EXPORT static FileStreamReader* |
| 54 CreateForFileSystemFile(fileapi::FileSystemContext* context, | 58 CreateForFileSystemFile(fileapi::FileSystemContext* context, |
| 55 const fileapi::FileSystemURL& url, | 59 const fileapi::FileSystemURL& url, |
| 56 int64 initial_offset, | 60 int64 initial_offset, |
| 57 const base::Time& expected_modification_time); | 61 const base::Time& expected_modification_time); |
| 58 | 62 |
| 63 #if defined(OS_ANDROID) |
| 64 // Creates a new reader for a content URL |url| form |initial_offset|. |
| 65 WEBKIT_STORAGE_BROWSER_EXPORT static FileStreamReader* |
| 66 CreateForContentUrl(base::TaskRunner* task_runner, |
| 67 const GURL& content_url, |
| 68 int64 initial_offset); |
| 69 #endif |
| 70 |
| 59 // It is valid to delete the reader at any time. If the stream is deleted | 71 // It is valid to delete the reader at any time. If the stream is deleted |
| 60 // while it has a pending read, its callback will not be called. | 72 // while it has a pending read, its callback will not be called. |
| 61 virtual ~FileStreamReader() {} | 73 virtual ~FileStreamReader() {} |
| 62 | 74 |
| 63 // Reads from the current cursor position asynchronously. | 75 // Reads from the current cursor position asynchronously. |
| 64 // | 76 // |
| 65 // Up to buf_len bytes will be copied into buf. (In other words, partial | 77 // Up to buf_len bytes will be copied into buf. (In other words, partial |
| 66 // reads are allowed.) Returns the number of bytes copied, 0 if at | 78 // reads are allowed.) Returns the number of bytes copied, 0 if at |
| 67 // end-of-file, or an error code if the operation could not be performed. | 79 // end-of-file, or an error code if the operation could not be performed. |
| 68 // If the read could not complete synchronously, then ERR_IO_PENDING is | 80 // If the read could not complete synchronously, then ERR_IO_PENDING is |
| (...skipping 15 matching lines...) Expand all Loading... |
| 84 // |callback| will not be called. | 96 // |callback| will not be called. |
| 85 // Note that the return type is int64 to return a larger file's size (a file | 97 // Note that the return type is int64 to return a larger file's size (a file |
| 86 // larger than 2G) but an error code should fit in the int range (may be | 98 // larger than 2G) but an error code should fit in the int range (may be |
| 87 // smaller than int64 range). | 99 // smaller than int64 range). |
| 88 virtual int64 GetLength(const net::Int64CompletionCallback& callback) = 0; | 100 virtual int64 GetLength(const net::Int64CompletionCallback& callback) = 0; |
| 89 }; | 101 }; |
| 90 | 102 |
| 91 } // namespace webkit_blob | 103 } // namespace webkit_blob |
| 92 | 104 |
| 93 #endif // WEBKIT_BLOB_FILE_STREAM_READER_H_ | 105 #endif // WEBKIT_BLOB_FILE_STREAM_READER_H_ |
| OLD | NEW |