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_LOCAL_FILE_READER_H_ | 5 #ifndef WEBKIT_BLOB_LOCAL_FILE_READER_H_ |
6 #define WEBKIT_BLOB_LOCAL_FILE_READER_H_ | 6 #define WEBKIT_BLOB_LOCAL_FILE_READER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "webkit/blob/blob_export.h" | 15 #include "webkit/blob/blob_export.h" |
16 #include "webkit/blob/file_reader.h" | 16 #include "webkit/blob/file_reader.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class MessageLoopProxy; | 19 class TaskRunner; |
20 } | 20 } |
21 | 21 |
22 namespace webkit_blob { | 22 namespace webkit_blob { |
23 | 23 |
24 // A thin wrapper of net::FileStream with range support for sliced file | 24 // A thin wrapper of net::FileStream with range support for sliced file |
25 // handling. | 25 // handling. |
26 class BLOB_EXPORT LocalFileReader : public FileReader { | 26 class BLOB_EXPORT LocalFileReader : public FileReader { |
27 public: | 27 public: |
28 // A convenient method to translate platform file error to net error code. | 28 // A convenient method to translate platform file error to net error code. |
29 static int PlatformFileErrorToNetError(base::PlatformFileError file_error); | 29 static int PlatformFileErrorToNetError(base::PlatformFileError file_error); |
30 | 30 |
31 // Creates a new FileReader for a local file |file_path|. | 31 // Creates a new FileReader for a local file |file_path|. |
32 // |initial_offset| specifies the offset in the file where the first read | 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 | 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. | 34 // read operation may error out with net::ERR_REQUEST_RANGE_NOT_SATISFIABLE. |
35 // | 35 // |
36 // |expected_modification_time| specifies the expected last modification | 36 // |expected_modification_time| specifies the expected last modification |
37 // If the value is non-null, the reader will check the underlying file's | 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 | 38 // actual modification time to see if the file has been modified, and if |
39 // it does any succeeding read operations should fail with | 39 // it does any succeeding read operations should fail with |
40 // ERR_UPLOAD_FILE_CHANGED error. | 40 // ERR_UPLOAD_FILE_CHANGED error. |
41 // TODO(kinuko): Consider using SequencedWorkerPool. | 41 LocalFileReader(base::TaskRunner* task_runner, |
42 LocalFileReader(base::MessageLoopProxy* file_thread_proxy, | |
43 const FilePath& file_path, | 42 const FilePath& file_path, |
44 int64 initial_offset, | 43 int64 initial_offset, |
45 const base::Time& expected_modification_time); | 44 const base::Time& expected_modification_time); |
46 virtual ~LocalFileReader(); | 45 virtual ~LocalFileReader(); |
47 | 46 |
48 // FileReader overrides. | 47 // FileReader overrides. |
49 virtual int Read(net::IOBuffer* buf, int buf_len, | 48 virtual int Read(net::IOBuffer* buf, int buf_len, |
50 const net::CompletionCallback& callback) OVERRIDE; | 49 const net::CompletionCallback& callback) OVERRIDE; |
51 | 50 |
52 // Returns the length of the file if it could successfully retrieve the | 51 // Returns the length of the file if it could successfully retrieve the |
(...skipping 16 matching lines...) Expand all Loading... |
69 int64 seek_result); | 68 int64 seek_result); |
70 void DidOpenForRead(net::IOBuffer* buf, | 69 void DidOpenForRead(net::IOBuffer* buf, |
71 int buf_len, | 70 int buf_len, |
72 const net::CompletionCallback& callback, | 71 const net::CompletionCallback& callback, |
73 int open_result); | 72 int open_result); |
74 | 73 |
75 void DidGetFileInfoForGetLength(const net::Int64CompletionCallback& callback, | 74 void DidGetFileInfoForGetLength(const net::Int64CompletionCallback& callback, |
76 base::PlatformFileError error, | 75 base::PlatformFileError error, |
77 const base::PlatformFileInfo& file_info); | 76 const base::PlatformFileInfo& file_info); |
78 | 77 |
79 scoped_refptr<base::MessageLoopProxy> file_thread_proxy_; | 78 scoped_refptr<base::TaskRunner> task_runner_; |
80 scoped_ptr<net::FileStream> stream_impl_; | 79 scoped_ptr<net::FileStream> stream_impl_; |
81 const FilePath file_path_; | 80 const FilePath file_path_; |
82 const int64 initial_offset_; | 81 const int64 initial_offset_; |
83 const base::Time expected_modification_time_; | 82 const base::Time expected_modification_time_; |
84 bool has_pending_open_; | 83 bool has_pending_open_; |
85 base::WeakPtrFactory<LocalFileReader> weak_factory_; | 84 base::WeakPtrFactory<LocalFileReader> weak_factory_; |
86 }; | 85 }; |
87 | 86 |
88 } // namespace webkit_blob | 87 } // namespace webkit_blob |
89 | 88 |
90 #endif // WEBKIT_BLOB_LOCAL_FILE_READER_H_ | 89 #endif // WEBKIT_BLOB_LOCAL_FILE_READER_H_ |
OLD | NEW |