Chromium Code Reviews| Index: chrome/browser/download/download_manager.cc |
| diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc |
| index da878b0f2687bf7823138c1062daaa22da64b5f1..ad4ada025e92f92d1dacf0599cfa92f626c46bb3 100644 |
| --- a/chrome/browser/download/download_manager.cc |
| +++ b/chrome/browser/download/download_manager.cc |
| @@ -120,6 +120,7 @@ void DownloadManager::Shutdown() { |
| // And clear all non-owning containers. |
| in_progress_.clear(); |
| + active_downloads_.clear(); |
| #if !defined(NDEBUG) |
| save_page_as_downloads_.clear(); |
| #endif |
| @@ -427,7 +428,9 @@ void DownloadManager::CreateDownloadItem(DownloadCreateInfo* info) { |
| DownloadItem* download = new DownloadItem(this, *info, |
| profile_->IsOffTheRecord()); |
| DCHECK(!ContainsKey(in_progress_, info->download_id)); |
| + DCHECK(!ContainsKey(active_downloads_, info->download_id)); |
| downloads_.insert(download); |
| + active_downloads_[info->download_id] = download; |
| } |
| void DownloadManager::AttachDownloadItem(DownloadCreateInfo* info, |
| @@ -437,22 +440,14 @@ void DownloadManager::AttachDownloadItem(DownloadCreateInfo* info, |
| scoped_ptr<DownloadCreateInfo> infop(info); |
| info->path = target_path; |
| - // NOTE(ahendrickson) We will be adding a new map |active_downloads_|, into |
| - // which we will be adding the download as soon as it's created. This will |
| - // make this loop unnecessary. |
| - // Eventually |active_downloads_| will replace |in_progress_|, but we don't |
| - // want to change the semantics yet. |
| + // NOTE(ahendrickson) Eventually |active_downloads_| will replace |
| + // |in_progress_|, but we don't want to change the semantics yet. |
|
Randy Smith (Not in Mondays)
2010/12/29 15:58:11
Just FYI: I think we'll be in a position to yank i
|
| DCHECK(!ContainsKey(in_progress_, info->download_id)); |
| - DownloadItem* download = NULL; |
| - for (std::set<DownloadItem*>::iterator i = downloads_.begin(); |
| - i != downloads_.end(); ++i) { |
| - DownloadItem* item = (*i); |
| - if (item && (item->id() == info->download_id)) { |
| - download = item; |
| - break; |
| - } |
| - } |
| + DCHECK(ContainsKey(active_downloads_, info->download_id)); |
| + DownloadItem* download = active_downloads_[info->download_id]; |
| DCHECK(download != NULL); |
| + DCHECK(downloads_.find(download) != downloads_.end()); |
| + |
| download->SetFileCheckResults(info->path, |
| info->is_dangerous, |
| info->path_uniquifier, |
| @@ -506,8 +501,8 @@ void DownloadManager::AttachDownloadItem(DownloadCreateInfo* info, |
| } |
| void DownloadManager::UpdateDownload(int32 download_id, int64 size) { |
| - DownloadMap::iterator it = in_progress_.find(download_id); |
| - if (it != in_progress_.end()) { |
| + DownloadMap::iterator it = active_downloads_.find(download_id); |
| + if (it != active_downloads_.end()) { |
| DownloadItem* download = it->second; |
| download->Update(size); |
| download_history_->UpdateEntry(download); |
| @@ -553,6 +548,7 @@ void DownloadManager::OnAllDataSaved(int32 download_id, int64 size) { |
| // don't have a valid db_handle yet. |
| if (download->db_handle() != DownloadHistory::kUninitializedHandle) { |
| in_progress_.erase(it); |
| + active_downloads_.erase(download_id); |
|
Randy Smith (Not in Mondays)
2010/12/29 15:58:11
It looks like the semantics for active_downloads_
ahendrickson
2011/01/01 18:15:59
Done.
|
| download_history_->UpdateEntry(download); |
| } |
| @@ -661,6 +657,7 @@ void DownloadManager::DownloadCancelled(int32 download_id) { |
| // don't have a valid db_handle yet. |
| if (download->db_handle() != DownloadHistory::kUninitializedHandle) { |
| in_progress_.erase(it); |
| + active_downloads_.erase(download_id); |
| download_history_->UpdateEntry(download); |
| } |
| @@ -983,7 +980,7 @@ void DownloadManager::OnCreateDownloadEntryComplete( |
| history_downloads_.end()); |
| history_downloads_[download->db_handle()] = download; |
| - // Show in the appropropriate browser UI. |
| + // Show in the appropriate browser UI. |
| ShowDownloadInBrowser(info, download); |
| // Inform interested objects about the new download. |
| @@ -995,6 +992,7 @@ void DownloadManager::OnCreateDownloadEntryComplete( |
| // observers so that they get more than just the start notification. |
| if (download->state() != DownloadItem::IN_PROGRESS) { |
| in_progress_.erase(it); |
| + active_downloads_.erase(info.download_id); |
| download_history_->UpdateEntry(download); |
| download->UpdateObservers(); |
| } |
| @@ -1048,7 +1046,7 @@ void DownloadManager::AssertContainersConsistent() const { |
| #if !defined(NDEBUG) |
| // Turn everything into sets. |
| DownloadSet in_progress_set, history_set; |
| - const DownloadMap* input_maps[] = {&in_progress_, &history_downloads_}; |
| + const DownloadMap* input_maps[] = {&active_downloads_, &history_downloads_}; |
| DownloadSet* local_sets[] = {&in_progress_set, &history_set}; |
| DCHECK_EQ(ARRAYSIZE_UNSAFE(input_maps), ARRAYSIZE_UNSAFE(local_sets)); |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_maps); i++) { |