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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 !base::GetFileInfo(gdoc_file_path, | 112 !base::GetFileInfo(gdoc_file_path, |
113 reinterpret_cast<base::File::Info*>(&file_info))) | 113 reinterpret_cast<base::File::Info*>(&file_info))) |
114 return FILE_ERROR_FAILED; | 114 return FILE_ERROR_FAILED; |
115 | 115 |
116 *cache_file_path = gdoc_file_path; | 116 *cache_file_path = gdoc_file_path; |
117 SetPlatformFileInfoToResourceEntry(file_info, entry); | 117 SetPlatformFileInfoToResourceEntry(file_info, entry); |
118 return FILE_ERROR_OK; | 118 return FILE_ERROR_OK; |
119 } | 119 } |
120 | 120 |
121 FileCacheEntry cache_entry; | 121 FileCacheEntry cache_entry; |
122 if (!cache->GetCacheEntry(local_id, &cache_entry) || | 122 error = cache->GetCacheEntry(local_id, &cache_entry); |
123 !cache_entry.is_present()) { // This file has no cache file. | 123 if (error != FILE_ERROR_OK && error != FILE_ERROR_NOT_FOUND) |
| 124 return error; |
| 125 if (!cache_entry.is_present()) { // This file has no cache file. |
124 if (!entry->resource_id().empty()) { | 126 if (!entry->resource_id().empty()) { |
125 // This entry exists on the server, leave |cache_file_path| empty to | 127 // This entry exists on the server, leave |cache_file_path| empty to |
126 // start download. | 128 // start download. |
127 return PrepareForDownloadFile(cache, entry->file_info().size(), | 129 return PrepareForDownloadFile(cache, entry->file_info().size(), |
128 temporary_file_directory, | 130 temporary_file_directory, |
129 temp_download_file_path); | 131 temp_download_file_path); |
130 } | 132 } |
131 | 133 |
132 // This entry does not exist on the server, store an empty file and mark it | 134 // This entry does not exist on the server, store an empty file and mark it |
133 // as dirty. | 135 // as dirty. |
134 base::FilePath empty_file; | 136 base::FilePath empty_file; |
135 if (!base::CreateTemporaryFileInDir(temporary_file_directory, &empty_file)) | 137 if (!base::CreateTemporaryFileInDir(temporary_file_directory, &empty_file)) |
136 return FILE_ERROR_FAILED; | 138 return FILE_ERROR_FAILED; |
137 error = cache->Store(local_id, std::string(), empty_file, | 139 error = cache->Store(local_id, std::string(), empty_file, |
138 internal::FileCache::FILE_OPERATION_MOVE); | 140 internal::FileCache::FILE_OPERATION_MOVE); |
139 if (error != FILE_ERROR_OK) | 141 if (error != FILE_ERROR_OK) |
140 return error; | 142 return error; |
141 | 143 |
142 if (!cache->GetCacheEntry(local_id, &cache_entry)) | 144 error = cache->GetCacheEntry(local_id, &cache_entry); |
143 return FILE_ERROR_NOT_FOUND; | 145 if (error != FILE_ERROR_OK) |
| 146 return error; |
144 } | 147 } |
145 | 148 |
146 // Leave |cache_file_path| empty when the stored file is obsolete and has no | 149 // Leave |cache_file_path| empty when the stored file is obsolete and has no |
147 // local modification. | 150 // local modification. |
148 if (!cache_entry.is_dirty() && | 151 if (!cache_entry.is_dirty() && |
149 entry->file_specific_info().md5() != cache_entry.md5()) { | 152 entry->file_specific_info().md5() != cache_entry.md5()) { |
150 return PrepareForDownloadFile(cache, entry->file_info().size(), | 153 return PrepareForDownloadFile(cache, entry->file_info().size(), |
151 temporary_file_directory, | 154 temporary_file_directory, |
152 temp_download_file_path); | 155 temp_download_file_path); |
153 } | 156 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 base::ScopedClosureRunner file_deleter(base::Bind( | 226 base::ScopedClosureRunner file_deleter(base::Bind( |
224 base::IgnoreResult(&base::DeleteFile), | 227 base::IgnoreResult(&base::DeleteFile), |
225 downloaded_file_path, false /* recursive */)); | 228 downloaded_file_path, false /* recursive */)); |
226 | 229 |
227 FileError error = GDataToFileError(gdata_error); | 230 FileError error = GDataToFileError(gdata_error); |
228 if (error != FILE_ERROR_OK) | 231 if (error != FILE_ERROR_OK) |
229 return error; | 232 return error; |
230 | 233 |
231 // Do not overwrite locally edited file with server side contents. | 234 // Do not overwrite locally edited file with server side contents. |
232 FileCacheEntry cache_entry; | 235 FileCacheEntry cache_entry; |
233 if (cache->GetCacheEntry(local_id, &cache_entry) && cache_entry.is_dirty()) | 236 error = cache->GetCacheEntry(local_id, &cache_entry); |
| 237 if (error != FILE_ERROR_OK && error != FILE_ERROR_NOT_FOUND) |
| 238 return error; |
| 239 if (cache_entry.is_dirty()) |
234 return FILE_ERROR_IN_USE; | 240 return FILE_ERROR_IN_USE; |
235 | 241 |
236 // Here the download is completed successfully, so store it into the cache. | 242 // Here the download is completed successfully, so store it into the cache. |
237 error = cache->Store(local_id, md5, downloaded_file_path, | 243 error = cache->Store(local_id, md5, downloaded_file_path, |
238 internal::FileCache::FILE_OPERATION_MOVE); | 244 internal::FileCache::FILE_OPERATION_MOVE); |
239 if (error != FILE_ERROR_OK) | 245 if (error != FILE_ERROR_OK) |
240 return error; | 246 return error; |
241 base::Closure unused_file_deleter_closure = file_deleter.Release(); | 247 base::Closure unused_file_deleter_closure = file_deleter.Release(); |
242 | 248 |
243 return cache->GetFile(local_id, cache_file_path); | 249 return cache->GetFile(local_id, cache_file_path); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 observer_->OnDirectoryChangedByOperation(file_path.DirName()); | 521 observer_->OnDirectoryChangedByOperation(file_path.DirName()); |
516 params->OnComplete(*cache_file_path); | 522 params->OnComplete(*cache_file_path); |
517 } | 523 } |
518 | 524 |
519 void DownloadOperation::CancelJob(JobID job_id) { | 525 void DownloadOperation::CancelJob(JobID job_id) { |
520 scheduler_->CancelJob(job_id); | 526 scheduler_->CancelJob(job_id); |
521 } | 527 } |
522 | 528 |
523 } // namespace file_system | 529 } // namespace file_system |
524 } // namespace drive | 530 } // namespace drive |
OLD | NEW |