| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/media_galleries/fileapi/mtp_file_stream_reader.h" | 5 #include "chrome/browser/media_galleries/fileapi/mtp_file_stream_reader.h" |
| 6 | 6 |
| 7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
| 8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
| 9 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" | 9 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" |
| 10 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" | 10 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "webkit/browser/fileapi/file_system_context.h" | 14 #include "webkit/browser/fileapi/file_system_context.h" |
| 15 | 15 |
| 16 using webkit_blob::FileStreamReader; | 16 using webkit_blob::FileStreamReader; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Called on the IO thread. | 20 // Called on the IO thread. |
| 21 MTPDeviceAsyncDelegate* GetMTPDeviceDelegate( | 21 MTPDeviceAsyncDelegate* GetMTPDeviceDelegate( |
| 22 const fileapi::FileSystemURL& url) { | 22 const fileapi::FileSystemURL& url) { |
| 23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 24 return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate( | 24 return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate( |
| 25 url.filesystem_id()); | 25 url.filesystem_id()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void CallCompletionCallbackWithPlatformFileError( | 28 void CallCompletionCallbackWithPlatformFileError( |
| 29 const net::CompletionCallback& callback, | 29 const net::CompletionCallback& callback, |
| 30 base::PlatformFileError platform_file_error) { | 30 base::File::Error file_error) { |
| 31 callback.Run(net::PlatformFileErrorToNetError(platform_file_error)); | 31 callback.Run(net::FileErrorToNetError(file_error)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void CallInt64CompletionCallbackWithPlatformFileError( | 34 void CallInt64CompletionCallbackWithPlatformFileError( |
| 35 const net::Int64CompletionCallback& callback, | 35 const net::Int64CompletionCallback& callback, |
| 36 base::PlatformFileError platform_file_error) { | 36 base::File::Error file_error) { |
| 37 callback.Run(net::PlatformFileErrorToNetError(platform_file_error)); | 37 callback.Run(net::FileErrorToNetError(file_error)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 MTPFileStreamReader::MTPFileStreamReader( | 42 MTPFileStreamReader::MTPFileStreamReader( |
| 43 fileapi::FileSystemContext* file_system_context, | 43 fileapi::FileSystemContext* file_system_context, |
| 44 const fileapi::FileSystemURL& url, | 44 const fileapi::FileSystemURL& url, |
| 45 int64 initial_offset, | 45 int64 initial_offset, |
| 46 const base::Time& expected_modification_time) | 46 const base::Time& expected_modification_time) |
| 47 : file_system_context_(file_system_context), | 47 : file_system_context_(file_system_context), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 base::Bind(&CallInt64CompletionCallbackWithPlatformFileError, | 87 base::Bind(&CallInt64CompletionCallbackWithPlatformFileError, |
| 88 callback)); | 88 callback)); |
| 89 | 89 |
| 90 return net::ERR_IO_PENDING; | 90 return net::ERR_IO_PENDING; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void MTPFileStreamReader::OnFileInfoForRead( | 93 void MTPFileStreamReader::OnFileInfoForRead( |
| 94 net::IOBuffer* buf, | 94 net::IOBuffer* buf, |
| 95 int buf_len, | 95 int buf_len, |
| 96 const net::CompletionCallback& callback, | 96 const net::CompletionCallback& callback, |
| 97 const base::PlatformFileInfo& file_info) { | 97 const base::File::Info& file_info) { |
| 98 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 98 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 99 | 99 |
| 100 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { | 100 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { |
| 101 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); | 101 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); |
| 102 return; | 102 return; |
| 103 } | 103 } |
| 104 | 104 |
| 105 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url_); | 105 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url_); |
| 106 if (!delegate) { | 106 if (!delegate) { |
| 107 callback.Run(net::ERR_FAILED); | 107 callback.Run(net::ERR_FAILED); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 127 void MTPFileStreamReader::FinishRead(const net::CompletionCallback& callback, | 127 void MTPFileStreamReader::FinishRead(const net::CompletionCallback& callback, |
| 128 int bytes_read) { | 128 int bytes_read) { |
| 129 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 129 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 130 DCHECK_GE(bytes_read, 0); | 130 DCHECK_GE(bytes_read, 0); |
| 131 current_offset_ += bytes_read; | 131 current_offset_ += bytes_read; |
| 132 callback.Run(bytes_read); | 132 callback.Run(bytes_read); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void MTPFileStreamReader::FinishGetLength( | 135 void MTPFileStreamReader::FinishGetLength( |
| 136 const net::Int64CompletionCallback& callback, | 136 const net::Int64CompletionCallback& callback, |
| 137 const base::PlatformFileInfo& file_info) { | 137 const base::File::Info& file_info) { |
| 138 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 138 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 139 | 139 |
| 140 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { | 140 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { |
| 141 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); | 141 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); |
| 142 return; | 142 return; |
| 143 } | 143 } |
| 144 | 144 |
| 145 callback.Run(file_info.size); | 145 callback.Run(file_info.size); |
| 146 } | 146 } |
| OLD | NEW |