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

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

Issue 298843002: Media Galleries: Refactor DeviceMediaAsyncFileUtil. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 7 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 "webkit/browser/blob/file_stream_reader.h"
19 #include "webkit/browser/fileapi/file_system_context.h" 19 #include "webkit/browser/fileapi/file_system_context.h"
20 #include "webkit/browser/fileapi/file_system_operation_context.h" 20 #include "webkit/browser/fileapi/file_system_operation_context.h"
21 #include "webkit/browser/fileapi/file_system_url.h" 21 #include "webkit/browser/fileapi/file_system_url.h"
22 #include "webkit/browser/fileapi/native_file_util.h" 22 #include "webkit/browser/fileapi/native_file_util.h"
23 #include "webkit/common/blob/shareable_file_reference.h" 23 #include "webkit/common/blob/shareable_file_reference.h"
24 24
25 using fileapi::AsyncFileUtil;
25 using fileapi::FileSystemOperationContext; 26 using fileapi::FileSystemOperationContext;
26 using fileapi::FileSystemURL; 27 using fileapi::FileSystemURL;
27 using webkit_blob::ShareableFileReference; 28 using webkit_blob::ShareableFileReference;
28 29
29 namespace { 30 namespace {
30 31
31 const char kDeviceMediaAsyncFileUtilTempDir[] = "DeviceMediaFileSystem"; 32 const char kDeviceMediaAsyncFileUtilTempDir[] = "DeviceMediaFileSystem";
32 33
33 // Called on the IO thread.
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 }
39 39
40 // Called when GetFileInfo method call failed to get the details of file
41 // specified by the requested url. |callback| is invoked to notify the
42 // caller about the file |error|.
43 void OnGetFileInfoError(const AsyncFileUtil::GetFileInfoCallback& callback,
44 base::File::Error error) {
45 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
46 callback.Run(error, base::File::Info());
47 }
48
49 // Called when ReadDirectory method call failed to enumerate the directory
50 // objects. |callback| is invoked to notify the caller about the |error|
51 // that occured while reading the directory objects.
52 void OnReadDirectoryError(const AsyncFileUtil::ReadDirectoryCallback& callback,
53 base::File::Error error) {
54 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
55 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/);
56 }
57
40 // Called on a blocking pool thread to create a snapshot file to hold the 58 // Called on a blocking pool thread to create a snapshot file to hold the
41 // contents of |device_file_path|. The snapshot file is created in the 59 // contents of |device_file_path|. The snapshot file is created in the
42 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. Return the 60 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. Return the
43 // snapshot file path or an empty path on failure. 61 // snapshot file path or an empty path on failure.
44 base::FilePath CreateSnapshotFileOnBlockingPool( 62 base::FilePath CreateSnapshotFileOnBlockingPool(
45 const base::FilePath& device_file_path, 63 const base::FilePath& device_file_path,
46 const base::FilePath& profile_path) { 64 const base::FilePath& profile_path) {
47 base::FilePath snapshot_file_path; 65 base::FilePath snapshot_file_path;
48 base::FilePath media_file_system_dir_path = 66 base::FilePath media_file_system_dir_path =
49 profile_path.AppendASCII(kDeviceMediaAsyncFileUtilTempDir); 67 profile_path.AppendASCII(kDeviceMediaAsyncFileUtilTempDir);
50 if (!base::CreateDirectory(media_file_system_dir_path) || 68 if (!base::CreateDirectory(media_file_system_dir_path) ||
51 !base::CreateTemporaryFileInDir(media_file_system_dir_path, 69 !base::CreateTemporaryFileInDir(media_file_system_dir_path,
52 &snapshot_file_path)) { 70 &snapshot_file_path)) {
53 LOG(WARNING) << "Could not create media snapshot file " 71 LOG(WARNING) << "Could not create media snapshot file "
54 << media_file_system_dir_path.value(); 72 << media_file_system_dir_path.value();
55 snapshot_file_path = base::FilePath(); 73 snapshot_file_path = base::FilePath();
56 } 74 }
57 return snapshot_file_path; 75 return snapshot_file_path;
58 } 76 }
59 77
78 // Called after OnDidCreateSnapshotFile finishes media check.
79 // |callback| is invoked to complete the CreateSnapshotFile request.
80 void OnDidCheckMediaForCreateSnapshotFile(
81 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
82 const base::File::Info& file_info,
83 scoped_refptr<webkit_blob::ShareableFileReference> platform_file,
84 base::File::Error error) {
85 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
86 base::FilePath platform_path(platform_file.get()->path());
87 if (error != base::File::FILE_OK)
88 platform_file = NULL;
89 callback.Run(error, file_info, platform_path, platform_file);
90 }
91
92 // Called when the snapshot file specified by the |platform_path| is
93 // successfully created. |file_info| contains the device media file details
94 // for which the snapshot file is created.
95 void OnDidCreateSnapshotFile(
96 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
97 base::SequencedTaskRunner* media_task_runner,
98 bool validate_media_files,
99 const base::File::Info& file_info,
100 const base::FilePath& platform_path) {
101 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
102 scoped_refptr<webkit_blob::ShareableFileReference> file =
103 ShareableFileReference::GetOrCreate(
104 platform_path,
105 ShareableFileReference::DELETE_ON_FINAL_RELEASE,
106 media_task_runner);
107
108 if (validate_media_files) {
109 base::PostTaskAndReplyWithResult(
110 media_task_runner,
111 FROM_HERE,
112 base::Bind(&NativeMediaFileUtil::IsMediaFile, platform_path),
113 base::Bind(&OnDidCheckMediaForCreateSnapshotFile,
114 callback,
115 file_info,
116 file));
117 } else {
118 OnDidCheckMediaForCreateSnapshotFile(callback, file_info, file,
119 base::File::FILE_OK);
120 }
121 }
122
123 // Called when CreateSnapshotFile method call fails. |callback| is invoked to
124 // notify the caller about the |error|.
125 void OnCreateSnapshotFileError(
126 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
127 base::File::Error error) {
128 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
129 callback.Run(error, base::File::Info(), base::FilePath(),
130 scoped_refptr<ShareableFileReference>());
131 }
132
133 // Called when the snapshot file specified by the |snapshot_file_path| is
134 // created to hold the contents of the url.path(). If the snapshot
135 // file is successfully created, |snapshot_file_path| will be an non-empty
136 // file path. In case of failure, |snapshot_file_path| will be an empty file
137 // path. Forwards the CreateSnapshot request to the delegate to copy the
138 // contents of url.path() to |snapshot_file_path|.
139 void OnSnapshotFileCreatedRunTask(
140 scoped_ptr<FileSystemOperationContext> context,
141 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
142 const FileSystemURL& url,
143 bool validate_media_files,
144 const base::FilePath& snapshot_file_path) {
145 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
146 if (snapshot_file_path.empty()) {
147 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_FAILED);
148 return;
149 }
150 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url);
151 if (!delegate) {
152 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_NOT_FOUND);
153 return;
154 }
155 delegate->CreateSnapshotFile(
156 url.path(), // device file path
157 snapshot_file_path,
158 base::Bind(&OnDidCreateSnapshotFile,
159 callback,
160 make_scoped_refptr(context->task_runner()),
161 validate_media_files),
162 base::Bind(&OnCreateSnapshotFileError, callback));
163 }
164
60 } // namespace 165 } // namespace
61 166
62 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() { 167 DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() {
63 } 168 }
64 169
65 // static 170 // static
66 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( 171 scoped_ptr<DeviceMediaAsyncFileUtil> DeviceMediaAsyncFileUtil::Create(
67 const base::FilePath& profile_path, 172 const base::FilePath& profile_path,
68 MediaFileValidationType validation_type) { 173 MediaFileValidationType validation_type) {
69 DCHECK(!profile_path.empty()); 174 DCHECK(!profile_path.empty());
70 return new DeviceMediaAsyncFileUtil(profile_path, validation_type); 175 return make_scoped_ptr(
176 new DeviceMediaAsyncFileUtil(profile_path, validation_type));
71 } 177 }
72 178
73 bool DeviceMediaAsyncFileUtil::SupportsStreaming( 179 bool DeviceMediaAsyncFileUtil::SupportsStreaming(
74 const fileapi::FileSystemURL& url) { 180 const fileapi::FileSystemURL& url) {
75 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 181 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
76 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); 182 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url);
77 if (!delegate) 183 if (!delegate)
78 return false; 184 return false;
79 return delegate->IsStreaming(); 185 return delegate->IsStreaming();
80 } 186 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); 235 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url);
130 if (!delegate) { 236 if (!delegate) {
131 OnGetFileInfoError(callback, base::File::FILE_ERROR_NOT_FOUND); 237 OnGetFileInfoError(callback, base::File::FILE_ERROR_NOT_FOUND);
132 return; 238 return;
133 } 239 }
134 delegate->GetFileInfo( 240 delegate->GetFileInfo(
135 url.path(), 241 url.path(),
136 base::Bind(&DeviceMediaAsyncFileUtil::OnDidGetFileInfo, 242 base::Bind(&DeviceMediaAsyncFileUtil::OnDidGetFileInfo,
137 weak_ptr_factory_.GetWeakPtr(), 243 weak_ptr_factory_.GetWeakPtr(),
138 callback), 244 callback),
139 base::Bind(&DeviceMediaAsyncFileUtil::OnGetFileInfoError, 245 base::Bind(&OnGetFileInfoError, callback));
140 weak_ptr_factory_.GetWeakPtr(),
141 callback));
142 } 246 }
143 247
144 void DeviceMediaAsyncFileUtil::ReadDirectory( 248 void DeviceMediaAsyncFileUtil::ReadDirectory(
145 scoped_ptr<FileSystemOperationContext> context, 249 scoped_ptr<FileSystemOperationContext> context,
146 const FileSystemURL& url, 250 const FileSystemURL& url,
147 const ReadDirectoryCallback& callback) { 251 const ReadDirectoryCallback& callback) {
148 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 252 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
149 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); 253 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url);
150 if (!delegate) { 254 if (!delegate) {
151 OnReadDirectoryError(callback, base::File::FILE_ERROR_NOT_FOUND); 255 OnReadDirectoryError(callback, base::File::FILE_ERROR_NOT_FOUND);
152 return; 256 return;
153 } 257 }
154 delegate->ReadDirectory( 258 delegate->ReadDirectory(
155 url.path(), 259 url.path(),
156 base::Bind(&DeviceMediaAsyncFileUtil::OnDidReadDirectory, 260 base::Bind(&DeviceMediaAsyncFileUtil::OnDidReadDirectory,
157 weak_ptr_factory_.GetWeakPtr(), 261 weak_ptr_factory_.GetWeakPtr(),
158 callback), 262 callback),
159 base::Bind(&DeviceMediaAsyncFileUtil::OnReadDirectoryError, 263 base::Bind(&OnReadDirectoryError, callback));
160 weak_ptr_factory_.GetWeakPtr(),
161 callback));
162 } 264 }
163 265
164 void DeviceMediaAsyncFileUtil::Touch( 266 void DeviceMediaAsyncFileUtil::Touch(
165 scoped_ptr<FileSystemOperationContext> context, 267 scoped_ptr<FileSystemOperationContext> context,
166 const FileSystemURL& url, 268 const FileSystemURL& url,
167 const base::Time& last_access_time, 269 const base::Time& last_access_time,
168 const base::Time& last_modified_time, 270 const base::Time& last_modified_time,
169 const StatusCallback& callback) { 271 const StatusCallback& callback) {
170 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 272 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
171 NOTIMPLEMENTED(); 273 NOTIMPLEMENTED();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 scoped_ptr<FileSystemOperationContext> context, 347 scoped_ptr<FileSystemOperationContext> context,
246 const FileSystemURL& url, 348 const FileSystemURL& url,
247 const CreateSnapshotFileCallback& callback) { 349 const CreateSnapshotFileCallback& callback) {
248 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 350 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
249 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); 351 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url);
250 if (!delegate) { 352 if (!delegate) {
251 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_NOT_FOUND); 353 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_NOT_FOUND);
252 return; 354 return;
253 } 355 }
254 356
255 // Grab the SequencedTaskRunner now because base::Passed(&context) will
256 // turn |context| empty before |task_runner| gets accessed.
257 scoped_refptr<base::SequencedTaskRunner> task_runner(context->task_runner()); 357 scoped_refptr<base::SequencedTaskRunner> task_runner(context->task_runner());
258 base::PostTaskAndReplyWithResult( 358 base::PostTaskAndReplyWithResult(
259 task_runner, 359 task_runner,
260 FROM_HERE, 360 FROM_HERE,
261 base::Bind(&CreateSnapshotFileOnBlockingPool, 361 base::Bind(&CreateSnapshotFileOnBlockingPool, url.path(), profile_path_),
262 url.path(), 362 base::Bind(&OnSnapshotFileCreatedRunTask,
263 profile_path_),
264 base::Bind(&DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask,
265 weak_ptr_factory_.GetWeakPtr(),
266 base::Passed(&context), 363 base::Passed(&context),
267 callback, 364 callback,
268 url)); 365 url,
366 validate_media_files()));
269 } 367 }
270 368
271 scoped_ptr<webkit_blob::FileStreamReader> 369 scoped_ptr<webkit_blob::FileStreamReader>
272 DeviceMediaAsyncFileUtil::GetFileStreamReader( 370 DeviceMediaAsyncFileUtil::GetFileStreamReader(
273 const FileSystemURL& url, 371 const FileSystemURL& url,
274 int64 offset, 372 int64 offset,
275 const base::Time& expected_modification_time, 373 const base::Time& expected_modification_time,
276 fileapi::FileSystemContext* context) { 374 fileapi::FileSystemContext* context) {
277 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); 375 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url);
278 if (!delegate) 376 if (!delegate)
279 return scoped_ptr<webkit_blob::FileStreamReader>(); 377 return scoped_ptr<webkit_blob::FileStreamReader>();
280 378
281 DCHECK(delegate->IsStreaming()); 379 DCHECK(delegate->IsStreaming());
282 return scoped_ptr<webkit_blob::FileStreamReader>( 380 return scoped_ptr<webkit_blob::FileStreamReader>(
283 new ReadaheadFileStreamReader(new MTPFileStreamReader( 381 new ReadaheadFileStreamReader(
284 context, url, offset, expected_modification_time, 382 new MTPFileStreamReader(context,
285 validation_type_ == APPLY_MEDIA_FILE_VALIDATION))); 383 url,
384 offset,
385 expected_modification_time,
386 validate_media_files())));
286 } 387 }
287 388
288 DeviceMediaAsyncFileUtil::DeviceMediaAsyncFileUtil( 389 DeviceMediaAsyncFileUtil::DeviceMediaAsyncFileUtil(
289 const base::FilePath& profile_path, 390 const base::FilePath& profile_path,
290 MediaFileValidationType validation_type) 391 MediaFileValidationType validation_type)
291 : profile_path_(profile_path), 392 : profile_path_(profile_path),
292 validation_type_(validation_type), 393 validation_type_(validation_type),
293 weak_ptr_factory_(this) { 394 weak_ptr_factory_(this) {
294 } 395 }
295 396
296 void DeviceMediaAsyncFileUtil::OnDidGetFileInfo( 397 void DeviceMediaAsyncFileUtil::OnDidGetFileInfo(
297 const AsyncFileUtil::GetFileInfoCallback& callback, 398 const GetFileInfoCallback& callback,
298 const base::File::Info& file_info) { 399 const base::File::Info& file_info) {
400 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
299 callback.Run(base::File::FILE_OK, file_info); 401 callback.Run(base::File::FILE_OK, file_info);
300 } 402 }
301 403
302 void DeviceMediaAsyncFileUtil::OnGetFileInfoError(
303 const AsyncFileUtil::GetFileInfoCallback& callback,
304 base::File::Error error) {
305 callback.Run(error, base::File::Info());
306 }
307
308 void DeviceMediaAsyncFileUtil::OnDidReadDirectory( 404 void DeviceMediaAsyncFileUtil::OnDidReadDirectory(
309 const AsyncFileUtil::ReadDirectoryCallback& callback, 405 const ReadDirectoryCallback& callback,
310 const AsyncFileUtil::EntryList& file_list, 406 const EntryList& file_list,
311 bool has_more) { 407 bool has_more) {
408 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
312 callback.Run(base::File::FILE_OK, file_list, has_more); 409 callback.Run(base::File::FILE_OK, file_list, has_more);
313 } 410 }
314 411
315 void DeviceMediaAsyncFileUtil::OnReadDirectoryError( 412 bool DeviceMediaAsyncFileUtil::validate_media_files() const {
316 const AsyncFileUtil::ReadDirectoryCallback& callback, 413 return validation_type_ == APPLY_MEDIA_FILE_VALIDATION;
317 base::File::Error error) {
318 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/);
319 } 414 }
320
321 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile(
322 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
323 base::SequencedTaskRunner* media_task_runner,
324 const base::File::Info& file_info,
325 const base::FilePath& platform_path) {
326 scoped_refptr<webkit_blob::ShareableFileReference> file =
327 ShareableFileReference::GetOrCreate(
328 platform_path,
329 ShareableFileReference::DELETE_ON_FINAL_RELEASE,
330 media_task_runner);
331
332 if (validation_type_ == APPLY_MEDIA_FILE_VALIDATION) {
333 base::PostTaskAndReplyWithResult(
334 media_task_runner,
335 FROM_HERE,
336 base::Bind(&NativeMediaFileUtil::IsMediaFile, platform_path),
337 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCheckMedia,
338 weak_ptr_factory_.GetWeakPtr(),
339 callback,
340 file_info,
341 file));
342 } else {
343 OnDidCheckMedia(callback, file_info, file, base::File::FILE_OK);
344 }
345 }
346
347 void DeviceMediaAsyncFileUtil::OnDidCheckMedia(
348 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
349 const base::File::Info& file_info,
350 scoped_refptr<webkit_blob::ShareableFileReference> platform_file,
351 base::File::Error error) {
352 base::FilePath platform_path(platform_file.get()->path());
353 if (error != base::File::FILE_OK)
354 platform_file = NULL;
355 callback.Run(error, file_info, platform_path, platform_file);
356 }
357
358 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError(
359 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
360 base::File::Error error) {
361 callback.Run(error, base::File::Info(), base::FilePath(),
362 scoped_refptr<ShareableFileReference>());
363 }
364
365 void DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask(
366 scoped_ptr<FileSystemOperationContext> context,
367 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
368 const FileSystemURL& url,
369 const base::FilePath& snapshot_file_path) {
370 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
371 if (snapshot_file_path.empty()) {
372 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_FAILED);
373 return;
374 }
375 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url);
376 if (!delegate) {
377 OnCreateSnapshotFileError(callback, base::File::FILE_ERROR_NOT_FOUND);
378 return;
379 }
380 delegate->CreateSnapshotFile(
381 url.path(), // device file path
382 snapshot_file_path,
383 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile,
384 weak_ptr_factory_.GetWeakPtr(),
385 callback,
386 make_scoped_refptr(context->task_runner())),
387 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError,
388 weak_ptr_factory_.GetWeakPtr(),
389 callback));
390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698