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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 extension, | 107 extension, |
108 &gdoc_file_path) || | 108 &gdoc_file_path) || |
109 !util::CreateGDocFile(gdoc_file_path, | 109 !util::CreateGDocFile(gdoc_file_path, |
110 GURL(entry->file_specific_info().alternate_url()), | 110 GURL(entry->file_specific_info().alternate_url()), |
111 entry->resource_id()) || | 111 entry->resource_id()) || |
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 entry->mutable_file_info()->set_size(file_info.size); |
118 return FILE_ERROR_OK; | 118 return FILE_ERROR_OK; |
119 } | 119 } |
120 | 120 |
121 if (!entry->file_specific_info().cache_state().is_present()) { | 121 if (!entry->file_specific_info().cache_state().is_present()) { |
122 // This file has no cache file. | 122 // This file has no cache file. |
123 if (!entry->resource_id().empty()) { | 123 if (!entry->resource_id().empty()) { |
124 // This entry exists on the server, leave |cache_file_path| empty to | 124 // This entry exists on the server, leave |cache_file_path| empty to |
125 // start download. | 125 // start download. |
126 return PrepareForDownloadFile(cache, entry->file_info().size(), | 126 return PrepareForDownloadFile(cache, entry->file_info().size(), |
127 temporary_file_directory, | 127 temporary_file_directory, |
(...skipping 29 matching lines...) Expand all Loading... |
157 error = cache->GetFile(local_id, cache_file_path); | 157 error = cache->GetFile(local_id, cache_file_path); |
158 if (error != FILE_ERROR_OK) | 158 if (error != FILE_ERROR_OK) |
159 return error; | 159 return error; |
160 | 160 |
161 // If the cache file is to be returned as the download result, the file info | 161 // If the cache file is to be returned as the download result, the file info |
162 // of the cache needs to be returned via |entry|. | 162 // of the cache needs to be returned via |entry|. |
163 // TODO(kinaba): crbug.com/246469. The logic below is similar to that in | 163 // TODO(kinaba): crbug.com/246469. The logic below is similar to that in |
164 // drive::FileSystem::CheckLocalModificationAndRun. We should merge them. | 164 // drive::FileSystem::CheckLocalModificationAndRun. We should merge them. |
165 base::File::Info file_info; | 165 base::File::Info file_info; |
166 if (base::GetFileInfo(*cache_file_path, &file_info)) | 166 if (base::GetFileInfo(*cache_file_path, &file_info)) |
167 SetPlatformFileInfoToResourceEntry(file_info, entry); | 167 entry->mutable_file_info()->set_size(file_info.size); |
168 | 168 |
169 return FILE_ERROR_OK; | 169 return FILE_ERROR_OK; |
170 } | 170 } |
171 | 171 |
172 struct CheckPreconditionForEnsureFileDownloadedParams { | 172 struct CheckPreconditionForEnsureFileDownloadedParams { |
173 internal::ResourceMetadata* metadata; | 173 internal::ResourceMetadata* metadata; |
174 internal::FileCache* cache; | 174 internal::FileCache* cache; |
175 base::FilePath temporary_file_directory; | 175 base::FilePath temporary_file_directory; |
176 }; | 176 }; |
177 | 177 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 observer_->OnDirectoryChangedByOperation(file_path.DirName()); | 532 observer_->OnDirectoryChangedByOperation(file_path.DirName()); |
533 params->OnDownloadCompleted(*cache_file_path, entry_after_update.Pass()); | 533 params->OnDownloadCompleted(*cache_file_path, entry_after_update.Pass()); |
534 } | 534 } |
535 | 535 |
536 void DownloadOperation::CancelJob(JobID job_id) { | 536 void DownloadOperation::CancelJob(JobID job_id) { |
537 scheduler_->CancelJob(job_id); | 537 scheduler_->CancelJob(job_id); |
538 } | 538 } |
539 | 539 |
540 } // namespace file_system | 540 } // namespace file_system |
541 } // namespace drive | 541 } // namespace drive |
OLD | NEW |