Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: chrome/browser/media_galleries/fileapi/device_media_async_file_util.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" 11 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h"
12 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" 12 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h"
13 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" 13 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h"
14 #include "chrome/browser/media_galleries/fileapi/mtp_file_stream_reader.h" 14 #include "chrome/browser/media_galleries/fileapi/mtp_file_stream_reader.h"
15 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" 15 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h"
16 #include "chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h" 16 #include "chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "webkit/browser/blob/file_stream_reader.h" 18 #include "storage/browser/blob/file_stream_reader.h"
19 #include "webkit/browser/fileapi/file_system_context.h" 19 #include "storage/browser/fileapi/file_system_context.h"
20 #include "webkit/browser/fileapi/file_system_operation_context.h" 20 #include "storage/browser/fileapi/file_system_operation_context.h"
21 #include "webkit/browser/fileapi/file_system_url.h" 21 #include "storage/browser/fileapi/file_system_url.h"
22 #include "webkit/browser/fileapi/native_file_util.h" 22 #include "storage/browser/fileapi/native_file_util.h"
23 #include "webkit/common/blob/shareable_file_reference.h" 23 #include "storage/common/blob/shareable_file_reference.h"
24 24
25 using fileapi::AsyncFileUtil; 25 using storage::AsyncFileUtil;
26 using fileapi::FileSystemOperationContext; 26 using storage::FileSystemOperationContext;
27 using fileapi::FileSystemURL; 27 using storage::FileSystemURL;
28 using webkit_blob::ShareableFileReference; 28 using storage::ShareableFileReference;
29 29
30 namespace { 30 namespace {
31 31
32 const char kDeviceMediaAsyncFileUtilTempDir[] = "DeviceMediaFileSystem"; 32 const char kDeviceMediaAsyncFileUtilTempDir[] = "DeviceMediaFileSystem";
33 33
34 MTPDeviceAsyncDelegate* GetMTPDeviceDelegate(const FileSystemURL& url) { 34 MTPDeviceAsyncDelegate* GetMTPDeviceDelegate(const FileSystemURL& url) {
35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
36 return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate( 36 return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate(
37 url.filesystem_id()); 37 url.filesystem_id());
38 } 38 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 snapshot_file_path = base::FilePath(); 97 snapshot_file_path = base::FilePath();
98 } 98 }
99 return snapshot_file_path; 99 return snapshot_file_path;
100 } 100 }
101 101
102 // Called after OnDidCreateSnapshotFile finishes media check. 102 // Called after OnDidCreateSnapshotFile finishes media check.
103 // |callback| is invoked to complete the CreateSnapshotFile request. 103 // |callback| is invoked to complete the CreateSnapshotFile request.
104 void OnDidCheckMediaForCreateSnapshotFile( 104 void OnDidCheckMediaForCreateSnapshotFile(
105 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 105 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
106 const base::File::Info& file_info, 106 const base::File::Info& file_info,
107 scoped_refptr<webkit_blob::ShareableFileReference> platform_file, 107 scoped_refptr<storage::ShareableFileReference> platform_file,
108 base::File::Error error) { 108 base::File::Error error) {
109 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 109 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
110 base::FilePath platform_path(platform_file.get()->path()); 110 base::FilePath platform_path(platform_file.get()->path());
111 if (error != base::File::FILE_OK) 111 if (error != base::File::FILE_OK)
112 platform_file = NULL; 112 platform_file = NULL;
113 callback.Run(error, file_info, platform_path, platform_file); 113 callback.Run(error, file_info, platform_path, platform_file);
114 } 114 }
115 115
116 // Called when the snapshot file specified by the |platform_path| is 116 // Called when the snapshot file specified by the |platform_path| is
117 // successfully created. |file_info| contains the device media file details 117 // successfully created. |file_info| contains the device media file details
118 // for which the snapshot file is created. 118 // for which the snapshot file is created.
119 void OnDidCreateSnapshotFile( 119 void OnDidCreateSnapshotFile(
120 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 120 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
121 base::SequencedTaskRunner* media_task_runner, 121 base::SequencedTaskRunner* media_task_runner,
122 bool validate_media_files, 122 bool validate_media_files,
123 const base::File::Info& file_info, 123 const base::File::Info& file_info,
124 const base::FilePath& platform_path) { 124 const base::FilePath& platform_path) {
125 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 125 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
126 scoped_refptr<webkit_blob::ShareableFileReference> file = 126 scoped_refptr<storage::ShareableFileReference> file =
127 ShareableFileReference::GetOrCreate( 127 ShareableFileReference::GetOrCreate(
128 platform_path, 128 platform_path,
129 ShareableFileReference::DELETE_ON_FINAL_RELEASE, 129 ShareableFileReference::DELETE_ON_FINAL_RELEASE,
130 media_task_runner); 130 media_task_runner);
131 131
132 if (validate_media_files) { 132 if (validate_media_files) {
133 base::PostTaskAndReplyWithResult( 133 base::PostTaskAndReplyWithResult(
134 media_task_runner, 134 media_task_runner,
135 FROM_HERE, 135 FROM_HERE,
136 base::Bind(&NativeMediaFileUtil::IsMediaFile, platform_path), 136 base::Bind(&NativeMediaFileUtil::IsMediaFile, platform_path),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 217 }
218 218
219 DeviceMediaAsyncFileUtil::MediaPathFilterWrapper::~MediaPathFilterWrapper() { 219 DeviceMediaAsyncFileUtil::MediaPathFilterWrapper::~MediaPathFilterWrapper() {
220 } 220 }
221 221
222 AsyncFileUtil::EntryList 222 AsyncFileUtil::EntryList
223 DeviceMediaAsyncFileUtil::MediaPathFilterWrapper::FilterMediaEntries( 223 DeviceMediaAsyncFileUtil::MediaPathFilterWrapper::FilterMediaEntries(
224 const AsyncFileUtil::EntryList& file_list) { 224 const AsyncFileUtil::EntryList& file_list) {
225 AsyncFileUtil::EntryList results; 225 AsyncFileUtil::EntryList results;
226 for (size_t i = 0; i < file_list.size(); ++i) { 226 for (size_t i = 0; i < file_list.size(); ++i) {
227 const fileapi::DirectoryEntry& entry = file_list[i]; 227 const storage::DirectoryEntry& entry = file_list[i];
228 if (entry.is_directory || CheckFilePath(base::FilePath(entry.name))) { 228 if (entry.is_directory || CheckFilePath(base::FilePath(entry.name))) {
229 results.push_back(entry); 229 results.push_back(entry);
230 } 230 }
231 } 231 }
232 return results; 232 return results;
233 } 233 }
234 234
235 bool DeviceMediaAsyncFileUtil::MediaPathFilterWrapper::CheckFilePath( 235 bool DeviceMediaAsyncFileUtil::MediaPathFilterWrapper::CheckFilePath(
236 const base::FilePath& path) { 236 const base::FilePath& path) {
237 return media_path_filter_->Match(path); 237 return media_path_filter_->Match(path);
238 } 238 }
239 239
240 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { 240 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() {
241 } 241 }
242 242
243 // static 243 // static
244 scoped_ptr<DeviceMediaAsyncFileUtil> DeviceMediaAsyncFileUtil::Create( 244 scoped_ptr<DeviceMediaAsyncFileUtil> DeviceMediaAsyncFileUtil::Create(
245 const base::FilePath& profile_path, 245 const base::FilePath& profile_path,
246 MediaFileValidationType validation_type) { 246 MediaFileValidationType validation_type) {
247 DCHECK(!profile_path.empty()); 247 DCHECK(!profile_path.empty());
248 return make_scoped_ptr( 248 return make_scoped_ptr(
249 new DeviceMediaAsyncFileUtil(profile_path, validation_type)); 249 new DeviceMediaAsyncFileUtil(profile_path, validation_type));
250 } 250 }
251 251
252 bool DeviceMediaAsyncFileUtil::SupportsStreaming( 252 bool DeviceMediaAsyncFileUtil::SupportsStreaming(
253 const fileapi::FileSystemURL& url) { 253 const storage::FileSystemURL& url) {
254 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 254 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
255 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); 255 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url);
256 if (!delegate) 256 if (!delegate)
257 return false; 257 return false;
258 return delegate->IsStreaming(); 258 return delegate->IsStreaming();
259 } 259 }
260 260
261 void DeviceMediaAsyncFileUtil::CreateOrOpen( 261 void DeviceMediaAsyncFileUtil::CreateOrOpen(
262 scoped_ptr<FileSystemOperationContext> context, 262 scoped_ptr<FileSystemOperationContext> context,
263 const FileSystemURL& url, 263 const FileSystemURL& url,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 task_runner, 435 task_runner,
436 FROM_HERE, 436 FROM_HERE,
437 base::Bind(&CreateSnapshotFileOnBlockingPool, url.path(), profile_path_), 437 base::Bind(&CreateSnapshotFileOnBlockingPool, url.path(), profile_path_),
438 base::Bind(&OnSnapshotFileCreatedRunTask, 438 base::Bind(&OnSnapshotFileCreatedRunTask,
439 base::Passed(&context), 439 base::Passed(&context),
440 callback, 440 callback,
441 url, 441 url,
442 validate_media_files())); 442 validate_media_files()));
443 } 443 }
444 444
445 scoped_ptr<webkit_blob::FileStreamReader> 445 scoped_ptr<storage::FileStreamReader>
446 DeviceMediaAsyncFileUtil::GetFileStreamReader( 446 DeviceMediaAsyncFileUtil::GetFileStreamReader(
447 const FileSystemURL& url, 447 const FileSystemURL& url,
448 int64 offset, 448 int64 offset,
449 const base::Time& expected_modification_time, 449 const base::Time& expected_modification_time,
450 fileapi::FileSystemContext* context) { 450 storage::FileSystemContext* context) {
451 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); 451 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url);
452 if (!delegate) 452 if (!delegate)
453 return scoped_ptr<webkit_blob::FileStreamReader>(); 453 return scoped_ptr<storage::FileStreamReader>();
454 454
455 DCHECK(delegate->IsStreaming()); 455 DCHECK(delegate->IsStreaming());
456 return scoped_ptr<webkit_blob::FileStreamReader>( 456 return scoped_ptr<storage::FileStreamReader>(new ReadaheadFileStreamReader(
457 new ReadaheadFileStreamReader( 457 new MTPFileStreamReader(context,
458 new MTPFileStreamReader(context, 458 url,
459 url, 459 offset,
460 offset, 460 expected_modification_time,
461 expected_modification_time, 461 validate_media_files())));
462 validate_media_files())));
463 } 462 }
464 463
465 DeviceMediaAsyncFileUtil::DeviceMediaAsyncFileUtil( 464 DeviceMediaAsyncFileUtil::DeviceMediaAsyncFileUtil(
466 const base::FilePath& profile_path, 465 const base::FilePath& profile_path,
467 MediaFileValidationType validation_type) 466 MediaFileValidationType validation_type)
468 : profile_path_(profile_path), 467 : profile_path_(profile_path),
469 weak_ptr_factory_(this) { 468 weak_ptr_factory_(this) {
470 if (validation_type == APPLY_MEDIA_FILE_VALIDATION) { 469 if (validation_type == APPLY_MEDIA_FILE_VALIDATION) {
471 media_path_filter_wrapper_ = new MediaPathFilterWrapper; 470 media_path_filter_wrapper_ = new MediaPathFilterWrapper;
472 } 471 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 FROM_HERE, 507 FROM_HERE,
509 base::Bind(&MediaPathFilterWrapper::FilterMediaEntries, 508 base::Bind(&MediaPathFilterWrapper::FilterMediaEntries,
510 media_path_filter_wrapper_, 509 media_path_filter_wrapper_,
511 file_list), 510 file_list),
512 base::Bind(&OnDidCheckMediaForReadDirectory, callback, has_more)); 511 base::Bind(&OnDidCheckMediaForReadDirectory, callback, has_more));
513 } 512 }
514 513
515 bool DeviceMediaAsyncFileUtil::validate_media_files() const { 514 bool DeviceMediaAsyncFileUtil::validate_media_files() const {
516 return media_path_filter_wrapper_.get() != NULL; 515 return media_path_filter_wrapper_.get() != NULL;
517 } 516 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698