| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" | 10 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // If requested read includes all the header bytes, we read directly to | 97 // If requested read includes all the header bytes, we read directly to |
| 98 // the original buffer, and validate the header bytes within that. | 98 // the original buffer, and validate the header bytes within that. |
| 99 header_buf = buf; | 99 header_buf = buf; |
| 100 header_buf_len = buf_len; | 100 header_buf_len = buf_len; |
| 101 } else { | 101 } else { |
| 102 // Otherwise, make a special request for the header. | 102 // Otherwise, make a special request for the header. |
| 103 header_buf = new net::IOBuffer(net::kMaxBytesToSniff); | 103 header_buf = new net::IOBuffer(net::kMaxBytesToSniff); |
| 104 header_buf_len = net::kMaxBytesToSniff; | 104 header_buf_len = net::kMaxBytesToSniff; |
| 105 } | 105 } |
| 106 | 106 |
| 107 ReadBytes(url_, header_buf, 0, header_buf_len, | 107 ReadBytes(url_, |
| 108 header_buf.get(), |
| 109 0, |
| 110 header_buf_len, |
| 108 base::Bind(&MTPFileStreamReader::FinishValidateMediaHeader, | 111 base::Bind(&MTPFileStreamReader::FinishValidateMediaHeader, |
| 109 weak_factory_.GetWeakPtr(), header_buf, | 112 weak_factory_.GetWeakPtr(), |
| 110 make_scoped_refptr(buf), buf_len, callback), | 113 header_buf, |
| 114 make_scoped_refptr(buf), |
| 115 buf_len, |
| 116 callback), |
| 111 callback); | 117 callback); |
| 112 return net::ERR_IO_PENDING; | 118 return net::ERR_IO_PENDING; |
| 113 } | 119 } |
| 114 | 120 |
| 115 ReadBytes(url_, buf, current_offset_, buf_len, | 121 ReadBytes(url_, buf, current_offset_, buf_len, |
| 116 base::Bind(&MTPFileStreamReader::FinishRead, | 122 base::Bind(&MTPFileStreamReader::FinishRead, |
| 117 weak_factory_.GetWeakPtr(), callback), | 123 weak_factory_.GetWeakPtr(), callback), |
| 118 callback); | 124 callback); |
| 119 | 125 |
| 120 return net::ERR_IO_PENDING; | 126 return net::ERR_IO_PENDING; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 const base::File::Info& file_info) { | 194 const base::File::Info& file_info) { |
| 189 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 195 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 190 | 196 |
| 191 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { | 197 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { |
| 192 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); | 198 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); |
| 193 return; | 199 return; |
| 194 } | 200 } |
| 195 | 201 |
| 196 callback.Run(file_info.size); | 202 callback.Run(file_info.size); |
| 197 } | 203 } |
| OLD | NEW |