| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/media_galleries/fileapi/device_media_async_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/device_media_async_file_util.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 return snapshot_file_path; | 57 return snapshot_file_path; |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { | 62 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { |
| 63 } | 63 } |
| 64 | 64 |
| 65 // static | 65 // static |
| 66 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( | 66 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( |
| 67 const base::FilePath& profile_path) { | 67 const base::FilePath& profile_path, |
| 68 MediaFileValidationType validation_type) { |
| 68 DCHECK(!profile_path.empty()); | 69 DCHECK(!profile_path.empty()); |
| 69 return new DeviceMediaAsyncFileUtil(profile_path); | 70 return new DeviceMediaAsyncFileUtil(profile_path, validation_type); |
| 70 } | 71 } |
| 71 | 72 |
| 72 bool DeviceMediaAsyncFileUtil::SupportsStreaming( | 73 bool DeviceMediaAsyncFileUtil::SupportsStreaming( |
| 73 const fileapi::FileSystemURL& url) { | 74 const fileapi::FileSystemURL& url) { |
| 74 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 75 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 75 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); | 76 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); |
| 76 if (!delegate) | 77 if (!delegate) |
| 77 return false; | 78 return false; |
| 78 return delegate->IsStreaming(); | 79 return delegate->IsStreaming(); |
| 79 } | 80 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 int64 offset, | 277 int64 offset, |
| 277 const base::Time& expected_modification_time, | 278 const base::Time& expected_modification_time, |
| 278 fileapi::FileSystemContext* context) { | 279 fileapi::FileSystemContext* context) { |
| 279 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); | 280 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); |
| 280 if (!delegate) | 281 if (!delegate) |
| 281 return scoped_ptr<webkit_blob::FileStreamReader>(); | 282 return scoped_ptr<webkit_blob::FileStreamReader>(); |
| 282 | 283 |
| 283 DCHECK(delegate->IsStreaming()); | 284 DCHECK(delegate->IsStreaming()); |
| 284 return scoped_ptr<webkit_blob::FileStreamReader>( | 285 return scoped_ptr<webkit_blob::FileStreamReader>( |
| 285 new ReadaheadFileStreamReader(new MTPFileStreamReader( | 286 new ReadaheadFileStreamReader(new MTPFileStreamReader( |
| 286 context, url, offset, expected_modification_time))); | 287 context, url, offset, expected_modification_time, |
| 288 validation_type_ == APPLY_MEDIA_FILE_VALIDATION))); |
| 287 } | 289 } |
| 288 | 290 |
| 289 DeviceMediaAsyncFileUtil::DeviceMediaAsyncFileUtil( | 291 DeviceMediaAsyncFileUtil::DeviceMediaAsyncFileUtil( |
| 290 const base::FilePath& profile_path) | 292 const base::FilePath& profile_path, |
| 293 MediaFileValidationType validation_type) |
| 291 : profile_path_(profile_path), | 294 : profile_path_(profile_path), |
| 295 validation_type_(validation_type), |
| 292 weak_ptr_factory_(this) { | 296 weak_ptr_factory_(this) { |
| 293 } | 297 } |
| 294 | 298 |
| 295 void DeviceMediaAsyncFileUtil::OnDidGetFileInfo( | 299 void DeviceMediaAsyncFileUtil::OnDidGetFileInfo( |
| 296 const AsyncFileUtil::GetFileInfoCallback& callback, | 300 const AsyncFileUtil::GetFileInfoCallback& callback, |
| 297 const base::File::Info& file_info) { | 301 const base::File::Info& file_info) { |
| 298 callback.Run(base::File::FILE_OK, file_info); | 302 callback.Run(base::File::FILE_OK, file_info); |
| 299 } | 303 } |
| 300 | 304 |
| 301 void DeviceMediaAsyncFileUtil::OnGetFileInfoError( | 305 void DeviceMediaAsyncFileUtil::OnGetFileInfoError( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 315 const AsyncFileUtil::ReadDirectoryCallback& callback, | 319 const AsyncFileUtil::ReadDirectoryCallback& callback, |
| 316 base::File::Error error) { | 320 base::File::Error error) { |
| 317 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); | 321 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); |
| 318 } | 322 } |
| 319 | 323 |
| 320 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( | 324 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( |
| 321 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | 325 const AsyncFileUtil::CreateSnapshotFileCallback& callback, |
| 322 base::SequencedTaskRunner* media_task_runner, | 326 base::SequencedTaskRunner* media_task_runner, |
| 323 const base::File::Info& file_info, | 327 const base::File::Info& file_info, |
| 324 const base::FilePath& platform_path) { | 328 const base::FilePath& platform_path) { |
| 325 base::PostTaskAndReplyWithResult( | 329 scoped_refptr<webkit_blob::ShareableFileReference> file = |
| 326 media_task_runner, | 330 ShareableFileReference::GetOrCreate( |
| 327 FROM_HERE, | 331 platform_path, |
| 328 base::Bind(&NativeMediaFileUtil::IsMediaFile, platform_path), | 332 ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
| 329 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCheckMedia, | 333 media_task_runner); |
| 330 weak_ptr_factory_.GetWeakPtr(), | 334 |
| 331 callback, | 335 if (validation_type_ == APPLY_MEDIA_FILE_VALIDATION) { |
| 332 file_info, | 336 base::PostTaskAndReplyWithResult( |
| 333 ShareableFileReference::GetOrCreate( | 337 media_task_runner, |
| 334 platform_path, | 338 FROM_HERE, |
| 335 ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 339 base::Bind(&NativeMediaFileUtil::IsMediaFile, platform_path), |
| 336 media_task_runner))); | 340 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCheckMedia, |
| 341 weak_ptr_factory_.GetWeakPtr(), |
| 342 callback, |
| 343 file_info, |
| 344 file)); |
| 345 } else { |
| 346 OnDidCheckMedia(callback, file_info, file, base::File::FILE_OK); |
| 347 } |
| 337 } | 348 } |
| 338 | 349 |
| 339 void DeviceMediaAsyncFileUtil::OnDidCheckMedia( | 350 void DeviceMediaAsyncFileUtil::OnDidCheckMedia( |
| 340 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | 351 const AsyncFileUtil::CreateSnapshotFileCallback& callback, |
| 341 const base::File::Info& file_info, | 352 const base::File::Info& file_info, |
| 342 scoped_refptr<webkit_blob::ShareableFileReference> platform_file, | 353 scoped_refptr<webkit_blob::ShareableFileReference> platform_file, |
| 343 base::File::Error error) { | 354 base::File::Error error) { |
| 344 base::FilePath platform_path(platform_file.get()->path()); | 355 base::FilePath platform_path(platform_file.get()->path()); |
| 345 if (error != base::File::FILE_OK) | 356 if (error != base::File::FILE_OK) |
| 346 platform_file = NULL; | 357 platform_file = NULL; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 373 url.path(), // device file path | 384 url.path(), // device file path |
| 374 snapshot_file_path, | 385 snapshot_file_path, |
| 375 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, | 386 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, |
| 376 weak_ptr_factory_.GetWeakPtr(), | 387 weak_ptr_factory_.GetWeakPtr(), |
| 377 callback, | 388 callback, |
| 378 make_scoped_refptr(context->task_runner())), | 389 make_scoped_refptr(context->task_runner())), |
| 379 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, | 390 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, |
| 380 weak_ptr_factory_.GetWeakPtr(), | 391 weak_ptr_factory_.GetWeakPtr(), |
| 381 callback)); | 392 callback)); |
| 382 } | 393 } |
| OLD | NEW |