OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 DownloadManagerImpl::~DownloadManagerImpl() { | 94 DownloadManagerImpl::~DownloadManagerImpl() { |
95 DCHECK(!shutdown_needed_); | 95 DCHECK(!shutdown_needed_); |
96 if (status_updater_.get() != NULL) | 96 if (status_updater_.get() != NULL) |
97 status_updater_->RemoveDelegate(this); | 97 status_updater_->RemoveDelegate(this); |
98 } | 98 } |
99 | 99 |
100 DownloadId DownloadManagerImpl::GetNextId() { | 100 DownloadId DownloadManagerImpl::GetNextId() { |
101 return id_factory_->GetNextId(); | 101 return id_factory_->GetNextId(); |
102 } | 102 } |
103 | 103 |
| 104 bool DownloadManagerImpl::ShouldOpenDownload(DownloadItem* item) { |
| 105 return delegate_->ShouldOpenDownload(item); |
| 106 } |
| 107 |
| 108 bool DownloadManagerImpl::ShouldOpenFileBasedOnExtension(const FilePath& path) { |
| 109 return delegate_->ShouldOpenFileBasedOnExtension(path); |
| 110 } |
| 111 |
104 void DownloadManagerImpl::Shutdown() { | 112 void DownloadManagerImpl::Shutdown() { |
105 VLOG(20) << __FUNCTION__ << "()" | 113 VLOG(20) << __FUNCTION__ << "()" |
106 << " shutdown_needed_ = " << shutdown_needed_; | 114 << " shutdown_needed_ = " << shutdown_needed_; |
107 if (!shutdown_needed_) | 115 if (!shutdown_needed_) |
108 return; | 116 return; |
109 shutdown_needed_ = false; | 117 shutdown_needed_ = false; |
110 | 118 |
111 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown()); | 119 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown()); |
112 // TODO(benjhayden): Consider clearing observers_. | 120 // TODO(benjhayden): Consider clearing observers_. |
113 | 121 |
(...skipping 13 matching lines...) Expand all Loading... |
127 // Save iterator from potential erases in this set done by called code. | 135 // Save iterator from potential erases in this set done by called code. |
128 // Iterators after an erasure point are still valid for lists and | 136 // Iterators after an erasure point are still valid for lists and |
129 // associative containers such as sets. | 137 // associative containers such as sets. |
130 it++; | 138 it++; |
131 | 139 |
132 if (download->GetSafetyState() == DownloadItem::DANGEROUS && | 140 if (download->GetSafetyState() == DownloadItem::DANGEROUS && |
133 download->IsPartialDownload()) { | 141 download->IsPartialDownload()) { |
134 // The user hasn't accepted it, so we need to remove it | 142 // The user hasn't accepted it, so we need to remove it |
135 // from the disk. This may or may not result in it being | 143 // from the disk. This may or may not result in it being |
136 // removed from the DownloadManager queues and deleted | 144 // removed from the DownloadManager queues and deleted |
137 // (specifically, DownloadManager::RemoveDownload only | 145 // (specifically, DownloadManager::DownloadRemoved only |
138 // removes and deletes it if it's known to the history service) | 146 // removes and deletes it if it's known to the history service) |
139 // so the only thing we know after calling this function is that | 147 // so the only thing we know after calling this function is that |
140 // the download was deleted if-and-only-if it was removed | 148 // the download was deleted if-and-only-if it was removed |
141 // from all queues. | 149 // from all queues. |
142 download->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN); | 150 download->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN); |
143 } else if (download->IsPartialDownload()) { | 151 } else if (download->IsPartialDownload()) { |
144 download->Cancel(false); | 152 download->Cancel(false); |
145 delegate_->UpdateItemInPersistentStore(download); | 153 delegate_->UpdateItemInPersistentStore(download); |
146 } | 154 } |
147 } | 155 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 contents, suggested_path, reinterpret_cast<void*>(id_ptr)); | 318 contents, suggested_path, reinterpret_cast<void*>(id_ptr)); |
311 | 319 |
312 FOR_EACH_OBSERVER(Observer, observers_, | 320 FOR_EACH_OBSERVER(Observer, observers_, |
313 SelectFileDialogDisplayed(download_id)); | 321 SelectFileDialogDisplayed(download_id)); |
314 } else { | 322 } else { |
315 // No prompting for download, just continue with the suggested name. | 323 // No prompting for download, just continue with the suggested name. |
316 ContinueDownloadWithPath(download, suggested_path); | 324 ContinueDownloadWithPath(download, suggested_path); |
317 } | 325 } |
318 } | 326 } |
319 | 327 |
320 content::BrowserContext* DownloadManagerImpl::BrowserContext() { | 328 content::BrowserContext* DownloadManagerImpl::BrowserContext() const { |
321 return browser_context_; | 329 return browser_context_; |
322 } | 330 } |
323 | 331 |
324 FilePath DownloadManagerImpl::LastDownloadPath() { | 332 FilePath DownloadManagerImpl::LastDownloadPath() { |
325 return last_download_path_; | 333 return last_download_path_; |
326 } | 334 } |
327 | 335 |
328 void DownloadManagerImpl::CreateDownloadItem( | 336 void DownloadManagerImpl::CreateDownloadItem( |
329 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) { | 337 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) { |
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
331 | 339 |
332 DownloadItem* download = new DownloadItemImpl( | 340 DownloadItem* download = new DownloadItemImpl( |
333 this, *info, new DownloadRequestHandle(request_handle), | 341 this, *info, new DownloadRequestHandle(request_handle), |
334 browser_context_->IsOffTheRecord()); | 342 browser_context_->IsOffTheRecord()); |
335 int32 download_id = info->download_id.local(); | 343 int32 download_id = info->download_id.local(); |
336 DCHECK(!ContainsKey(in_progress_, download_id)); | 344 DCHECK(!ContainsKey(in_progress_, download_id)); |
337 | 345 |
338 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. | 346 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. |
339 CHECK(!ContainsKey(active_downloads_, download_id)); | 347 CHECK(!ContainsKey(active_downloads_, download_id)); |
340 downloads_.insert(download); | 348 downloads_.insert(download); |
341 active_downloads_[download_id] = download; | 349 active_downloads_[download_id] = download; |
342 } | 350 } |
343 | 351 |
| 352 DownloadItem* DownloadManagerImpl::CreateSavePackageDownloadItem( |
| 353 const FilePath& main_file_path, |
| 354 const GURL& page_url, |
| 355 bool is_otr, |
| 356 DownloadItem::Observer* observer) { |
| 357 DownloadItem* download = new DownloadItemImpl( |
| 358 this, main_file_path, page_url, is_otr, GetNextId()); |
| 359 |
| 360 download->AddObserver(observer); |
| 361 |
| 362 DCHECK(!ContainsKey(save_page_downloads_, download->GetId())); |
| 363 downloads_.insert(download); |
| 364 save_page_downloads_[download->GetId()] = download; |
| 365 |
| 366 // Will notify the observer in the callback. |
| 367 delegate_->AddItemToPersistentStore(download); |
| 368 |
| 369 return download; |
| 370 } |
| 371 |
344 void DownloadManagerImpl::ContinueDownloadWithPath( | 372 void DownloadManagerImpl::ContinueDownloadWithPath( |
345 DownloadItem* download, const FilePath& chosen_file) { | 373 DownloadItem* download, const FilePath& chosen_file) { |
346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
347 DCHECK(download); | 375 DCHECK(download); |
348 | 376 |
349 int32 download_id = download->GetId(); | 377 int32 download_id = download->GetId(); |
350 | 378 |
351 // NOTE(ahendrickson) Eventually |active_downloads_| will replace | 379 // NOTE(ahendrickson) Eventually |active_downloads_| will replace |
352 // |in_progress_|, but we don't want to change the semantics yet. | 380 // |in_progress_|, but we don't want to change the semantics yet. |
353 DCHECK(!ContainsKey(in_progress_, download_id)); | 381 DCHECK(!ContainsKey(in_progress_, download_id)); |
(...skipping 10 matching lines...) Expand all Loading... |
364 UpdateDownloadProgress(); // Reflect entry into in_progress_. | 392 UpdateDownloadProgress(); // Reflect entry into in_progress_. |
365 | 393 |
366 // Rename to intermediate name. | 394 // Rename to intermediate name. |
367 FilePath download_path; | 395 FilePath download_path; |
368 if (!delegate_->OverrideIntermediatePath(download, &download_path)) | 396 if (!delegate_->OverrideIntermediatePath(download, &download_path)) |
369 download_path = download->GetFullPath(); | 397 download_path = download->GetFullPath(); |
370 | 398 |
371 BrowserThread::PostTask( | 399 BrowserThread::PostTask( |
372 BrowserThread::FILE, FROM_HERE, | 400 BrowserThread::FILE, FROM_HERE, |
373 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile, | 401 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile, |
374 file_manager_, download->GetGlobalId(), download_path)); | 402 file_manager_, download->GetGlobalId(), |
| 403 download_path)); |
375 | 404 |
376 download->Rename(download_path); | 405 download->Rename(download_path); |
377 | 406 |
378 delegate_->AddItemToPersistentStore(download); | 407 delegate_->AddItemToPersistentStore(download); |
379 } | 408 } |
380 | 409 |
381 void DownloadManagerImpl::UpdateDownload(int32 download_id, int64 bytes_so_far, | 410 void DownloadManagerImpl::UpdateDownload(int32 download_id, int64 bytes_so_far, |
382 int64 bytes_per_sec) { | 411 int64 bytes_per_sec) { |
383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
384 DownloadMap::iterator it = active_downloads_.find(download_id); | 413 DownloadMap::iterator it = active_downloads_.find(download_id); |
(...skipping 17 matching lines...) Expand all Loading... |
402 | 431 |
403 // If it's not in active_downloads_, that means it was cancelled; just | 432 // If it's not in active_downloads_, that means it was cancelled; just |
404 // ignore the notification. | 433 // ignore the notification. |
405 if (active_downloads_.count(download_id) == 0) | 434 if (active_downloads_.count(download_id) == 0) |
406 return; | 435 return; |
407 | 436 |
408 DownloadItem* download = active_downloads_[download_id]; | 437 DownloadItem* download = active_downloads_[download_id]; |
409 download->OnAllDataSaved(size, hash); | 438 download->OnAllDataSaved(size, hash); |
410 delegate_->OnResponseCompleted(download); | 439 delegate_->OnResponseCompleted(download); |
411 | 440 |
412 MaybeCompleteDownload(download); | 441 download->MaybeCompleteDownload(); |
413 } | 442 } |
414 | 443 |
415 void DownloadManagerImpl::AssertQueueStateConsistent(DownloadItem* download) { | 444 void DownloadManagerImpl::AssertStateConsistent(DownloadItem* download) const { |
416 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 445 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
417 if (download->GetState() == DownloadItem::REMOVING) { | 446 if (download->GetState() == DownloadItem::REMOVING) { |
418 CHECK(!ContainsKey(downloads_, download)); | 447 CHECK(!ContainsKey(downloads_, download)); |
419 CHECK(!ContainsKey(active_downloads_, download->GetId())); | 448 CHECK(!ContainsKey(active_downloads_, download->GetId())); |
420 CHECK(!ContainsKey(in_progress_, download->GetId())); | 449 CHECK(!ContainsKey(in_progress_, download->GetId())); |
421 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle())); | 450 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle())); |
422 return; | 451 return; |
423 } | 452 } |
424 | 453 |
425 // Should be in downloads_ if we're not REMOVING. | 454 // Should be in downloads_ if we're not REMOVING. |
426 CHECK(ContainsKey(downloads_, download)); | 455 CHECK(ContainsKey(downloads_, download)); |
427 | 456 |
428 // Check history_downloads_ consistency. | 457 // Check history_downloads_ consistency. |
429 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) { | 458 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) { |
430 CHECK(ContainsKey(history_downloads_, download->GetDbHandle())); | 459 CHECK(ContainsKey(history_downloads_, download->GetDbHandle())); |
431 } else { | 460 } else { |
432 // TODO(rdsmith): Somewhat painful; make sure to disable in | 461 // TODO(rdsmith): Somewhat painful; make sure to disable in |
433 // release builds after resolution of http://crbug.com/85408. | 462 // release builds after resolution of http://crbug.com/85408. |
434 for (DownloadMap::iterator it = history_downloads_.begin(); | 463 for (DownloadMap::const_iterator it = history_downloads_.begin(); |
435 it != history_downloads_.end(); ++it) { | 464 it != history_downloads_.end(); ++it) { |
436 CHECK(it->second != download); | 465 CHECK(it->second != download); |
437 } | 466 } |
438 } | 467 } |
439 | 468 |
440 int64 state = download->GetState(); | 469 int64 state = download->GetState(); |
441 base::debug::Alias(&state); | 470 base::debug::Alias(&state); |
442 if (ContainsKey(active_downloads_, download->GetId())) { | 471 if (ContainsKey(active_downloads_, download->GetId())) { |
443 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) | 472 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) |
444 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState()); | 473 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 // Remove the id from in_progress | 533 // Remove the id from in_progress |
505 in_progress_.erase(download->GetId()); | 534 in_progress_.erase(download->GetId()); |
506 UpdateDownloadProgress(); // Reflect removal from in_progress_. | 535 UpdateDownloadProgress(); // Reflect removal from in_progress_. |
507 | 536 |
508 delegate_->UpdateItemInPersistentStore(download); | 537 delegate_->UpdateItemInPersistentStore(download); |
509 | 538 |
510 // Finish the download. | 539 // Finish the download. |
511 download->OnDownloadCompleting(file_manager_); | 540 download->OnDownloadCompleting(file_manager_); |
512 } | 541 } |
513 | 542 |
514 void DownloadManagerImpl::DownloadCompleted(int32 download_id) { | 543 void DownloadManagerImpl::DownloadCompleted(DownloadItem* download) { |
515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
516 DownloadItem* download = GetDownloadItem(download_id); | |
517 DCHECK(download); | 545 DCHECK(download); |
518 delegate_->UpdateItemInPersistentStore(download); | 546 delegate_->UpdateItemInPersistentStore(download); |
519 active_downloads_.erase(download_id); | 547 active_downloads_.erase(download->GetId()); |
520 AssertQueueStateConsistent(download); | 548 AssertStateConsistent(download); |
521 } | 549 } |
522 | 550 |
523 void DownloadManagerImpl::OnDownloadRenamedToFinalName( | 551 void DownloadManagerImpl::OnDownloadRenamedToFinalName( |
524 int download_id, | 552 int download_id, |
525 const FilePath& full_path, | 553 const FilePath& full_path, |
526 int uniquifier) { | 554 int uniquifier) { |
527 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id | 555 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id |
528 << " full_path = \"" << full_path.value() << "\"" | 556 << " full_path = \"" << full_path.value() << "\"" |
529 << " uniquifier = " << uniquifier; | 557 << " uniquifier = " << uniquifier; |
530 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 21 matching lines...) Expand all Loading... |
552 void DownloadManagerImpl::CancelDownload(int32 download_id) { | 580 void DownloadManagerImpl::CancelDownload(int32 download_id) { |
553 DownloadItem* download = GetActiveDownload(download_id); | 581 DownloadItem* download = GetActiveDownload(download_id); |
554 // A cancel at the right time could remove the download from the | 582 // A cancel at the right time could remove the download from the |
555 // |active_downloads_| map before we get here. | 583 // |active_downloads_| map before we get here. |
556 if (!download) | 584 if (!download) |
557 return; | 585 return; |
558 | 586 |
559 download->Cancel(true); | 587 download->Cancel(true); |
560 } | 588 } |
561 | 589 |
562 void DownloadManagerImpl::DownloadCancelledInternal(DownloadItem* download) { | 590 void DownloadManagerImpl::DownloadCancelled(DownloadItem* download) { |
563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
564 | 592 |
565 VLOG(20) << __FUNCTION__ << "()" | 593 VLOG(20) << __FUNCTION__ << "()" |
566 << " download = " << download->DebugString(true); | 594 << " download = " << download->DebugString(true); |
567 | 595 |
568 RemoveFromActiveList(download); | 596 RemoveFromActiveList(download); |
569 // This function is called from the DownloadItem, so DI state | 597 // This function is called from the DownloadItem, so DI state |
570 // should already have been updated. | 598 // should already have been updated. |
571 AssertQueueStateConsistent(download); | 599 AssertStateConsistent(download); |
572 | 600 |
573 if (file_manager_) | 601 if (file_manager_) |
574 download->OffThreadCancel(file_manager_); | 602 download->OffThreadCancel(file_manager_); |
575 } | 603 } |
576 | 604 |
577 void DownloadManagerImpl::OnDownloadInterrupted(int32 download_id, | 605 void DownloadManagerImpl::OnDownloadInterrupted(int32 download_id, |
578 int64 size, | 606 int64 size, |
579 InterruptReason reason) { | 607 InterruptReason reason) { |
580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
581 | 609 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 | 681 |
654 // Tell observers to refresh their views. | 682 // Tell observers to refresh their views. |
655 NotifyModelChanged(); | 683 NotifyModelChanged(); |
656 | 684 |
657 // Delete the download items themselves. | 685 // Delete the download items themselves. |
658 const int num_deleted = static_cast<int>(pending_deletes.size()); | 686 const int num_deleted = static_cast<int>(pending_deletes.size()); |
659 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end()); | 687 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end()); |
660 return num_deleted; | 688 return num_deleted; |
661 } | 689 } |
662 | 690 |
663 void DownloadManagerImpl::RemoveDownload(int64 download_handle) { | 691 void DownloadManagerImpl::DownloadRemoved(DownloadItem* download) { |
664 DownloadMap::iterator it = history_downloads_.find(download_handle); | 692 if (history_downloads_.find(download->GetDbHandle()) == |
665 if (it == history_downloads_.end()) | 693 history_downloads_.end()) |
666 return; | 694 return; |
667 | 695 |
668 // Make history update. | 696 // Make history update. |
669 DownloadItem* download = it->second; | |
670 delegate_->RemoveItemFromPersistentStore(download); | 697 delegate_->RemoveItemFromPersistentStore(download); |
671 | 698 |
672 // Remove from our tables and delete. | 699 // Remove from our tables and delete. |
673 int downloads_count = RemoveDownloadItems(DownloadVector(1, download)); | 700 int downloads_count = RemoveDownloadItems(DownloadVector(1, download)); |
674 DCHECK_EQ(1, downloads_count); | 701 DCHECK_EQ(1, downloads_count); |
675 } | 702 } |
676 | 703 |
677 int DownloadManagerImpl::RemoveDownloadsBetween(const base::Time remove_begin, | 704 int DownloadManagerImpl::RemoveDownloadsBetween(const base::Time remove_begin, |
678 const base::Time remove_end) { | 705 const base::Time remove_end) { |
679 delegate_->RemoveItemsFromPersistentStoreBetween(remove_begin, remove_end); | 706 delegate_->RemoveItemsFromPersistentStoreBetween(remove_begin, remove_end); |
680 | 707 |
681 // All downloads visible to the user will be in the history, | 708 // All downloads visible to the user will be in the history, |
682 // so scan that map. | 709 // so scan that map. |
683 DownloadVector pending_deletes; | 710 DownloadVector pending_deletes; |
684 for (DownloadMap::const_iterator it = history_downloads_.begin(); | 711 for (DownloadMap::const_iterator it = history_downloads_.begin(); |
685 it != history_downloads_.end(); | 712 it != history_downloads_.end(); |
686 ++it) { | 713 ++it) { |
687 DownloadItem* download = it->second; | 714 DownloadItem* download = it->second; |
688 if (download->GetStartTime() >= remove_begin && | 715 if (download->GetStartTime() >= remove_begin && |
689 (remove_end.is_null() || download->GetStartTime() < remove_end) && | 716 (remove_end.is_null() || download->GetStartTime() < remove_end) && |
690 (download->IsComplete() || download->IsCancelled())) { | 717 (download->IsComplete() || download->IsCancelled())) { |
691 AssertQueueStateConsistent(download); | 718 AssertStateConsistent(download); |
692 pending_deletes.push_back(download); | 719 pending_deletes.push_back(download); |
693 } | 720 } |
694 } | 721 } |
695 return RemoveDownloadItems(pending_deletes); | 722 return RemoveDownloadItems(pending_deletes); |
696 } | 723 } |
697 | 724 |
698 int DownloadManagerImpl::RemoveDownloads(const base::Time remove_begin) { | 725 int DownloadManagerImpl::RemoveDownloads(const base::Time remove_begin) { |
699 return RemoveDownloadsBetween(remove_begin, base::Time()); | 726 return RemoveDownloadsBetween(remove_begin, base::Time()); |
700 } | 727 } |
701 | 728 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 | 855 |
829 // The history service has retrieved all download entries. 'entries' contains | 856 // The history service has retrieved all download entries. 'entries' contains |
830 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). | 857 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). |
831 void DownloadManagerImpl::OnPersistentStoreQueryComplete( | 858 void DownloadManagerImpl::OnPersistentStoreQueryComplete( |
832 std::vector<DownloadPersistentStoreInfo>* entries) { | 859 std::vector<DownloadPersistentStoreInfo>* entries) { |
833 // TODO(rdsmith): Remove this and related logic when | 860 // TODO(rdsmith): Remove this and related logic when |
834 // http://crbug.com/85408 is fixed. | 861 // http://crbug.com/85408 is fixed. |
835 largest_db_handle_in_history_ = 0; | 862 largest_db_handle_in_history_ = 0; |
836 | 863 |
837 for (size_t i = 0; i < entries->size(); ++i) { | 864 for (size_t i = 0; i < entries->size(); ++i) { |
838 DownloadItem* download = new DownloadItemImpl(this, entries->at(i)); | 865 DownloadItem* download = new DownloadItemImpl( |
| 866 this, GetNextId(), entries->at(i)); |
839 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. | 867 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. |
840 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle())); | 868 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle())); |
841 downloads_.insert(download); | 869 downloads_.insert(download); |
842 history_downloads_[download->GetDbHandle()] = download; | 870 history_downloads_[download->GetDbHandle()] = download; |
843 VLOG(20) << __FUNCTION__ << "()" << i << ">" | 871 VLOG(20) << __FUNCTION__ << "()" << i << ">" |
844 << " download = " << download->DebugString(true); | 872 << " download = " << download->DebugString(true); |
845 | 873 |
846 if (download->GetDbHandle() > largest_db_handle_in_history_) | 874 if (download->GetDbHandle() > largest_db_handle_in_history_) |
847 largest_db_handle_in_history_ = download->GetDbHandle(); | 875 largest_db_handle_in_history_ = download->GetDbHandle(); |
848 } | 876 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 DownloadSet remainder; | 1046 DownloadSet remainder; |
1019 std::insert_iterator<DownloadSet> | 1047 std::insert_iterator<DownloadSet> |
1020 insert_remainder(remainder, remainder.begin()); | 1048 insert_remainder(remainder, remainder.begin()); |
1021 std::set_difference(downloads_.begin(), downloads_.end(), | 1049 std::set_difference(downloads_.begin(), downloads_.end(), |
1022 downloads_union.begin(), downloads_union.end(), | 1050 downloads_union.begin(), downloads_union.end(), |
1023 insert_remainder); | 1051 insert_remainder); |
1024 DCHECK(remainder.empty()); | 1052 DCHECK(remainder.empty()); |
1025 #endif | 1053 #endif |
1026 } | 1054 } |
1027 | 1055 |
1028 void DownloadManagerImpl::SavePageDownloadStarted(DownloadItem* download) { | |
1029 DCHECK(!ContainsKey(save_page_downloads_, download->GetId())); | |
1030 downloads_.insert(download); | |
1031 save_page_downloads_[download->GetId()] = download; | |
1032 | |
1033 // Add this entry to the history service. | |
1034 // Additionally, the UI is notified in the callback. | |
1035 delegate_->AddItemToPersistentStore(download); | |
1036 } | |
1037 | |
1038 // SavePackage will call SavePageDownloadFinished upon completion/cancellation. | 1056 // SavePackage will call SavePageDownloadFinished upon completion/cancellation. |
1039 // The history callback will call OnSavePageItemAddedToPersistentStore. | 1057 // The history callback will call OnSavePageItemAddedToPersistentStore. |
1040 // If the download finishes before the history callback, | 1058 // If the download finishes before the history callback, |
1041 // OnSavePageItemAddedToPersistentStore calls SavePageDownloadFinished, ensuring | 1059 // OnSavePageItemAddedToPersistentStore calls SavePageDownloadFinished, ensuring |
1042 // that the history event is update regardless of the order in which these two | 1060 // that the history event is update regardless of the order in which these two |
1043 // events complete. | 1061 // events complete. |
1044 // If something removes the download item from the download manager (Remove, | 1062 // If something removes the download item from the download manager (Remove, |
1045 // Shutdown) the result will be that the SavePage system will not be able to | 1063 // Shutdown) the result will be that the SavePage system will not be able to |
1046 // properly update the download item (which no longer exists) or the download | 1064 // properly update the download item (which no longer exists) or the download |
1047 // history, but the action will complete properly anyway. This may lead to the | 1065 // history, but the action will complete properly anyway. This may lead to the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 save_page_downloads_.erase(download->GetId()); | 1102 save_page_downloads_.erase(download->GetId()); |
1085 | 1103 |
1086 if (download->IsComplete()) | 1104 if (download->IsComplete()) |
1087 content::NotificationService::current()->Notify( | 1105 content::NotificationService::current()->Notify( |
1088 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 1106 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
1089 content::Source<DownloadManager>(this), | 1107 content::Source<DownloadManager>(this), |
1090 content::Details<DownloadItem>(download)); | 1108 content::Details<DownloadItem>(download)); |
1091 } | 1109 } |
1092 } | 1110 } |
1093 | 1111 |
1094 void DownloadManagerImpl::MarkDownloadOpened(DownloadItem* download) { | 1112 void DownloadManagerImpl::DownloadOpened(DownloadItem* download) { |
1095 delegate_->UpdateItemInPersistentStore(download); | 1113 delegate_->UpdateItemInPersistentStore(download); |
1096 int num_unopened = 0; | 1114 int num_unopened = 0; |
1097 for (DownloadMap::iterator it = history_downloads_.begin(); | 1115 for (DownloadMap::iterator it = history_downloads_.begin(); |
1098 it != history_downloads_.end(); ++it) { | 1116 it != history_downloads_.end(); ++it) { |
1099 if (it->second->IsComplete() && !it->second->GetOpened()) | 1117 if (it->second->IsComplete() && !it->second->GetOpened()) |
1100 ++num_unopened; | 1118 ++num_unopened; |
1101 } | 1119 } |
1102 download_stats::RecordOpensOutstanding(num_unopened); | 1120 download_stats::RecordOpensOutstanding(num_unopened); |
1103 } | 1121 } |
1104 | 1122 |
1105 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { | 1123 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { |
1106 file_manager_ = file_manager; | 1124 file_manager_ = file_manager; |
1107 } | 1125 } |
OLD | NEW |