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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 183 } |
184 | 184 |
185 DownloadManagerImpl::~DownloadManagerImpl() { | 185 DownloadManagerImpl::~DownloadManagerImpl() { |
186 DCHECK(!shutdown_needed_); | 186 DCHECK(!shutdown_needed_); |
187 } | 187 } |
188 | 188 |
189 DownloadItemImpl* DownloadManagerImpl::CreateActiveItem( | 189 DownloadItemImpl* DownloadManagerImpl::CreateActiveItem( |
190 uint32_t id, | 190 uint32_t id, |
191 const DownloadCreateInfo& info) { | 191 const DownloadCreateInfo& info) { |
192 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 192 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
193 DCHECK(!ContainsKey(downloads_, id)); | 193 DCHECK(!base::ContainsKey(downloads_, id)); |
194 net::BoundNetLog bound_net_log = | 194 net::BoundNetLog bound_net_log = |
195 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 195 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); |
196 DownloadItemImpl* download = | 196 DownloadItemImpl* download = |
197 item_factory_->CreateActiveItem(this, id, info, bound_net_log); | 197 item_factory_->CreateActiveItem(this, id, info, bound_net_log); |
198 downloads_[id] = download; | 198 downloads_[id] = download; |
199 downloads_by_guid_[download->GetGuid()] = download; | 199 downloads_by_guid_[download->GetGuid()] = download; |
200 return download; | 200 return download; |
201 } | 201 } |
202 | 202 |
203 void DownloadManagerImpl::GetNextId(const DownloadIdCallback& callback) { | 203 void DownloadManagerImpl::GetNextId(const DownloadIdCallback& callback) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 276 |
277 // If there are in-progress downloads, cancel them. This also goes for | 277 // If there are in-progress downloads, cancel them. This also goes for |
278 // dangerous downloads which will remain in history if they aren't explicitly | 278 // dangerous downloads which will remain in history if they aren't explicitly |
279 // accepted or discarded. Canceling will remove the intermediate download | 279 // accepted or discarded. Canceling will remove the intermediate download |
280 // file. | 280 // file. |
281 for (const auto& it : downloads_) { | 281 for (const auto& it : downloads_) { |
282 DownloadItemImpl* download = it.second; | 282 DownloadItemImpl* download = it.second; |
283 if (download->GetState() == DownloadItem::IN_PROGRESS) | 283 if (download->GetState() == DownloadItem::IN_PROGRESS) |
284 download->Cancel(false); | 284 download->Cancel(false); |
285 } | 285 } |
286 STLDeleteValues(&downloads_); | 286 base::STLDeleteValues(&downloads_); |
287 downloads_by_guid_.clear(); | 287 downloads_by_guid_.clear(); |
288 url_downloaders_.clear(); | 288 url_downloaders_.clear(); |
289 | 289 |
290 // We'll have nothing more to report to the observers after this point. | 290 // We'll have nothing more to report to the observers after this point. |
291 observers_.Clear(); | 291 observers_.Clear(); |
292 | 292 |
293 if (delegate_) | 293 if (delegate_) |
294 delegate_->Shutdown(); | 294 delegate_->Shutdown(); |
295 delegate_ = NULL; | 295 delegate_ = NULL; |
296 } | 296 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 download_item, | 404 download_item, |
405 base::Bind(&DownloadManagerImpl::OnFileExistenceChecked, | 405 base::Bind(&DownloadManagerImpl::OnFileExistenceChecked, |
406 weak_factory_.GetWeakPtr(), download_item->GetId())); | 406 weak_factory_.GetWeakPtr(), download_item->GetId())); |
407 } | 407 } |
408 } | 408 } |
409 | 409 |
410 void DownloadManagerImpl::OnFileExistenceChecked(uint32_t download_id, | 410 void DownloadManagerImpl::OnFileExistenceChecked(uint32_t download_id, |
411 bool result) { | 411 bool result) { |
412 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 412 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
413 if (!result) { // File does not exist. | 413 if (!result) { // File does not exist. |
414 if (ContainsKey(downloads_, download_id)) | 414 if (base::ContainsKey(downloads_, download_id)) |
415 downloads_[download_id]->OnDownloadedFileRemoved(); | 415 downloads_[download_id]->OnDownloadedFileRemoved(); |
416 } | 416 } |
417 } | 417 } |
418 | 418 |
419 BrowserContext* DownloadManagerImpl::GetBrowserContext() const { | 419 BrowserContext* DownloadManagerImpl::GetBrowserContext() const { |
420 return browser_context_; | 420 return browser_context_; |
421 } | 421 } |
422 | 422 |
423 void DownloadManagerImpl::CreateSavePackageDownloadItem( | 423 void DownloadManagerImpl::CreateSavePackageDownloadItem( |
424 const base::FilePath& main_file_path, | 424 const base::FilePath& main_file_path, |
(...skipping 10 matching lines...) Expand all Loading... |
435 | 435 |
436 void DownloadManagerImpl::CreateSavePackageDownloadItemWithId( | 436 void DownloadManagerImpl::CreateSavePackageDownloadItemWithId( |
437 const base::FilePath& main_file_path, | 437 const base::FilePath& main_file_path, |
438 const GURL& page_url, | 438 const GURL& page_url, |
439 const std::string& mime_type, | 439 const std::string& mime_type, |
440 std::unique_ptr<DownloadRequestHandleInterface> request_handle, | 440 std::unique_ptr<DownloadRequestHandleInterface> request_handle, |
441 const DownloadItemImplCreated& item_created, | 441 const DownloadItemImplCreated& item_created, |
442 uint32_t id) { | 442 uint32_t id) { |
443 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 443 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
444 DCHECK_NE(content::DownloadItem::kInvalidId, id); | 444 DCHECK_NE(content::DownloadItem::kInvalidId, id); |
445 DCHECK(!ContainsKey(downloads_, id)); | 445 DCHECK(!base::ContainsKey(downloads_, id)); |
446 net::BoundNetLog bound_net_log = | 446 net::BoundNetLog bound_net_log = |
447 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); | 447 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); |
448 DownloadItemImpl* download_item = item_factory_->CreateSavePageItem( | 448 DownloadItemImpl* download_item = item_factory_->CreateSavePageItem( |
449 this, id, main_file_path, page_url, mime_type, std::move(request_handle), | 449 this, id, main_file_path, page_url, mime_type, std::move(request_handle), |
450 bound_net_log); | 450 bound_net_log); |
451 downloads_[download_item->GetId()] = download_item; | 451 downloads_[download_item->GetId()] = download_item; |
452 DCHECK(!ContainsKey(downloads_by_guid_, download_item->GetGuid())); | 452 DCHECK(!base::ContainsKey(downloads_by_guid_, download_item->GetGuid())); |
453 downloads_by_guid_[download_item->GetGuid()] = download_item; | 453 downloads_by_guid_[download_item->GetGuid()] = download_item; |
454 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated( | 454 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated( |
455 this, download_item)); | 455 this, download_item)); |
456 if (!item_created.is_null()) | 456 if (!item_created.is_null()) |
457 item_created.Run(download_item); | 457 item_created.Run(download_item); |
458 } | 458 } |
459 | 459 |
460 void DownloadManagerImpl::OnSavePackageSuccessfullyFinished( | 460 void DownloadManagerImpl::OnSavePackageSuccessfullyFinished( |
461 DownloadItem* download_item) { | 461 DownloadItem* download_item) { |
462 FOR_EACH_OBSERVER(Observer, observers_, | 462 FOR_EACH_OBSERVER(Observer, observers_, |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 const base::Time& end_time, | 616 const base::Time& end_time, |
617 const std::string& etag, | 617 const std::string& etag, |
618 const std::string& last_modified, | 618 const std::string& last_modified, |
619 int64_t received_bytes, | 619 int64_t received_bytes, |
620 int64_t total_bytes, | 620 int64_t total_bytes, |
621 const std::string& hash, | 621 const std::string& hash, |
622 DownloadItem::DownloadState state, | 622 DownloadItem::DownloadState state, |
623 DownloadDangerType danger_type, | 623 DownloadDangerType danger_type, |
624 DownloadInterruptReason interrupt_reason, | 624 DownloadInterruptReason interrupt_reason, |
625 bool opened) { | 625 bool opened) { |
626 if (ContainsKey(downloads_, id)) { | 626 if (base::ContainsKey(downloads_, id)) { |
627 NOTREACHED(); | 627 NOTREACHED(); |
628 return NULL; | 628 return NULL; |
629 } | 629 } |
630 DCHECK(!ContainsKey(downloads_by_guid_, guid)); | 630 DCHECK(!base::ContainsKey(downloads_by_guid_, guid)); |
631 DownloadItemImpl* item = item_factory_->CreatePersistedItem( | 631 DownloadItemImpl* item = item_factory_->CreatePersistedItem( |
632 this, guid, id, current_path, target_path, url_chain, referrer_url, | 632 this, guid, id, current_path, target_path, url_chain, referrer_url, |
633 site_url, tab_url, tab_refererr_url, mime_type, original_mime_type, | 633 site_url, tab_url, tab_refererr_url, mime_type, original_mime_type, |
634 start_time, end_time, etag, last_modified, received_bytes, total_bytes, | 634 start_time, end_time, etag, last_modified, received_bytes, total_bytes, |
635 hash, state, danger_type, interrupt_reason, opened, | 635 hash, state, danger_type, interrupt_reason, opened, |
636 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); | 636 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); |
637 downloads_[id] = item; | 637 downloads_[id] = item; |
638 downloads_by_guid_[guid] = item; | 638 downloads_by_guid_[guid] = item; |
639 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); | 639 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); |
640 DVLOG(20) << __func__ << "() download = " << item->DebugString(true); | 640 DVLOG(20) << __func__ << "() download = " << item->DebugString(true); |
(...skipping 18 matching lines...) Expand all Loading... |
659 it.second->GetDangerType() != DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST && | 659 it.second->GetDangerType() != DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST && |
660 it.second->GetDangerType() != | 660 it.second->GetDangerType() != |
661 DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED) { | 661 DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED) { |
662 ++count; | 662 ++count; |
663 } | 663 } |
664 } | 664 } |
665 return count; | 665 return count; |
666 } | 666 } |
667 | 667 |
668 DownloadItem* DownloadManagerImpl::GetDownload(uint32_t download_id) { | 668 DownloadItem* DownloadManagerImpl::GetDownload(uint32_t download_id) { |
669 return ContainsKey(downloads_, download_id) ? downloads_[download_id] | 669 return base::ContainsKey(downloads_, download_id) ? downloads_[download_id] |
670 : nullptr; | 670 : nullptr; |
671 } | 671 } |
672 | 672 |
673 DownloadItem* DownloadManagerImpl::GetDownloadByGuid(const std::string& guid) { | 673 DownloadItem* DownloadManagerImpl::GetDownloadByGuid(const std::string& guid) { |
674 DCHECK(guid == base::ToUpperASCII(guid)); | 674 DCHECK(guid == base::ToUpperASCII(guid)); |
675 return ContainsKey(downloads_by_guid_, guid) ? downloads_by_guid_[guid] | 675 return base::ContainsKey(downloads_by_guid_, guid) ? downloads_by_guid_[guid] |
676 : nullptr; | 676 : nullptr; |
677 } | 677 } |
678 | 678 |
679 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { | 679 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { |
680 for (const auto& it : downloads_) { | 680 for (const auto& it : downloads_) { |
681 downloads->push_back(it.second); | 681 downloads->push_back(it.second); |
682 } | 682 } |
683 } | 683 } |
684 | 684 |
685 void DownloadManagerImpl::OpenDownload(DownloadItemImpl* download) { | 685 void DownloadManagerImpl::OpenDownload(DownloadItemImpl* download) { |
686 int num_unopened = 0; | 686 int num_unopened = 0; |
687 for (const auto& it : downloads_) { | 687 for (const auto& it : downloads_) { |
688 DownloadItemImpl* item = it.second; | 688 DownloadItemImpl* item = it.second; |
689 if ((item->GetState() == DownloadItem::COMPLETE) && | 689 if ((item->GetState() == DownloadItem::COMPLETE) && |
690 !item->GetOpened()) | 690 !item->GetOpened()) |
691 ++num_unopened; | 691 ++num_unopened; |
692 } | 692 } |
693 RecordOpensOutstanding(num_unopened); | 693 RecordOpensOutstanding(num_unopened); |
694 | 694 |
695 if (delegate_) | 695 if (delegate_) |
696 delegate_->OpenDownload(download); | 696 delegate_->OpenDownload(download); |
697 } | 697 } |
698 | 698 |
699 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 699 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
700 if (delegate_) | 700 if (delegate_) |
701 delegate_->ShowDownloadInShell(download); | 701 delegate_->ShowDownloadInShell(download); |
702 } | 702 } |
703 | 703 |
704 } // namespace content | 704 } // namespace content |
OLD | NEW |