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

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

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

Powered by Google App Engine
This is Rietveld 408576698