Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 8697006: DownloadManager intereface refactoring to allow cleaner DownloadItem unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improved isolation of MockDownloadManager. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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
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 size) { 410 void DownloadManagerImpl::UpdateDownload(int32 download_id, int64 size) {
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
383 DownloadMap::iterator it = active_downloads_.find(download_id); 412 DownloadMap::iterator it = active_downloads_.find(download_id);
384 if (it != active_downloads_.end()) { 413 if (it != active_downloads_.end()) {
(...skipping 19 matching lines...) Expand all
404 if (active_downloads_.count(download_id) == 0) 433 if (active_downloads_.count(download_id) == 0)
405 return; 434 return;
406 435
407 DownloadItem* download = active_downloads_[download_id]; 436 DownloadItem* download = active_downloads_[download_id];
408 download->OnAllDataSaved(size, hash); 437 download->OnAllDataSaved(size, hash);
409 delegate_->OnResponseCompleted(download); 438 delegate_->OnResponseCompleted(download);
410 439
411 MaybeCompleteDownload(download); 440 MaybeCompleteDownload(download);
412 } 441 }
413 442
414 void DownloadManagerImpl::AssertQueueStateConsistent(DownloadItem* download) { 443 void DownloadManagerImpl::AssertStateConsistent(DownloadItem* download) const {
415 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 444 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
416 if (download->GetState() == DownloadItem::REMOVING) { 445 if (download->GetState() == DownloadItem::REMOVING) {
417 CHECK(!ContainsKey(downloads_, download)); 446 CHECK(!ContainsKey(downloads_, download));
418 CHECK(!ContainsKey(active_downloads_, download->GetId())); 447 CHECK(!ContainsKey(active_downloads_, download->GetId()));
419 CHECK(!ContainsKey(in_progress_, download->GetId())); 448 CHECK(!ContainsKey(in_progress_, download->GetId()));
420 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle())); 449 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle()));
421 return; 450 return;
422 } 451 }
423 452
424 // Should be in downloads_ if we're not REMOVING. 453 // Should be in downloads_ if we're not REMOVING.
425 CHECK(ContainsKey(downloads_, download)); 454 CHECK(ContainsKey(downloads_, download));
426 455
427 // Check history_downloads_ consistency. 456 // Check history_downloads_ consistency.
428 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) { 457 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) {
429 CHECK(ContainsKey(history_downloads_, download->GetDbHandle())); 458 CHECK(ContainsKey(history_downloads_, download->GetDbHandle()));
430 } else { 459 } else {
431 // TODO(rdsmith): Somewhat painful; make sure to disable in 460 // TODO(rdsmith): Somewhat painful; make sure to disable in
432 // release builds after resolution of http://crbug.com/85408. 461 // release builds after resolution of http://crbug.com/85408.
433 for (DownloadMap::iterator it = history_downloads_.begin(); 462 for (DownloadMap::const_iterator it = history_downloads_.begin();
434 it != history_downloads_.end(); ++it) { 463 it != history_downloads_.end(); ++it) {
435 CHECK(it->second != download); 464 CHECK(it->second != download);
436 } 465 }
437 } 466 }
438 467
439 int64 state = download->GetState(); 468 int64 state = download->GetState();
440 base::debug::Alias(&state); 469 base::debug::Alias(&state);
441 if (ContainsKey(active_downloads_, download->GetId())) { 470 if (ContainsKey(active_downloads_, download->GetId())) {
442 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) 471 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle)
443 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState()); 472 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 // Remove the id from in_progress 532 // Remove the id from in_progress
504 in_progress_.erase(download->GetId()); 533 in_progress_.erase(download->GetId());
505 UpdateDownloadProgress(); // Reflect removal from in_progress_. 534 UpdateDownloadProgress(); // Reflect removal from in_progress_.
506 535
507 delegate_->UpdateItemInPersistentStore(download); 536 delegate_->UpdateItemInPersistentStore(download);
508 537
509 // Finish the download. 538 // Finish the download.
510 download->OnDownloadCompleting(file_manager_); 539 download->OnDownloadCompleting(file_manager_);
511 } 540 }
512 541
513 void DownloadManagerImpl::DownloadCompleted(int32 download_id) { 542 void DownloadManagerImpl::DownloadCompleted(DownloadItem* download) {
514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
515 DownloadItem* download = GetDownloadItem(download_id);
516 DCHECK(download); 544 DCHECK(download);
517 delegate_->UpdateItemInPersistentStore(download); 545 delegate_->UpdateItemInPersistentStore(download);
518 active_downloads_.erase(download_id); 546 active_downloads_.erase(download->GetId());
519 AssertQueueStateConsistent(download); 547 AssertStateConsistent(download);
520 } 548 }
521 549
522 void DownloadManagerImpl::OnDownloadRenamedToFinalName( 550 void DownloadManagerImpl::OnDownloadRenamedToFinalName(
523 int download_id, 551 int download_id,
524 const FilePath& full_path, 552 const FilePath& full_path,
525 int uniquifier) { 553 int uniquifier) {
526 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id 554 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id
527 << " full_path = \"" << full_path.value() << "\"" 555 << " full_path = \"" << full_path.value() << "\""
528 << " uniquifier = " << uniquifier; 556 << " uniquifier = " << uniquifier;
529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 21 matching lines...) Expand all
551 void DownloadManagerImpl::CancelDownload(int32 download_id) { 579 void DownloadManagerImpl::CancelDownload(int32 download_id) {
552 DownloadItem* download = GetActiveDownload(download_id); 580 DownloadItem* download = GetActiveDownload(download_id);
553 // A cancel at the right time could remove the download from the 581 // A cancel at the right time could remove the download from the
554 // |active_downloads_| map before we get here. 582 // |active_downloads_| map before we get here.
555 if (!download) 583 if (!download)
556 return; 584 return;
557 585
558 download->Cancel(true); 586 download->Cancel(true);
559 } 587 }
560 588
561 void DownloadManagerImpl::DownloadCancelledInternal(DownloadItem* download) { 589 void DownloadManagerImpl::DownloadCancelled(DownloadItem* download) {
562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
563 591
564 VLOG(20) << __FUNCTION__ << "()" 592 VLOG(20) << __FUNCTION__ << "()"
565 << " download = " << download->DebugString(true); 593 << " download = " << download->DebugString(true);
566 594
567 RemoveFromActiveList(download); 595 RemoveFromActiveList(download);
568 // This function is called from the DownloadItem, so DI state 596 // This function is called from the DownloadItem, so DI state
569 // should already have been updated. 597 // should already have been updated.
570 AssertQueueStateConsistent(download); 598 AssertStateConsistent(download);
571 599
572 if (file_manager_) 600 if (file_manager_)
573 download->OffThreadCancel(file_manager_); 601 download->OffThreadCancel(file_manager_);
574 } 602 }
575 603
576 void DownloadManagerImpl::OnDownloadInterrupted(int32 download_id, 604 void DownloadManagerImpl::OnDownloadInterrupted(int32 download_id,
577 int64 size, 605 int64 size,
578 InterruptReason reason) { 606 InterruptReason reason) {
579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
580 608
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 680
653 // Tell observers to refresh their views. 681 // Tell observers to refresh their views.
654 NotifyModelChanged(); 682 NotifyModelChanged();
655 683
656 // Delete the download items themselves. 684 // Delete the download items themselves.
657 const int num_deleted = static_cast<int>(pending_deletes.size()); 685 const int num_deleted = static_cast<int>(pending_deletes.size());
658 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end()); 686 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end());
659 return num_deleted; 687 return num_deleted;
660 } 688 }
661 689
662 void DownloadManagerImpl::RemoveDownload(int64 download_handle) { 690 void DownloadManagerImpl::DownloadRemoved(DownloadItem* download) {
663 DownloadMap::iterator it = history_downloads_.find(download_handle); 691 if (history_downloads_.find(download->GetDbHandle()) ==
664 if (it == history_downloads_.end()) 692 history_downloads_.end())
665 return; 693 return;
666 694
667 // Make history update. 695 // Make history update.
668 DownloadItem* download = it->second;
669 delegate_->RemoveItemFromPersistentStore(download); 696 delegate_->RemoveItemFromPersistentStore(download);
670 697
671 // Remove from our tables and delete. 698 // Remove from our tables and delete.
672 int downloads_count = RemoveDownloadItems(DownloadVector(1, download)); 699 int downloads_count = RemoveDownloadItems(DownloadVector(1, download));
673 DCHECK_EQ(1, downloads_count); 700 DCHECK_EQ(1, downloads_count);
674 } 701 }
675 702
676 int DownloadManagerImpl::RemoveDownloadsBetween(const base::Time remove_begin, 703 int DownloadManagerImpl::RemoveDownloadsBetween(const base::Time remove_begin,
677 const base::Time remove_end) { 704 const base::Time remove_end) {
678 delegate_->RemoveItemsFromPersistentStoreBetween(remove_begin, remove_end); 705 delegate_->RemoveItemsFromPersistentStoreBetween(remove_begin, remove_end);
679 706
680 // All downloads visible to the user will be in the history, 707 // All downloads visible to the user will be in the history,
681 // so scan that map. 708 // so scan that map.
682 DownloadVector pending_deletes; 709 DownloadVector pending_deletes;
683 for (DownloadMap::const_iterator it = history_downloads_.begin(); 710 for (DownloadMap::const_iterator it = history_downloads_.begin();
684 it != history_downloads_.end(); 711 it != history_downloads_.end();
685 ++it) { 712 ++it) {
686 DownloadItem* download = it->second; 713 DownloadItem* download = it->second;
687 if (download->GetStartTime() >= remove_begin && 714 if (download->GetStartTime() >= remove_begin &&
688 (remove_end.is_null() || download->GetStartTime() < remove_end) && 715 (remove_end.is_null() || download->GetStartTime() < remove_end) &&
689 (download->IsComplete() || download->IsCancelled())) { 716 (download->IsComplete() || download->IsCancelled())) {
690 AssertQueueStateConsistent(download); 717 AssertStateConsistent(download);
691 pending_deletes.push_back(download); 718 pending_deletes.push_back(download);
692 } 719 }
693 } 720 }
694 return RemoveDownloadItems(pending_deletes); 721 return RemoveDownloadItems(pending_deletes);
695 } 722 }
696 723
697 int DownloadManagerImpl::RemoveDownloads(const base::Time remove_begin) { 724 int DownloadManagerImpl::RemoveDownloads(const base::Time remove_begin) {
698 return RemoveDownloadsBetween(remove_begin, base::Time()); 725 return RemoveDownloadsBetween(remove_begin, base::Time());
699 } 726 }
700 727
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 854
828 // The history service has retrieved all download entries. 'entries' contains 855 // The history service has retrieved all download entries. 'entries' contains
829 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). 856 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time).
830 void DownloadManagerImpl::OnPersistentStoreQueryComplete( 857 void DownloadManagerImpl::OnPersistentStoreQueryComplete(
831 std::vector<DownloadPersistentStoreInfo>* entries) { 858 std::vector<DownloadPersistentStoreInfo>* entries) {
832 // TODO(rdsmith): Remove this and related logic when 859 // TODO(rdsmith): Remove this and related logic when
833 // http://crbug.com/85408 is fixed. 860 // http://crbug.com/85408 is fixed.
834 largest_db_handle_in_history_ = 0; 861 largest_db_handle_in_history_ = 0;
835 862
836 for (size_t i = 0; i < entries->size(); ++i) { 863 for (size_t i = 0; i < entries->size(); ++i) {
837 DownloadItem* download = new DownloadItemImpl(this, entries->at(i)); 864 DownloadItem* download = new DownloadItemImpl(
865 this, GetNextId(), entries->at(i));
838 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. 866 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
839 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle())); 867 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle()));
840 downloads_.insert(download); 868 downloads_.insert(download);
841 history_downloads_[download->GetDbHandle()] = download; 869 history_downloads_[download->GetDbHandle()] = download;
842 VLOG(20) << __FUNCTION__ << "()" << i << ">" 870 VLOG(20) << __FUNCTION__ << "()" << i << ">"
843 << " download = " << download->DebugString(true); 871 << " download = " << download->DebugString(true);
844 872
845 if (download->GetDbHandle() > largest_db_handle_in_history_) 873 if (download->GetDbHandle() > largest_db_handle_in_history_)
846 largest_db_handle_in_history_ = download->GetDbHandle(); 874 largest_db_handle_in_history_ = download->GetDbHandle();
847 } 875 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 DownloadSet remainder; 1045 DownloadSet remainder;
1018 std::insert_iterator<DownloadSet> 1046 std::insert_iterator<DownloadSet>
1019 insert_remainder(remainder, remainder.begin()); 1047 insert_remainder(remainder, remainder.begin());
1020 std::set_difference(downloads_.begin(), downloads_.end(), 1048 std::set_difference(downloads_.begin(), downloads_.end(),
1021 downloads_union.begin(), downloads_union.end(), 1049 downloads_union.begin(), downloads_union.end(),
1022 insert_remainder); 1050 insert_remainder);
1023 DCHECK(remainder.empty()); 1051 DCHECK(remainder.empty());
1024 #endif 1052 #endif
1025 } 1053 }
1026 1054
1027 void DownloadManagerImpl::SavePageDownloadStarted(DownloadItem* download) {
1028 DCHECK(!ContainsKey(save_page_downloads_, download->GetId()));
1029 downloads_.insert(download);
1030 save_page_downloads_[download->GetId()] = download;
1031
1032 // Add this entry to the history service.
1033 // Additionally, the UI is notified in the callback.
1034 delegate_->AddItemToPersistentStore(download);
1035 }
1036
1037 // SavePackage will call SavePageDownloadFinished upon completion/cancellation. 1055 // SavePackage will call SavePageDownloadFinished upon completion/cancellation.
1038 // The history callback will call OnSavePageItemAddedToPersistentStore. 1056 // The history callback will call OnSavePageItemAddedToPersistentStore.
1039 // If the download finishes before the history callback, 1057 // If the download finishes before the history callback,
1040 // OnSavePageItemAddedToPersistentStore calls SavePageDownloadFinished, ensuring 1058 // OnSavePageItemAddedToPersistentStore calls SavePageDownloadFinished, ensuring
1041 // that the history event is update regardless of the order in which these two 1059 // that the history event is update regardless of the order in which these two
1042 // events complete. 1060 // events complete.
1043 // If something removes the download item from the download manager (Remove, 1061 // If something removes the download item from the download manager (Remove,
1044 // Shutdown) the result will be that the SavePage system will not be able to 1062 // Shutdown) the result will be that the SavePage system will not be able to
1045 // properly update the download item (which no longer exists) or the download 1063 // properly update the download item (which no longer exists) or the download
1046 // history, but the action will complete properly anyway. This may lead to the 1064 // 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
1083 save_page_downloads_.erase(download->GetId()); 1101 save_page_downloads_.erase(download->GetId());
1084 1102
1085 if (download->IsComplete()) 1103 if (download->IsComplete())
1086 content::NotificationService::current()->Notify( 1104 content::NotificationService::current()->Notify(
1087 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 1105 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
1088 content::Source<DownloadManager>(this), 1106 content::Source<DownloadManager>(this),
1089 content::Details<DownloadItem>(download)); 1107 content::Details<DownloadItem>(download));
1090 } 1108 }
1091 } 1109 }
1092 1110
1093 void DownloadManagerImpl::MarkDownloadOpened(DownloadItem* download) { 1111 void DownloadManagerImpl::DownloadOpened(DownloadItem* download) {
1094 delegate_->UpdateItemInPersistentStore(download); 1112 delegate_->UpdateItemInPersistentStore(download);
1095 int num_unopened = 0; 1113 int num_unopened = 0;
1096 for (DownloadMap::iterator it = history_downloads_.begin(); 1114 for (DownloadMap::iterator it = history_downloads_.begin();
1097 it != history_downloads_.end(); ++it) { 1115 it != history_downloads_.end(); ++it) {
1098 if (it->second->IsComplete() && !it->second->GetOpened()) 1116 if (it->second->IsComplete() && !it->second->GetOpened())
1099 ++num_unopened; 1117 ++num_unopened;
1100 } 1118 }
1101 download_stats::RecordOpensOutstanding(num_unopened); 1119 download_stats::RecordOpensOutstanding(num_unopened);
1102 } 1120 }
1103 1121
1104 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { 1122 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) {
1105 file_manager_ = file_manager; 1123 file_manager_ = file_manager;
1106 } 1124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698