| 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/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 12 #include "chrome/browser/chromeos/drive/drive.pb.h" | 12 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 13 #include "chrome/browser/chromeos/drive/file_cache.h" | 13 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 14 #include "chrome/browser/chromeos/drive/file_change.h" | 14 #include "chrome/browser/chromeos/drive/file_change.h" |
| 15 #include "chrome/browser/chromeos/drive/file_errors.h" | 15 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 16 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h" | 16 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h" |
| 17 #include "chrome/browser/chromeos/drive/file_system_util.h" | 17 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 18 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 18 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 19 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 19 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "google_apis/drive/gdata_errorcode.h" | 21 #include "google_apis/drive/drive_api_error_codes.h" |
| 22 | 22 |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 | 24 |
| 25 namespace drive { | 25 namespace drive { |
| 26 namespace file_system { | 26 namespace file_system { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Generates an unused file path with |extension| to |out_path|, as a descendant | 29 // Generates an unused file path with |extension| to |out_path|, as a descendant |
| 30 // of |dir|, with its parent directory created. | 30 // of |dir|, with its parent directory created. |
| 31 bool GeneratesUniquePathWithExtension( | 31 bool GeneratesUniquePathWithExtension( |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 208 } |
| 209 | 209 |
| 210 // Stores the downloaded file at |downloaded_file_path| into |cache|. | 210 // Stores the downloaded file at |downloaded_file_path| into |cache|. |
| 211 // If succeeded, returns FILE_ERROR_OK with |cache_file_path| storing the | 211 // If succeeded, returns FILE_ERROR_OK with |cache_file_path| storing the |
| 212 // path to the cache file. | 212 // path to the cache file. |
| 213 // If failed, returns an error code with deleting |downloaded_file_path|. | 213 // If failed, returns an error code with deleting |downloaded_file_path|. |
| 214 FileError UpdateLocalStateForDownloadFile( | 214 FileError UpdateLocalStateForDownloadFile( |
| 215 internal::ResourceMetadata* metadata, | 215 internal::ResourceMetadata* metadata, |
| 216 internal::FileCache* cache, | 216 internal::FileCache* cache, |
| 217 const ResourceEntry& entry_before_download, | 217 const ResourceEntry& entry_before_download, |
| 218 google_apis::GDataErrorCode gdata_error, | 218 google_apis::DriveApiErrorCode gdata_error, |
| 219 const base::FilePath& downloaded_file_path, | 219 const base::FilePath& downloaded_file_path, |
| 220 ResourceEntry* entry_after_update, | 220 ResourceEntry* entry_after_update, |
| 221 base::FilePath* cache_file_path) { | 221 base::FilePath* cache_file_path) { |
| 222 DCHECK(cache); | 222 DCHECK(cache); |
| 223 | 223 |
| 224 // Downloaded file should be deleted on errors. | 224 // Downloaded file should be deleted on errors. |
| 225 base::ScopedClosureRunner file_deleter(base::Bind( | 225 base::ScopedClosureRunner file_deleter(base::Bind( |
| 226 base::IgnoreResult(&base::DeleteFile), | 226 base::IgnoreResult(&base::DeleteFile), |
| 227 downloaded_file_path, false /* recursive */)); | 227 downloaded_file_path, false /* recursive */)); |
| 228 | 228 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 | 480 |
| 481 // Notify via |initialized_callback| if necessary. | 481 // Notify via |initialized_callback| if necessary. |
| 482 params_ptr->OnStartDownloading( | 482 params_ptr->OnStartDownloading( |
| 483 base::Bind(&DownloadOperation::CancelJob, | 483 base::Bind(&DownloadOperation::CancelJob, |
| 484 weak_ptr_factory_.GetWeakPtr(), id)); | 484 weak_ptr_factory_.GetWeakPtr(), id)); |
| 485 } | 485 } |
| 486 | 486 |
| 487 void DownloadOperation::EnsureFileDownloadedAfterDownloadFile( | 487 void DownloadOperation::EnsureFileDownloadedAfterDownloadFile( |
| 488 const base::FilePath& drive_file_path, | 488 const base::FilePath& drive_file_path, |
| 489 scoped_ptr<DownloadParams> params, | 489 scoped_ptr<DownloadParams> params, |
| 490 google_apis::GDataErrorCode gdata_error, | 490 google_apis::DriveApiErrorCode gdata_error, |
| 491 const base::FilePath& downloaded_file_path) { | 491 const base::FilePath& downloaded_file_path) { |
| 492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 493 | 493 |
| 494 DownloadParams* params_ptr = params.get(); | 494 DownloadParams* params_ptr = params.get(); |
| 495 ResourceEntry* entry_after_update = new ResourceEntry; | 495 ResourceEntry* entry_after_update = new ResourceEntry; |
| 496 base::FilePath* cache_file_path = new base::FilePath; | 496 base::FilePath* cache_file_path = new base::FilePath; |
| 497 base::PostTaskAndReplyWithResult( | 497 base::PostTaskAndReplyWithResult( |
| 498 blocking_task_runner_.get(), | 498 blocking_task_runner_.get(), |
| 499 FROM_HERE, | 499 FROM_HERE, |
| 500 base::Bind(&UpdateLocalStateForDownloadFile, | 500 base::Bind(&UpdateLocalStateForDownloadFile, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 delegate_->OnFileChangedByOperation(changed_files); | 534 delegate_->OnFileChangedByOperation(changed_files); |
| 535 params->OnDownloadCompleted(*cache_file_path, entry_after_update.Pass()); | 535 params->OnDownloadCompleted(*cache_file_path, entry_after_update.Pass()); |
| 536 } | 536 } |
| 537 | 537 |
| 538 void DownloadOperation::CancelJob(JobID job_id) { | 538 void DownloadOperation::CancelJob(JobID job_id) { |
| 539 scheduler_->CancelJob(job_id); | 539 scheduler_->CancelJob(job_id); |
| 540 } | 540 } |
| 541 | 541 |
| 542 } // namespace file_system | 542 } // namespace file_system |
| 543 } // namespace drive | 543 } // namespace drive |
| OLD | NEW |