| 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/browser/fileapi/file_system_file_stream_reader.h" | 5 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" |
| 6 | 6 |
| 7 #include "base/files/file_util_proxy.h" | 7 #include "base/files/file_util_proxy.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "net/base/file_stream.h" | 9 #include "net/base/file_stream.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "webkit/browser/blob/file_stream_reader.h" | 12 #include "webkit/browser/blob/file_stream_reader.h" |
| 13 #include "webkit/browser/fileapi/file_system_context.h" | 13 #include "webkit/browser/fileapi/file_system_context.h" |
| 14 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 14 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 15 | 15 |
| 16 using webkit_blob::FileStreamReader; | 16 using storage::FileStreamReader; |
| 17 | 17 |
| 18 // TODO(kinuko): Remove this temporary namespace hack after we move both | 18 // TODO(kinuko): Remove this temporary namespace hack after we move both |
| 19 // blob and fileapi into content namespace. | 19 // blob and fileapi into content namespace. |
| 20 namespace webkit_blob { | 20 namespace storage { |
| 21 | 21 |
| 22 FileStreamReader* FileStreamReader::CreateForFileSystemFile( | 22 FileStreamReader* FileStreamReader::CreateForFileSystemFile( |
| 23 fileapi::FileSystemContext* file_system_context, | 23 storage::FileSystemContext* file_system_context, |
| 24 const fileapi::FileSystemURL& url, | 24 const storage::FileSystemURL& url, |
| 25 int64 initial_offset, | 25 int64 initial_offset, |
| 26 const base::Time& expected_modification_time) { | 26 const base::Time& expected_modification_time) { |
| 27 return new fileapi::FileSystemFileStreamReader( | 27 return new storage::FileSystemFileStreamReader( |
| 28 file_system_context, | 28 file_system_context, url, initial_offset, expected_modification_time); |
| 29 url, | |
| 30 initial_offset, | |
| 31 expected_modification_time); | |
| 32 } | 29 } |
| 33 | 30 |
| 34 } // namespace webkit_blob | 31 } // namespace storage |
| 35 | 32 |
| 36 namespace fileapi { | 33 namespace storage { |
| 37 | 34 |
| 38 namespace { | 35 namespace { |
| 39 | 36 |
| 40 void ReadAdapter(base::WeakPtr<FileSystemFileStreamReader> reader, | 37 void ReadAdapter(base::WeakPtr<FileSystemFileStreamReader> reader, |
| 41 net::IOBuffer* buf, int buf_len, | 38 net::IOBuffer* buf, int buf_len, |
| 42 const net::CompletionCallback& callback) { | 39 const net::CompletionCallback& callback) { |
| 43 if (!reader.get()) | 40 if (!reader.get()) |
| 44 return; | 41 return; |
| 45 int rv = reader->Read(buf, buf_len, callback); | 42 int rv = reader->Read(buf, buf_len, callback); |
| 46 if (rv != net::ERR_IO_PENDING) | 43 if (rv != net::ERR_IO_PENDING) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 error_callback)); | 109 error_callback)); |
| 113 return net::ERR_IO_PENDING; | 110 return net::ERR_IO_PENDING; |
| 114 } | 111 } |
| 115 | 112 |
| 116 void FileSystemFileStreamReader::DidCreateSnapshot( | 113 void FileSystemFileStreamReader::DidCreateSnapshot( |
| 117 const base::Closure& callback, | 114 const base::Closure& callback, |
| 118 const net::CompletionCallback& error_callback, | 115 const net::CompletionCallback& error_callback, |
| 119 base::File::Error file_error, | 116 base::File::Error file_error, |
| 120 const base::File::Info& file_info, | 117 const base::File::Info& file_info, |
| 121 const base::FilePath& platform_path, | 118 const base::FilePath& platform_path, |
| 122 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 119 const scoped_refptr<storage::ShareableFileReference>& file_ref) { |
| 123 DCHECK(has_pending_create_snapshot_); | 120 DCHECK(has_pending_create_snapshot_); |
| 124 DCHECK(!local_file_reader_.get()); | 121 DCHECK(!local_file_reader_.get()); |
| 125 has_pending_create_snapshot_ = false; | 122 has_pending_create_snapshot_ = false; |
| 126 | 123 |
| 127 if (file_error != base::File::FILE_OK) { | 124 if (file_error != base::File::FILE_OK) { |
| 128 error_callback.Run(net::FileErrorToNetError(file_error)); | 125 error_callback.Run(net::FileErrorToNetError(file_error)); |
| 129 return; | 126 return; |
| 130 } | 127 } |
| 131 | 128 |
| 132 // Keep the reference (if it's non-null) so that the file won't go away. | 129 // Keep the reference (if it's non-null) so that the file won't go away. |
| 133 snapshot_ref_ = file_ref; | 130 snapshot_ref_ = file_ref; |
| 134 | 131 |
| 135 local_file_reader_.reset( | 132 local_file_reader_.reset( |
| 136 FileStreamReader::CreateForLocalFile( | 133 FileStreamReader::CreateForLocalFile( |
| 137 file_system_context_->default_file_task_runner(), | 134 file_system_context_->default_file_task_runner(), |
| 138 platform_path, initial_offset_, expected_modification_time_)); | 135 platform_path, initial_offset_, expected_modification_time_)); |
| 139 | 136 |
| 140 callback.Run(); | 137 callback.Run(); |
| 141 } | 138 } |
| 142 | 139 |
| 143 } // namespace fileapi | 140 } // namespace storage |
| OLD | NEW |