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 #include "webkit/blob/local_file_reader.h" | 5 #include "webkit/blob/local_file_reader.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/file_util_proxy.h" | 8 #include "base/file_util_proxy.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 // Verify if the underlying file has not been modified. | 37 // Verify if the underlying file has not been modified. |
38 bool VerifySnapshotTime(const base::Time& expected_modification_time, | 38 bool VerifySnapshotTime(const base::Time& expected_modification_time, |
39 const base::PlatformFileInfo& file_info) { | 39 const base::PlatformFileInfo& file_info) { |
40 return expected_modification_time.is_null() || | 40 return expected_modification_time.is_null() || |
41 expected_modification_time.ToTimeT() == | 41 expected_modification_time.ToTimeT() == |
42 file_info.last_modified.ToTimeT(); | 42 file_info.last_modified.ToTimeT(); |
43 } | 43 } |
44 | 44 |
45 void DidGetFileInfoForGetLength(const net::CompletionCallback& callback, | 45 void DidGetFileInfoForGetLength(const net::Int64CompletionCallback& callback, |
46 const base::Time& expected_modification_time, | 46 const base::Time& expected_modification_time, |
47 int64 initial_offset, | 47 int64 initial_offset, |
48 base::PlatformFileError error, | 48 base::PlatformFileError error, |
49 const base::PlatformFileInfo& file_info) { | 49 const base::PlatformFileInfo& file_info) { |
50 if (file_info.is_directory) { | 50 if (file_info.is_directory) { |
51 callback.Run(net::ERR_FILE_NOT_FOUND); | 51 callback.Run(net::ERR_FILE_NOT_FOUND); |
52 return; | 52 return; |
53 } | 53 } |
54 if (error != base::PLATFORM_FILE_OK) { | 54 if (error != base::PLATFORM_FILE_OK) { |
55 callback.Run(PlatformFileErrorToNetError(error)); | 55 callback.Run(PlatformFileErrorToNetError(error)); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 int LocalFileReader::Read(net::IOBuffer* buf, int buf_len, | 163 int LocalFileReader::Read(net::IOBuffer* buf, int buf_len, |
164 const net::CompletionCallback& callback) { | 164 const net::CompletionCallback& callback) { |
165 DCHECK(!has_pending_open_); | 165 DCHECK(!has_pending_open_); |
166 if (stream_impl_.get()) | 166 if (stream_impl_.get()) |
167 return stream_impl_->Read(buf, buf_len, callback); | 167 return stream_impl_->Read(buf, buf_len, callback); |
168 return Open(base::Bind(&LocalFileReader::DidOpen, weak_factory_.GetWeakPtr(), | 168 return Open(base::Bind(&LocalFileReader::DidOpen, weak_factory_.GetWeakPtr(), |
169 make_scoped_refptr(buf), buf_len, callback)); | 169 make_scoped_refptr(buf), buf_len, callback)); |
170 } | 170 } |
171 | 171 |
172 int LocalFileReader::GetLength(const net::CompletionCallback& callback) { | 172 int LocalFileReader::GetLength(const net::Int64CompletionCallback& callback) { |
173 const bool posted = base::FileUtilProxy::GetFileInfo( | 173 const bool posted = base::FileUtilProxy::GetFileInfo( |
174 file_thread_proxy_, file_path_, | 174 file_thread_proxy_, file_path_, |
175 base::Bind(&DidGetFileInfoForGetLength, callback, | 175 base::Bind(&DidGetFileInfoForGetLength, callback, |
176 expected_modification_time_, initial_offset_)); | 176 expected_modification_time_, initial_offset_)); |
177 DCHECK(posted); | 177 DCHECK(posted); |
178 return net::ERR_IO_PENDING; | 178 return net::ERR_IO_PENDING; |
179 } | 179 } |
180 | 180 |
181 int LocalFileReader::Open(const OpenFileStreamCallback& callback) { | 181 int LocalFileReader::Open(const OpenFileStreamCallback& callback) { |
182 DCHECK(!has_pending_open_); | 182 DCHECK(!has_pending_open_); |
(...skipping 24 matching lines...) Expand all Loading... |
207 return; | 207 return; |
208 } | 208 } |
209 DCHECK(stream_impl.get()); | 209 DCHECK(stream_impl.get()); |
210 stream_impl_ = stream_impl.Pass(); | 210 stream_impl_ = stream_impl.Pass(); |
211 const int read_error = stream_impl_->Read(buf, buf_len, callback); | 211 const int read_error = stream_impl_->Read(buf, buf_len, callback); |
212 if (read_error != net::ERR_IO_PENDING) | 212 if (read_error != net::ERR_IO_PENDING) |
213 callback.Run(read_error); | 213 callback.Run(read_error); |
214 } | 214 } |
215 | 215 |
216 } // namespace webkit_blob | 216 } // namespace webkit_blob |
OLD | NEW |