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