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/media_galleries/fileapi/itunes_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/itunes_file_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
| 11 #include <utility> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/media_galleries/fileapi/itunes_data_provider.h" | 17 #include "chrome/browser/media_galleries/fileapi/itunes_data_provider.h" |
17 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | 18 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
18 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" | 19 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 #include "storage/browser/blob/shareable_file_reference.h" | 21 #include "storage/browser/blob/shareable_file_reference.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 69 } |
69 | 70 |
70 void ITunesFileUtil::GetFileInfoOnTaskRunnerThread( | 71 void ITunesFileUtil::GetFileInfoOnTaskRunnerThread( |
71 scoped_ptr<storage::FileSystemOperationContext> context, | 72 scoped_ptr<storage::FileSystemOperationContext> context, |
72 const storage::FileSystemURL& url, | 73 const storage::FileSystemURL& url, |
73 const GetFileInfoCallback& callback) { | 74 const GetFileInfoCallback& callback) { |
74 ITunesDataProvider* data_provider = GetDataProvider(); | 75 ITunesDataProvider* data_provider = GetDataProvider(); |
75 // |data_provider| may be NULL if the file system was revoked before this | 76 // |data_provider| may be NULL if the file system was revoked before this |
76 // operation had a chance to run. | 77 // operation had a chance to run. |
77 if (!data_provider) { | 78 if (!data_provider) { |
78 GetFileInfoWithFreshDataProvider(context.Pass(), url, callback, false); | 79 GetFileInfoWithFreshDataProvider(std::move(context), url, callback, false); |
79 } else { | 80 } else { |
80 data_provider->RefreshData( | 81 data_provider->RefreshData( |
81 base::Bind(&ITunesFileUtil::GetFileInfoWithFreshDataProvider, | 82 base::Bind(&ITunesFileUtil::GetFileInfoWithFreshDataProvider, |
82 weak_factory_.GetWeakPtr(), base::Passed(&context), url, | 83 weak_factory_.GetWeakPtr(), base::Passed(&context), url, |
83 callback)); | 84 callback)); |
84 } | 85 } |
85 } | 86 } |
86 | 87 |
87 void ITunesFileUtil::ReadDirectoryOnTaskRunnerThread( | 88 void ITunesFileUtil::ReadDirectoryOnTaskRunnerThread( |
88 scoped_ptr<storage::FileSystemOperationContext> context, | 89 scoped_ptr<storage::FileSystemOperationContext> context, |
89 const storage::FileSystemURL& url, | 90 const storage::FileSystemURL& url, |
90 const ReadDirectoryCallback& callback) { | 91 const ReadDirectoryCallback& callback) { |
91 ITunesDataProvider* data_provider = GetDataProvider(); | 92 ITunesDataProvider* data_provider = GetDataProvider(); |
92 // |data_provider| may be NULL if the file system was revoked before this | 93 // |data_provider| may be NULL if the file system was revoked before this |
93 // operation had a chance to run. | 94 // operation had a chance to run. |
94 if (!data_provider) { | 95 if (!data_provider) { |
95 ReadDirectoryWithFreshDataProvider(context.Pass(), url, callback, false); | 96 ReadDirectoryWithFreshDataProvider(std::move(context), url, callback, |
| 97 false); |
96 } else { | 98 } else { |
97 data_provider->RefreshData( | 99 data_provider->RefreshData( |
98 base::Bind(&ITunesFileUtil::ReadDirectoryWithFreshDataProvider, | 100 base::Bind(&ITunesFileUtil::ReadDirectoryWithFreshDataProvider, |
99 weak_factory_.GetWeakPtr(), base::Passed(&context), url, | 101 weak_factory_.GetWeakPtr(), base::Passed(&context), url, |
100 callback)); | 102 callback)); |
101 } | 103 } |
102 } | 104 } |
103 | 105 |
104 void ITunesFileUtil::CreateSnapshotFileOnTaskRunnerThread( | 106 void ITunesFileUtil::CreateSnapshotFileOnTaskRunnerThread( |
105 scoped_ptr<storage::FileSystemOperationContext> context, | 107 scoped_ptr<storage::FileSystemOperationContext> context, |
106 const storage::FileSystemURL& url, | 108 const storage::FileSystemURL& url, |
107 const CreateSnapshotFileCallback& callback) { | 109 const CreateSnapshotFileCallback& callback) { |
108 ITunesDataProvider* data_provider = GetDataProvider(); | 110 ITunesDataProvider* data_provider = GetDataProvider(); |
109 // |data_provider| may be NULL if the file system was revoked before this | 111 // |data_provider| may be NULL if the file system was revoked before this |
110 // operation had a chance to run. | 112 // operation had a chance to run. |
111 if (!data_provider) { | 113 if (!data_provider) { |
112 CreateSnapshotFileWithFreshDataProvider(context.Pass(), url, callback, | 114 CreateSnapshotFileWithFreshDataProvider(std::move(context), url, callback, |
113 false); | 115 false); |
114 } else { | 116 } else { |
115 data_provider->RefreshData( | 117 data_provider->RefreshData( |
116 base::Bind(&ITunesFileUtil::CreateSnapshotFileWithFreshDataProvider, | 118 base::Bind(&ITunesFileUtil::CreateSnapshotFileWithFreshDataProvider, |
117 weak_factory_.GetWeakPtr(), base::Passed(&context), url, | 119 weak_factory_.GetWeakPtr(), base::Passed(&context), url, |
118 callback)); | 120 callback)); |
119 } | 121 } |
120 } | 122 } |
121 | 123 |
122 // Contents of the iTunes media gallery: | 124 // Contents of the iTunes media gallery: |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 if (!valid_parse) { | 358 if (!valid_parse) { |
357 if (!callback.is_null()) { | 359 if (!callback.is_null()) { |
358 content::BrowserThread::PostTask( | 360 content::BrowserThread::PostTask( |
359 content::BrowserThread::IO, | 361 content::BrowserThread::IO, |
360 FROM_HERE, | 362 FROM_HERE, |
361 base::Bind(callback, base::File::FILE_ERROR_IO, | 363 base::Bind(callback, base::File::FILE_ERROR_IO, |
362 base::File::Info())); | 364 base::File::Info())); |
363 } | 365 } |
364 return; | 366 return; |
365 } | 367 } |
366 NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread(context.Pass(), url, | 368 NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread(std::move(context), url, |
367 callback); | 369 callback); |
368 } | 370 } |
369 | 371 |
370 void ITunesFileUtil::ReadDirectoryWithFreshDataProvider( | 372 void ITunesFileUtil::ReadDirectoryWithFreshDataProvider( |
371 scoped_ptr<storage::FileSystemOperationContext> context, | 373 scoped_ptr<storage::FileSystemOperationContext> context, |
372 const storage::FileSystemURL& url, | 374 const storage::FileSystemURL& url, |
373 const ReadDirectoryCallback& callback, | 375 const ReadDirectoryCallback& callback, |
374 bool valid_parse) { | 376 bool valid_parse) { |
375 if (!valid_parse) { | 377 if (!valid_parse) { |
376 if (!callback.is_null()) { | 378 if (!callback.is_null()) { |
377 content::BrowserThread::PostTask( | 379 content::BrowserThread::PostTask( |
378 content::BrowserThread::IO, | 380 content::BrowserThread::IO, |
379 FROM_HERE, | 381 FROM_HERE, |
380 base::Bind(callback, base::File::FILE_ERROR_IO, EntryList(), false)); | 382 base::Bind(callback, base::File::FILE_ERROR_IO, EntryList(), false)); |
381 } | 383 } |
382 return; | 384 return; |
383 } | 385 } |
384 NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread(context.Pass(), url, | 386 NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread(std::move(context), url, |
385 callback); | 387 callback); |
386 } | 388 } |
387 | 389 |
388 void ITunesFileUtil::CreateSnapshotFileWithFreshDataProvider( | 390 void ITunesFileUtil::CreateSnapshotFileWithFreshDataProvider( |
389 scoped_ptr<storage::FileSystemOperationContext> context, | 391 scoped_ptr<storage::FileSystemOperationContext> context, |
390 const storage::FileSystemURL& url, | 392 const storage::FileSystemURL& url, |
391 const CreateSnapshotFileCallback& callback, | 393 const CreateSnapshotFileCallback& callback, |
392 bool valid_parse) { | 394 bool valid_parse) { |
393 if (!valid_parse) { | 395 if (!valid_parse) { |
394 if (!callback.is_null()) { | 396 if (!callback.is_null()) { |
395 base::File::Info file_info; | 397 base::File::Info file_info; |
396 base::FilePath platform_path; | 398 base::FilePath platform_path; |
397 scoped_refptr<storage::ShareableFileReference> file_ref; | 399 scoped_refptr<storage::ShareableFileReference> file_ref; |
398 content::BrowserThread::PostTask( | 400 content::BrowserThread::PostTask( |
399 content::BrowserThread::IO, | 401 content::BrowserThread::IO, |
400 FROM_HERE, | 402 FROM_HERE, |
401 base::Bind(callback, base::File::FILE_ERROR_IO, file_info, | 403 base::Bind(callback, base::File::FILE_ERROR_IO, file_info, |
402 platform_path, file_ref)); | 404 platform_path, file_ref)); |
403 } | 405 } |
404 return; | 406 return; |
405 } | 407 } |
406 NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread(context.Pass(), url, | 408 NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread(std::move(context), |
407 callback); | 409 url, callback); |
408 } | 410 } |
409 | 411 |
410 ITunesDataProvider* ITunesFileUtil::GetDataProvider() { | 412 ITunesDataProvider* ITunesFileUtil::GetDataProvider() { |
411 if (!imported_registry_) | 413 if (!imported_registry_) |
412 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); | 414 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); |
413 return imported_registry_->ITunesDataProvider(); | 415 return imported_registry_->ITunesDataProvider(); |
414 } | 416 } |
415 | 417 |
416 } // namespace itunes | 418 } // namespace itunes |
OLD | NEW |