| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/download/save_package.h" | 5 #include "content/browser/download/save_package.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 Cancel(false); | 330 Cancel(false); |
| 331 return; | 331 return; |
| 332 } | 332 } |
| 333 wrote_to_completed_file_ = true; | 333 wrote_to_completed_file_ = true; |
| 334 download_->SetTotalBytes(size); | 334 download_->SetTotalBytes(size); |
| 335 download_->UpdateProgress(size, size, DownloadItem::kEmptyFileHash); | 335 download_->UpdateProgress(size, size, DownloadItem::kEmptyFileHash); |
| 336 // Must call OnAllDataSaved here in order for | 336 // Must call OnAllDataSaved here in order for |
| 337 // GDataDownloadObserver::ShouldUpload() to return true. | 337 // GDataDownloadObserver::ShouldUpload() to return true. |
| 338 // ShouldCompleteDownload() may depend on the gdata uploader to finish. | 338 // ShouldCompleteDownload() may depend on the gdata uploader to finish. |
| 339 download_->OnAllDataSaved(size, DownloadItem::kEmptyFileHash); | 339 download_->OnAllDataSaved(size, DownloadItem::kEmptyFileHash); |
| 340 // GDataDownloadObserver is waiting for the upload to complete. When that | 340 if (download_manager_->delegate()->ShouldCompleteDownload( |
| 341 // happens, it will call download_->MaybeCompleteDownload(), which will call | 341 download_, base::Bind(&SavePackage::Finish, this))) |
| 342 // through our OnDownloadUpdated() allowing us to Finish(). | 342 Finish(); |
| 343 // OnDownloadUpdated() may have been called in OnAllDataSaved(), so |this| may | |
| 344 // be deleted at this point. | |
| 345 } | 343 } |
| 346 | 344 |
| 347 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further | 345 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further |
| 348 // restricted by NAME_MAX. The maximum allowed path looks like: | 346 // restricted by NAME_MAX. The maximum allowed path looks like: |
| 349 // '/path/to/save_dir' + '/' + NAME_MAX. | 347 // '/path/to/save_dir' + '/' + NAME_MAX. |
| 350 uint32 SavePackage::GetMaxPathLengthForDirectory(const FilePath& base_dir) { | 348 uint32 SavePackage::GetMaxPathLengthForDirectory(const FilePath& base_dir) { |
| 351 #if defined(OS_POSIX) | 349 #if defined(OS_POSIX) |
| 352 return std::min(kMaxFilePathLength, | 350 return std::min(kMaxFilePathLength, |
| 353 static_cast<uint32>(base_dir.value().length()) + | 351 static_cast<uint32>(base_dir.value().length()) + |
| 354 NAME_MAX + 1); | 352 NAME_MAX + 1); |
| (...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 | 1349 |
| 1352 void SavePackage::OnDownloadUpdated(DownloadItem* download) { | 1350 void SavePackage::OnDownloadUpdated(DownloadItem* download) { |
| 1353 DCHECK(download_); | 1351 DCHECK(download_); |
| 1354 DCHECK(download_ == download); | 1352 DCHECK(download_ == download); |
| 1355 DCHECK(download_manager_); | 1353 DCHECK(download_manager_); |
| 1356 | 1354 |
| 1357 // Check for removal. | 1355 // Check for removal. |
| 1358 if (download_->GetState() == DownloadItem::REMOVING) { | 1356 if (download_->GetState() == DownloadItem::REMOVING) { |
| 1359 StopObservation(); | 1357 StopObservation(); |
| 1360 } | 1358 } |
| 1361 | |
| 1362 // MHTML saves may need to wait for GData to finish uploading. | |
| 1363 if ((save_type_ == content::SAVE_PAGE_TYPE_AS_MHTML) && | |
| 1364 download_->AllDataSaved() && | |
| 1365 !download_->IsComplete() && | |
| 1366 !mhtml_finishing_ && | |
| 1367 download_manager_->delegate()->ShouldCompleteDownload(download_)) { | |
| 1368 // Post a task to avoid re-entering OnDownloadUpdated. Set a flag to | |
| 1369 // prevent double-calling Finish() in case another OnDownloadUpdated happens | |
| 1370 // before Finish() runs. | |
| 1371 mhtml_finishing_ = true; | |
| 1372 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 1373 base::Bind(&SavePackage::Finish, this)); | |
| 1374 } | |
| 1375 } | 1359 } |
| 1376 | 1360 |
| 1377 void SavePackage::FinalizeDownloadEntry() { | 1361 void SavePackage::FinalizeDownloadEntry() { |
| 1378 DCHECK(download_); | 1362 DCHECK(download_); |
| 1379 DCHECK(download_manager_); | 1363 DCHECK(download_manager_); |
| 1380 | 1364 |
| 1381 download_manager_->SavePageDownloadFinished(download_); | 1365 download_manager_->SavePageDownloadFinished(download_); |
| 1382 StopObservation(); | 1366 StopObservation(); |
| 1383 } | 1367 } |
| OLD | NEW |