OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/drive/drive_file_stream_reader.h" | 5 #include "chrome/browser/chromeos/drive/drive_file_stream_reader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 198 } |
199 | 199 |
200 } // namespace internal | 200 } // namespace internal |
201 | 201 |
202 namespace { | 202 namespace { |
203 | 203 |
204 // Calls DriveFileSystemInterface::GetFileContentByPath if the file system | 204 // Calls DriveFileSystemInterface::GetFileContentByPath if the file system |
205 // is available. If not, the |completion_callback| is invoked with | 205 // is available. If not, the |completion_callback| is invoked with |
206 // FILE_ERROR_FAILED. | 206 // FILE_ERROR_FAILED. |
207 void GetFileContentByPathOnUIThread( | 207 void GetFileContentByPathOnUIThread( |
208 const DriveFileStreamReader::DriveFileSystemGetter& file_system_getter, | 208 const DriveFileStreamReader::FileSystemGetter& file_system_getter, |
209 const base::FilePath& drive_file_path, | 209 const base::FilePath& drive_file_path, |
210 const GetFileContentInitializedCallback& initialized_callback, | 210 const GetFileContentInitializedCallback& initialized_callback, |
211 const google_apis::GetContentCallback& get_content_callback, | 211 const google_apis::GetContentCallback& get_content_callback, |
212 const FileOperationCallback& completion_callback) { | 212 const FileOperationCallback& completion_callback) { |
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
214 | 214 |
215 DriveFileSystemInterface* file_system = file_system_getter.Run(); | 215 DriveFileSystemInterface* file_system = file_system_getter.Run(); |
216 if (!file_system) { | 216 if (!file_system) { |
217 completion_callback.Run(FILE_ERROR_FAILED); | 217 completion_callback.Run(FILE_ERROR_FAILED); |
218 return; | 218 return; |
219 } | 219 } |
220 | 220 |
221 file_system->GetFileContentByPath(drive_file_path, | 221 file_system->GetFileContentByPath(drive_file_path, |
222 initialized_callback, | 222 initialized_callback, |
223 get_content_callback, | 223 get_content_callback, |
224 completion_callback); | 224 completion_callback); |
225 } | 225 } |
226 | 226 |
227 // Helper to run DriveFileSystemInterface::GetFileContentByPath on UI thread. | 227 // Helper to run DriveFileSystemInterface::GetFileContentByPath on UI thread. |
228 void GetFileContentByPath( | 228 void GetFileContentByPath( |
229 const DriveFileStreamReader::DriveFileSystemGetter& file_system_getter, | 229 const DriveFileStreamReader::FileSystemGetter& file_system_getter, |
230 const base::FilePath& drive_file_path, | 230 const base::FilePath& drive_file_path, |
231 const GetFileContentInitializedCallback& initialized_callback, | 231 const GetFileContentInitializedCallback& initialized_callback, |
232 const google_apis::GetContentCallback& get_content_callback, | 232 const google_apis::GetContentCallback& get_content_callback, |
233 const FileOperationCallback& completion_callback) { | 233 const FileOperationCallback& completion_callback) { |
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
235 | 235 |
236 BrowserThread::PostTask( | 236 BrowserThread::PostTask( |
237 BrowserThread::UI, | 237 BrowserThread::UI, |
238 FROM_HERE, | 238 FROM_HERE, |
239 base::Bind(&GetFileContentByPathOnUIThread, | 239 base::Bind(&GetFileContentByPathOnUIThread, |
240 file_system_getter, | 240 file_system_getter, |
241 drive_file_path, | 241 drive_file_path, |
242 google_apis::CreateRelayCallback(initialized_callback), | 242 google_apis::CreateRelayCallback(initialized_callback), |
243 google_apis::CreateRelayCallback(get_content_callback), | 243 google_apis::CreateRelayCallback(get_content_callback), |
244 google_apis::CreateRelayCallback(completion_callback))); | 244 google_apis::CreateRelayCallback(completion_callback))); |
245 } | 245 } |
246 | 246 |
247 } // namespace | 247 } // namespace |
248 | 248 |
249 DriveFileStreamReader::DriveFileStreamReader( | 249 DriveFileStreamReader::DriveFileStreamReader( |
250 const DriveFileSystemGetter& drive_file_system_getter) | 250 const FileSystemGetter& file_system_getter) |
251 : drive_file_system_getter_(drive_file_system_getter), | 251 : file_system_getter_(file_system_getter), |
252 weak_ptr_factory_(this) { | 252 weak_ptr_factory_(this) { |
253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
254 } | 254 } |
255 | 255 |
256 DriveFileStreamReader::~DriveFileStreamReader() { | 256 DriveFileStreamReader::~DriveFileStreamReader() { |
257 } | 257 } |
258 | 258 |
259 bool DriveFileStreamReader::IsInitialized() const { | 259 bool DriveFileStreamReader::IsInitialized() const { |
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
261 return reader_proxy_.get() != NULL; | 261 return reader_proxy_.get() != NULL; |
262 } | 262 } |
263 | 263 |
264 void DriveFileStreamReader::Initialize( | 264 void DriveFileStreamReader::Initialize( |
265 const base::FilePath& drive_file_path, | 265 const base::FilePath& drive_file_path, |
266 const InitializeCompletionCallback& callback) { | 266 const InitializeCompletionCallback& callback) { |
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
268 DCHECK(!callback.is_null()); | 268 DCHECK(!callback.is_null()); |
269 | 269 |
270 GetFileContentByPath( | 270 GetFileContentByPath( |
271 drive_file_system_getter_, | 271 file_system_getter_, |
272 drive_file_path, | 272 drive_file_path, |
273 base::Bind(&DriveFileStreamReader | 273 base::Bind(&DriveFileStreamReader |
274 ::InitializeAfterGetFileContentByPathInitialized, | 274 ::InitializeAfterGetFileContentByPathInitialized, |
275 weak_ptr_factory_.GetWeakPtr(), | 275 weak_ptr_factory_.GetWeakPtr(), |
276 drive_file_path, | 276 drive_file_path, |
277 callback), | 277 callback), |
278 base::Bind(&DriveFileStreamReader::OnGetContent, | 278 base::Bind(&DriveFileStreamReader::OnGetContent, |
279 weak_ptr_factory_.GetWeakPtr()), | 279 weak_ptr_factory_.GetWeakPtr()), |
280 base::Bind(&DriveFileStreamReader::OnGetFileContentByPathCompletion, | 280 base::Bind(&DriveFileStreamReader::OnGetFileContentByPathCompletion, |
281 weak_ptr_factory_.GetWeakPtr(), | 281 weak_ptr_factory_.GetWeakPtr(), |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 // Note: due to the same reason, LocalReaderProxy::OnCompleted may | 383 // Note: due to the same reason, LocalReaderProxy::OnCompleted may |
384 // or may not be called. This is timing issue, and it is difficult to avoid | 384 // or may not be called. This is timing issue, and it is difficult to avoid |
385 // unfortunately. | 385 // unfortunately. |
386 if (error != FILE_ERROR_OK) { | 386 if (error != FILE_ERROR_OK) { |
387 callback.Run(error, scoped_ptr<DriveEntryProto>()); | 387 callback.Run(error, scoped_ptr<DriveEntryProto>()); |
388 } | 388 } |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 } // namespace drive | 392 } // namespace drive |
OLD | NEW |