| 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/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 downloads_.insert(download); | 426 downloads_.insert(download); |
| 427 active_downloads_[download_id] = download; | 427 active_downloads_[download_id] = download; |
| 428 | 428 |
| 429 return bound_net_log; | 429 return bound_net_log; |
| 430 } | 430 } |
| 431 | 431 |
| 432 DownloadItem* DownloadManagerImpl::CreateSavePackageDownloadItem( | 432 DownloadItem* DownloadManagerImpl::CreateSavePackageDownloadItem( |
| 433 const FilePath& main_file_path, | 433 const FilePath& main_file_path, |
| 434 const GURL& page_url, | 434 const GURL& page_url, |
| 435 bool is_otr, | 435 bool is_otr, |
| 436 const std::string& mime_type, |
| 436 DownloadItem::Observer* observer) { | 437 DownloadItem::Observer* observer) { |
| 437 net::BoundNetLog bound_net_log = | 438 net::BoundNetLog bound_net_log = |
| 438 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 439 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); |
| 439 DownloadItem* download = new DownloadItemImpl( | 440 DownloadItem* download = new DownloadItemImpl( |
| 440 this, main_file_path, page_url, is_otr, GetNextId(), bound_net_log); | 441 this, |
| 442 main_file_path, |
| 443 page_url, |
| 444 is_otr, |
| 445 GetNextId(), |
| 446 mime_type, |
| 447 bound_net_log); |
| 441 | 448 |
| 442 download->AddObserver(observer); | 449 download->AddObserver(observer); |
| 443 | 450 |
| 444 DCHECK(!ContainsKey(save_page_downloads_, download->GetId())); | 451 DCHECK(!ContainsKey(save_page_downloads_, download->GetId())); |
| 445 downloads_.insert(download); | 452 downloads_.insert(download); |
| 446 save_page_downloads_[download->GetId()] = download; | 453 save_page_downloads_[download->GetId()] = download; |
| 447 | 454 |
| 448 // Will notify the observer in the callback. | 455 // Will notify the observer in the callback. |
| 449 delegate_->AddItemToPersistentStore(download); | 456 delegate_->AddItemToPersistentStore(download); |
| 450 | 457 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 | 606 |
| 600 // If the download hasn't been inserted into the history system | 607 // If the download hasn't been inserted into the history system |
| 601 // (which occurs strictly after file name determination, intermediate | 608 // (which occurs strictly after file name determination, intermediate |
| 602 // file rename, and UI display) then it's not ready for completion. | 609 // file rename, and UI display) then it's not ready for completion. |
| 603 if (!download->IsPersisted()) | 610 if (!download->IsPersisted()) |
| 604 return false; | 611 return false; |
| 605 | 612 |
| 606 return true; | 613 return true; |
| 607 } | 614 } |
| 608 | 615 |
| 616 // When SavePackage downloads MHTML to GData (see |
| 617 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it |
| 618 // does for non-SavePackage downloads, but SavePackage downloads never satisfy |
| 619 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls |
| 620 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage |
| 621 // notices that the upload has completed and runs its normal Finish() pathway. |
| 622 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes |
| 623 // downloads. SavePackage always uses its own Finish() to mark downloads |
| 624 // complete. |
| 625 |
| 609 void DownloadManagerImpl::MaybeCompleteDownload(DownloadItem* download) { | 626 void DownloadManagerImpl::MaybeCompleteDownload(DownloadItem* download) { |
| 610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 611 VLOG(20) << __FUNCTION__ << "()" << " download = " | 628 VLOG(20) << __FUNCTION__ << "()" << " download = " |
| 612 << download->DebugString(false); | 629 << download->DebugString(false); |
| 613 | 630 |
| 614 if (!IsDownloadReadyForCompletion(download)) | 631 if (!IsDownloadReadyForCompletion(download)) |
| 615 return; | 632 return; |
| 616 | 633 |
| 617 // TODO(rdsmith): DCHECK that we only pass through this point | 634 // TODO(rdsmith): DCHECK that we only pass through this point |
| 618 // once per download. The natural way to do this is by a state | 635 // once per download. The natural way to do this is by a state |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 if (it->second->IsComplete() && !it->second->GetOpened()) | 1192 if (it->second->IsComplete() && !it->second->GetOpened()) |
| 1176 ++num_unopened; | 1193 ++num_unopened; |
| 1177 } | 1194 } |
| 1178 download_stats::RecordOpensOutstanding(num_unopened); | 1195 download_stats::RecordOpensOutstanding(num_unopened); |
| 1179 } | 1196 } |
| 1180 | 1197 |
| 1181 void DownloadManagerImpl::SetFileManagerForTesting( | 1198 void DownloadManagerImpl::SetFileManagerForTesting( |
| 1182 DownloadFileManager* file_manager) { | 1199 DownloadFileManager* file_manager) { |
| 1183 file_manager_ = file_manager; | 1200 file_manager_ = file_manager; |
| 1184 } | 1201 } |
| OLD | NEW |