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 25 matching lines...) Expand all Loading... |
36 | 36 |
37 void CallInt64CompletionCallbackWithPlatformFileError( | 37 void CallInt64CompletionCallbackWithPlatformFileError( |
38 const net::Int64CompletionCallback& callback, | 38 const net::Int64CompletionCallback& callback, |
39 base::File::Error file_error) { | 39 base::File::Error file_error) { |
40 callback.Run(net::FileErrorToNetError(file_error)); | 40 callback.Run(net::FileErrorToNetError(file_error)); |
41 } | 41 } |
42 | 42 |
43 void ReadBytes( | 43 void ReadBytes( |
44 const storage::FileSystemURL& url, | 44 const storage::FileSystemURL& url, |
45 const scoped_refptr<net::IOBuffer>& buf, | 45 const scoped_refptr<net::IOBuffer>& buf, |
46 int64 offset, | 46 int64_t offset, |
47 int buf_len, | 47 int buf_len, |
48 const MTPDeviceAsyncDelegate::ReadBytesSuccessCallback& success_callback, | 48 const MTPDeviceAsyncDelegate::ReadBytesSuccessCallback& success_callback, |
49 const net::CompletionCallback& error_callback) { | 49 const net::CompletionCallback& error_callback) { |
50 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); | 50 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); |
51 if (!delegate) { | 51 if (!delegate) { |
52 error_callback.Run(net::ERR_FAILED); | 52 error_callback.Run(net::ERR_FAILED); |
53 return; | 53 return; |
54 } | 54 } |
55 | 55 |
56 delegate->ReadBytes( | 56 delegate->ReadBytes( |
57 url.path(), | 57 url.path(), |
58 buf, | 58 buf, |
59 offset, | 59 offset, |
60 buf_len, | 60 buf_len, |
61 success_callback, | 61 success_callback, |
62 base::Bind(&CallCompletionCallbackWithPlatformFileError, error_callback)); | 62 base::Bind(&CallCompletionCallbackWithPlatformFileError, error_callback)); |
63 } | 63 } |
64 | 64 |
65 } // namespace | 65 } // namespace |
66 | 66 |
67 MTPFileStreamReader::MTPFileStreamReader( | 67 MTPFileStreamReader::MTPFileStreamReader( |
68 storage::FileSystemContext* file_system_context, | 68 storage::FileSystemContext* file_system_context, |
69 const storage::FileSystemURL& url, | 69 const storage::FileSystemURL& url, |
70 int64 initial_offset, | 70 int64_t initial_offset, |
71 const base::Time& expected_modification_time, | 71 const base::Time& expected_modification_time, |
72 bool do_media_header_validation) | 72 bool do_media_header_validation) |
73 : file_system_context_(file_system_context), | 73 : file_system_context_(file_system_context), |
74 url_(url), | 74 url_(url), |
75 current_offset_(initial_offset), | 75 current_offset_(initial_offset), |
76 expected_modification_time_(expected_modification_time), | 76 expected_modification_time_(expected_modification_time), |
77 media_header_validated_(!do_media_header_validation), | 77 media_header_validated_(!do_media_header_validation), |
78 weak_factory_(this) { | 78 weak_factory_(this) {} |
79 } | |
80 | 79 |
81 MTPFileStreamReader::~MTPFileStreamReader() { | 80 MTPFileStreamReader::~MTPFileStreamReader() { |
82 } | 81 } |
83 | 82 |
84 int MTPFileStreamReader::Read(net::IOBuffer* buf, int buf_len, | 83 int MTPFileStreamReader::Read(net::IOBuffer* buf, int buf_len, |
85 const net::CompletionCallback& callback) { | 84 const net::CompletionCallback& callback) { |
86 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 85 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
87 | 86 |
88 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url_); | 87 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url_); |
89 if (!delegate) | 88 if (!delegate) |
(...skipping 29 matching lines...) Expand all Loading... |
119 } | 118 } |
120 | 119 |
121 ReadBytes(url_, buf, current_offset_, buf_len, | 120 ReadBytes(url_, buf, current_offset_, buf_len, |
122 base::Bind(&MTPFileStreamReader::FinishRead, | 121 base::Bind(&MTPFileStreamReader::FinishRead, |
123 weak_factory_.GetWeakPtr(), callback), | 122 weak_factory_.GetWeakPtr(), callback), |
124 callback); | 123 callback); |
125 | 124 |
126 return net::ERR_IO_PENDING; | 125 return net::ERR_IO_PENDING; |
127 } | 126 } |
128 | 127 |
129 int64 MTPFileStreamReader::GetLength( | 128 int64_t MTPFileStreamReader::GetLength( |
130 const net::Int64CompletionCallback& callback) { | 129 const net::Int64CompletionCallback& callback) { |
131 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 130 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
132 | 131 |
133 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url_); | 132 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url_); |
134 if (!delegate) | 133 if (!delegate) |
135 return net::ERR_FAILED; | 134 return net::ERR_FAILED; |
136 | 135 |
137 delegate->GetFileInfo( | 136 delegate->GetFileInfo( |
138 url_.path(), | 137 url_.path(), |
139 base::Bind(&MTPFileStreamReader::FinishGetLength, | 138 base::Bind(&MTPFileStreamReader::FinishGetLength, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 const base::File::Info& file_info) { | 193 const base::File::Info& file_info) { |
195 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 194 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
196 | 195 |
197 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { | 196 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { |
198 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); | 197 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); |
199 return; | 198 return; |
200 } | 199 } |
201 | 200 |
202 callback.Run(file_info.size); | 201 callback.Run(file_info.size); |
203 } | 202 } |
OLD | NEW |