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/file_system/download_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 const GetFileCallback& completion_callback) { | 315 const GetFileCallback& completion_callback) { |
316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
317 DCHECK(!completion_callback.is_null()); | 317 DCHECK(!completion_callback.is_null()); |
318 | 318 |
319 DownloadCallback callback( | 319 DownloadCallback callback( |
320 initialized_callback, get_content_callback, completion_callback); | 320 initialized_callback, get_content_callback, completion_callback); |
321 | 321 |
322 ResourceEntry* entry = new ResourceEntry; | 322 ResourceEntry* entry = new ResourceEntry; |
323 base::FilePath* cache_file_path = new base::FilePath; | 323 base::FilePath* cache_file_path = new base::FilePath; |
324 base::PostTaskAndReplyWithResult( | 324 base::PostTaskAndReplyWithResult( |
325 blocking_task_runner_, | 325 blocking_task_runner_.get(), |
326 FROM_HERE, | 326 FROM_HERE, |
327 base::Bind(&CheckPreConditionForEnsureFileDownloadedByResourceId, | 327 base::Bind(&CheckPreConditionForEnsureFileDownloadedByResourceId, |
328 base::Unretained(metadata_), | 328 base::Unretained(metadata_), |
329 base::Unretained(cache_), | 329 base::Unretained(cache_), |
330 resource_id, | 330 resource_id, |
331 cache_file_path, | 331 cache_file_path, |
332 entry), | 332 entry), |
333 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition, | 333 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition, |
334 weak_ptr_factory_.GetWeakPtr(), | 334 weak_ptr_factory_.GetWeakPtr(), |
335 context, | 335 context, |
(...skipping 10 matching lines...) Expand all Loading... |
346 const GetFileCallback& completion_callback) { | 346 const GetFileCallback& completion_callback) { |
347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
348 DCHECK(!completion_callback.is_null()); | 348 DCHECK(!completion_callback.is_null()); |
349 | 349 |
350 DownloadCallback callback( | 350 DownloadCallback callback( |
351 initialized_callback, get_content_callback, completion_callback); | 351 initialized_callback, get_content_callback, completion_callback); |
352 | 352 |
353 ResourceEntry* entry = new ResourceEntry; | 353 ResourceEntry* entry = new ResourceEntry; |
354 base::FilePath* cache_file_path = new base::FilePath; | 354 base::FilePath* cache_file_path = new base::FilePath; |
355 base::PostTaskAndReplyWithResult( | 355 base::PostTaskAndReplyWithResult( |
356 blocking_task_runner_, | 356 blocking_task_runner_.get(), |
357 FROM_HERE, | 357 FROM_HERE, |
358 base::Bind(&CheckPreConditionForEnsureFileDownloadedByPath, | 358 base::Bind(&CheckPreConditionForEnsureFileDownloadedByPath, |
359 base::Unretained(metadata_), | 359 base::Unretained(metadata_), |
360 base::Unretained(cache_), | 360 base::Unretained(cache_), |
361 file_path, | 361 file_path, |
362 cache_file_path, | 362 cache_file_path, |
363 entry), | 363 entry), |
364 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition, | 364 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition, |
365 weak_ptr_factory_.GetWeakPtr(), | 365 weak_ptr_factory_.GetWeakPtr(), |
366 context, | 366 context, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 // shared from others with "prevent downloading by viewers" flag set.) | 435 // shared from others with "prevent downloading by viewers" flag set.) |
436 if (download_url.is_empty()) { | 436 if (download_url.is_empty()) { |
437 callback.OnError(FILE_ERROR_ACCESS_DENIED); | 437 callback.OnError(FILE_ERROR_ACCESS_DENIED); |
438 return; | 438 return; |
439 } | 439 } |
440 | 440 |
441 // Before starting to download actually, refresh the metadata and allocate | 441 // Before starting to download actually, refresh the metadata and allocate |
442 // the cache space. | 442 // the cache space. |
443 DownloadParams* params = new DownloadParams(context, download_url); | 443 DownloadParams* params = new DownloadParams(context, download_url); |
444 base::PostTaskAndReplyWithResult( | 444 base::PostTaskAndReplyWithResult( |
445 blocking_task_runner_, | 445 blocking_task_runner_.get(), |
446 FROM_HERE, | 446 FROM_HERE, |
447 base::Bind(&PrepareForDownloadFile, | 447 base::Bind(&PrepareForDownloadFile, |
448 base::Unretained(metadata_), | 448 base::Unretained(metadata_), |
449 base::Unretained(cache_), | 449 base::Unretained(cache_), |
450 base::Passed(&resource_entry), | 450 base::Passed(&resource_entry), |
451 params->entry.get(), | 451 params->entry.get(), |
452 ¶ms->drive_file_path, | 452 ¶ms->drive_file_path, |
453 ¶ms->temp_download_file_path), | 453 ¶ms->temp_download_file_path), |
454 base::Bind( | 454 base::Bind( |
455 &DownloadOperation::EnsureFileDownloadedAfterPrepareForDownloadFile, | 455 &DownloadOperation::EnsureFileDownloadedAfterPrepareForDownloadFile, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 const base::FilePath& drive_file_path, | 494 const base::FilePath& drive_file_path, |
495 scoped_ptr<ResourceEntry> entry, | 495 scoped_ptr<ResourceEntry> entry, |
496 const DownloadCallback& callback, | 496 const DownloadCallback& callback, |
497 google_apis::GDataErrorCode gdata_error, | 497 google_apis::GDataErrorCode gdata_error, |
498 const base::FilePath& downloaded_file_path) { | 498 const base::FilePath& downloaded_file_path) { |
499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
500 | 500 |
501 ResourceEntry* entry_ptr = entry.get(); | 501 ResourceEntry* entry_ptr = entry.get(); |
502 base::FilePath* cache_file_path = new base::FilePath; | 502 base::FilePath* cache_file_path = new base::FilePath; |
503 base::PostTaskAndReplyWithResult( | 503 base::PostTaskAndReplyWithResult( |
504 blocking_task_runner_, | 504 blocking_task_runner_.get(), |
505 FROM_HERE, | 505 FROM_HERE, |
506 base::Bind(&UpdateLocalStateForDownloadFile, | 506 base::Bind(&UpdateLocalStateForDownloadFile, |
507 base::Unretained(cache_), | 507 base::Unretained(cache_), |
508 entry_ptr->resource_id(), | 508 entry_ptr->resource_id(), |
509 entry_ptr->file_specific_info().md5(), | 509 entry_ptr->file_specific_info().md5(), |
510 gdata_error, | 510 gdata_error, |
511 downloaded_file_path, | 511 downloaded_file_path, |
512 cache_file_path), | 512 cache_file_path), |
513 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterUpdateLocalState, | 513 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterUpdateLocalState, |
514 weak_ptr_factory_.GetWeakPtr(), | 514 weak_ptr_factory_.GetWeakPtr(), |
(...skipping 20 matching lines...) Expand all Loading... |
535 observer_->OnDirectoryChangedByOperation(file_path.DirName()); | 535 observer_->OnDirectoryChangedByOperation(file_path.DirName()); |
536 callback.OnComplete(*cache_file_path, entry.Pass()); | 536 callback.OnComplete(*cache_file_path, entry.Pass()); |
537 } | 537 } |
538 | 538 |
539 void DownloadOperation::CancelJob(JobID job_id) { | 539 void DownloadOperation::CancelJob(JobID job_id) { |
540 scheduler_->CancelJob(job_id); | 540 scheduler_->CancelJob(job_id); |
541 } | 541 } |
542 | 542 |
543 } // namespace file_system | 543 } // namespace file_system |
544 } // namespace drive | 544 } // namespace drive |
OLD | NEW |