| 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" | |
| 8 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| 12 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 13 #include "chrome/browser/chromeos/drive/file_cache.h" | 12 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 14 #include "chrome/browser/chromeos/drive/file_errors.h" | 13 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 15 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 14 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
| 16 #include "chrome/browser/chromeos/drive/file_system_util.h" | 15 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 17 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 16 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // This entry exists on the server, leave |cache_file_path| empty to | 81 // This entry exists on the server, leave |cache_file_path| empty to |
| 83 // start download. | 82 // start download. |
| 84 return FILE_ERROR_OK; | 83 return FILE_ERROR_OK; |
| 85 } | 84 } |
| 86 | 85 |
| 87 // This entry does not exist on the server, store an empty file and mark it | 86 // This entry does not exist on the server, store an empty file and mark it |
| 88 // as dirty. | 87 // as dirty. |
| 89 base::FilePath empty_file; | 88 base::FilePath empty_file; |
| 90 if (!base::CreateTemporaryFileInDir(temporary_file_directory, &empty_file)) | 89 if (!base::CreateTemporaryFileInDir(temporary_file_directory, &empty_file)) |
| 91 return FILE_ERROR_FAILED; | 90 return FILE_ERROR_FAILED; |
| 92 error = cache->Store(local_id, base::MD5String(""), empty_file, | 91 error = cache->Store(local_id, std::string(), empty_file, |
| 93 internal::FileCache::FILE_OPERATION_MOVE); | 92 internal::FileCache::FILE_OPERATION_MOVE); |
| 94 if (error != FILE_ERROR_OK) | 93 if (error != FILE_ERROR_OK) |
| 95 return error; | 94 return error; |
| 96 scoped_ptr<base::ScopedClosureRunner> file_closer; | |
| 97 error = cache->OpenForWrite(entry->local_id(), &file_closer); | |
| 98 if (error != FILE_ERROR_OK) | |
| 99 return error; | |
| 100 | 95 |
| 101 if (!cache->GetCacheEntry(local_id, &cache_entry)) | 96 if (!cache->GetCacheEntry(local_id, &cache_entry)) |
| 102 return FILE_ERROR_NOT_FOUND; | 97 return FILE_ERROR_NOT_FOUND; |
| 103 } | 98 } |
| 104 | 99 |
| 105 // Leave |cache_file_path| empty when the stored file is obsolete and has no | 100 // Leave |cache_file_path| empty when the stored file is obsolete and has no |
| 106 // local modification. | 101 // local modification. |
| 107 if (!cache_entry.is_dirty() && | 102 if (!cache_entry.is_dirty() && |
| 108 entry->file_specific_info().md5() != cache_entry.md5()) | 103 entry->file_specific_info().md5() != cache_entry.md5()) |
| 109 return FILE_ERROR_OK; | 104 return FILE_ERROR_OK; |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 observer_->OnDirectoryChangedByOperation(file_path.DirName()); | 501 observer_->OnDirectoryChangedByOperation(file_path.DirName()); |
| 507 params->OnComplete(*cache_file_path); | 502 params->OnComplete(*cache_file_path); |
| 508 } | 503 } |
| 509 | 504 |
| 510 void DownloadOperation::CancelJob(JobID job_id) { | 505 void DownloadOperation::CancelJob(JobID job_id) { |
| 511 scheduler_->CancelJob(job_id); | 506 scheduler_->CancelJob(job_id); |
| 512 } | 507 } |
| 513 | 508 |
| 514 } // namespace file_system | 509 } // namespace file_system |
| 515 } // namespace drive | 510 } // namespace drive |
| OLD | NEW |