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

Side by Side Diff: webkit/blob/local_file_reader.h

Issue 10038019: Add FileReader interface and implement FileSystemFileReader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 8 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
« no previous file with comments | « webkit/blob/file_reader.h ('k') | webkit/blob/local_file_reader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "net/base/completion_callback.h"
15 #include "webkit/blob/blob_export.h" 15 #include "webkit/blob/blob_export.h"
16 #include "webkit/blob/file_reader.h"
16 17
17 namespace base { 18 namespace base {
18 class MessageLoopProxy; 19 class MessageLoopProxy;
19 } 20 }
20 21
21 namespace net {
22 class FileStream;
23 class IOBuffer;
24 }
25
26 namespace webkit_blob { 22 namespace webkit_blob {
27 23
28 // 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
29 // handling. 25 // handling.
30 class BLOB_EXPORT LocalFileReader { 26 class BLOB_EXPORT LocalFileReader : public FileReader {
31 public: 27 public:
32 typedef base::Callback<void(int error, scoped_ptr<net::FileStream> stream)> 28 typedef base::Callback<void(int error, scoped_ptr<net::FileStream> stream)>
33 OpenFileStreamCallback; 29 OpenFileStreamCallback;
34 30
31 // A convenient method to translate platform file error to net error code.
32 static int PlatformFileErrorToNetError(base::PlatformFileError file_error);
33
35 // Creates a new FileReader for a local file |file_path|. 34 // Creates a new FileReader for a local file |file_path|.
36 // |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
37 // 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
38 // 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.
39 // 38 //
40 // |expected_modification_time| specifies the expected last modification 39 // |expected_modification_time| specifies the expected last modification
41 // If the value is non-null, the reader will check the underlying file's 40 // If the value is non-null, the reader will check the underlying file's
42 // actual modification time to see if the file has been modified, and if 41 // actual modification time to see if the file has been modified, and if
43 // it does any succeeding read operations should fail with 42 // it does any succeeding read operations should fail with
44 // ERR_UPLOAD_FILE_CHANGED error. 43 // ERR_UPLOAD_FILE_CHANGED error.
44 // TODO(kinuko): Consider using SequencedWorkerPool.
45 LocalFileReader(base::MessageLoopProxy* file_thread_proxy, 45 LocalFileReader(base::MessageLoopProxy* file_thread_proxy,
46 const FilePath& file_path, 46 const FilePath& file_path,
47 int64 initial_offset, 47 int64 initial_offset,
48 const base::Time& expected_modification_time); 48 const base::Time& expected_modification_time);
49 virtual ~LocalFileReader();
49 50
50 ~LocalFileReader(); 51 // FileReader overrides.
52 virtual int Read(net::IOBuffer* buf, int buf_len,
53 const net::CompletionCallback& callback) OVERRIDE;
51 54
52 // Reads from the current cursor position asynchronously. 55 // Returns the length of the file if it could successfully retrieve the
53 // This works mostly same as how net::FileStream::Read() works except that 56 // file info *and* its last modification time equals to
54 // it internally opens (and seeks) the file if it is not opened yet. 57 // expected_modification_time_ (rv >= 0 cases).
55 // It is invalid to call Read while there is an in-flight Read operation.
56 int Read(net::IOBuffer* buf, int buf_len,
57 const net::CompletionCallback& callback);
58
59 // Returns the number of bytes available to read from the beginning of
60 // the file (or initial_offset) until the end of the file (rv >= 0 cases).
61 // Otherwise, a negative error code is returned (rv < 0 cases). 58 // Otherwise, a negative error code is returned (rv < 0 cases).
62 int GetLength(const net::Int64CompletionCallback& callback); 59 int GetLength(const net::Int64CompletionCallback& callback);
63 60
64 private: 61 private:
65 class OpenFileStreamHelper; 62 class OpenFileStreamHelper;
66 63
67 int Open(const OpenFileStreamCallback& callback); 64 int Open(const OpenFileStreamCallback& callback);
68 void DidOpen(net::IOBuffer* buf, 65 void DidOpen(net::IOBuffer* buf,
69 int buf_len, 66 int buf_len,
70 const net::CompletionCallback& callback, 67 const net::CompletionCallback& callback,
71 int open_error, 68 int open_error,
72 scoped_ptr<net::FileStream> stream); 69 scoped_ptr<net::FileStream> stream);
73 70
74 scoped_refptr<base::MessageLoopProxy> file_thread_proxy_; 71 scoped_refptr<base::MessageLoopProxy> file_thread_proxy_;
75 scoped_ptr<net::FileStream> stream_impl_; 72 scoped_ptr<net::FileStream> stream_impl_;
76 const FilePath file_path_; 73 const FilePath file_path_;
77 const int64 initial_offset_; 74 const int64 initial_offset_;
78 const base::Time expected_modification_time_; 75 const base::Time expected_modification_time_;
79 bool has_pending_open_; 76 bool has_pending_open_;
80 base::WeakPtrFactory<LocalFileReader> weak_factory_; 77 base::WeakPtrFactory<LocalFileReader> weak_factory_;
81 }; 78 };
82 79
83 } // namespace webkit_blob 80 } // namespace webkit_blob
84 81
85 #endif // WEBKIT_BLOB_LOCAL_FILE_READER_H_ 82 #endif // WEBKIT_BLOB_LOCAL_FILE_READER_H_
OLDNEW
« no previous file with comments | « webkit/blob/file_reader.h ('k') | webkit/blob/local_file_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698