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/fileapi/file_system_file_stream_reader.h" | 5 #include "webkit/fileapi/file_system_file_stream_reader.h" |
6 | 6 |
7 #include "base/file_util_proxy.h" | 7 #include "base/file_util_proxy.h" |
8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
9 #include "base/sequenced_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "net/base/file_stream.h" | 10 #include "net/base/file_stream.h" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "webkit/blob/local_file_stream_reader.h" | 13 #include "webkit/blob/local_file_stream_reader.h" |
14 #include "webkit/fileapi/file_system_context.h" | 14 #include "webkit/fileapi/file_system_context.h" |
15 #include "webkit/fileapi/file_system_operation_interface.h" | 15 #include "webkit/fileapi/file_system_operation_interface.h" |
| 16 #include "webkit/fileapi/file_system_task_runners.h" |
16 | 17 |
17 using webkit_blob::LocalFileStreamReader; | 18 using webkit_blob::LocalFileStreamReader; |
18 | 19 |
19 namespace fileapi { | 20 namespace fileapi { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 void ReadAdapter(base::WeakPtr<FileSystemFileStreamReader> reader, | 24 void ReadAdapter(base::WeakPtr<FileSystemFileStreamReader> reader, |
24 net::IOBuffer* buf, int buf_len, | 25 net::IOBuffer* buf, int buf_len, |
25 const net::CompletionCallback& callback) { | 26 const net::CompletionCallback& callback) { |
26 if (!reader.get()) | 27 if (!reader.get()) |
27 return; | 28 return; |
28 int rv = reader->Read(buf, buf_len, callback); | 29 int rv = reader->Read(buf, buf_len, callback); |
29 if (rv != net::ERR_IO_PENDING) | 30 if (rv != net::ERR_IO_PENDING) |
30 callback.Run(rv); | 31 callback.Run(rv); |
31 } | 32 } |
32 | 33 |
33 } | 34 } // namespace |
34 | 35 |
35 FileSystemFileStreamReader::FileSystemFileStreamReader( | 36 FileSystemFileStreamReader::FileSystemFileStreamReader( |
36 FileSystemContext* file_system_context, | 37 FileSystemContext* file_system_context, |
37 const FileSystemURL& url, | 38 const FileSystemURL& url, |
38 int64 initial_offset) | 39 int64 initial_offset) |
39 : file_system_context_(file_system_context), | 40 : file_system_context_(file_system_context), |
40 url_(url), | 41 url_(url), |
41 initial_offset_(initial_offset), | 42 initial_offset_(initial_offset), |
42 has_pending_create_snapshot_(false), | 43 has_pending_create_snapshot_(false), |
43 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 44 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 81 |
81 if (file_error != base::PLATFORM_FILE_OK) { | 82 if (file_error != base::PLATFORM_FILE_OK) { |
82 callback.Run(net::PlatformFileErrorToNetError(file_error)); | 83 callback.Run(net::PlatformFileErrorToNetError(file_error)); |
83 return; | 84 return; |
84 } | 85 } |
85 | 86 |
86 // Keep the reference (if it's non-null) so that the file won't go away. | 87 // Keep the reference (if it's non-null) so that the file won't go away. |
87 snapshot_ref_ = file_ref; | 88 snapshot_ref_ = file_ref; |
88 | 89 |
89 local_file_reader_.reset( | 90 local_file_reader_.reset( |
90 new LocalFileStreamReader(file_system_context_->file_task_runner(), | 91 new LocalFileStreamReader( |
91 platform_path, | 92 file_system_context_->task_runners()->file_task_runner(), |
92 initial_offset_, | 93 platform_path, initial_offset_, base::Time())); |
93 base::Time())); | |
94 | 94 |
95 read_closure.Run(); | 95 read_closure.Run(); |
96 } | 96 } |
97 | 97 |
98 } // namespace fileapi | 98 } // namespace fileapi |
OLD | NEW |