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 "chrome/browser/download/download_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 int DownloadManager::RemoveAllDownloads() { | 847 int DownloadManager::RemoveAllDownloads() { |
848 if (this != profile_->GetOriginalProfile()->GetDownloadManager()) { | 848 if (this != profile_->GetOriginalProfile()->GetDownloadManager()) { |
849 // This is an incognito downloader. Clear All should clear main download | 849 // This is an incognito downloader. Clear All should clear main download |
850 // manager as well. | 850 // manager as well. |
851 profile_->GetOriginalProfile()->GetDownloadManager()->RemoveAllDownloads(); | 851 profile_->GetOriginalProfile()->GetDownloadManager()->RemoveAllDownloads(); |
852 } | 852 } |
853 // The null times make the date range unbounded. | 853 // The null times make the date range unbounded. |
854 return RemoveDownloadsBetween(base::Time(), base::Time()); | 854 return RemoveDownloadsBetween(base::Time(), base::Time()); |
855 } | 855 } |
856 | 856 |
| 857 void DownloadManager::AddDownloadItemToHistory(DownloadItem* item, |
| 858 int64 db_handle) { |
| 859 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
| 860 // call this function with an invalid |db_handle|. For instance, this can |
| 861 // happen when the history database is offline. We cannot have multiple |
| 862 // DownloadItems with the same invalid db_handle, so we need to assign a |
| 863 // unique |db_handle| here. |
| 864 if (db_handle == DownloadHistory::kUninitializedHandle) |
| 865 db_handle = download_history_->GetNextFakeDbHandle(); |
| 866 |
| 867 DCHECK(item->db_handle() == DownloadHistory::kUninitializedHandle); |
| 868 item->set_db_handle(db_handle); |
| 869 DCHECK(!ContainsKey(history_downloads_, db_handle)); |
| 870 history_downloads_[db_handle] = item; |
| 871 } |
| 872 |
857 void DownloadManager::SavePageAsDownloadStarted(DownloadItem* download_item) { | 873 void DownloadManager::SavePageAsDownloadStarted(DownloadItem* download_item) { |
858 #if !defined(NDEBUG) | 874 #if !defined(NDEBUG) |
859 save_page_as_downloads_.insert(download_item); | 875 save_page_as_downloads_.insert(download_item); |
860 #endif | 876 #endif |
861 downloads_.insert(download_item); | 877 downloads_.insert(download_item); |
862 } | 878 } |
863 | 879 |
864 // Initiate a download of a specific URL. We send the request to the | 880 // Initiate a download of a specific URL. We send the request to the |
865 // ResourceDispatcherHost, and let it send us responses like a regular | 881 // ResourceDispatcherHost, and let it send us responses like a regular |
866 // download. | 882 // download. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 int64 db_handle) { | 1014 int64 db_handle) { |
999 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1015 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1000 DownloadMap::iterator it = in_progress_.find(info.download_id); | 1016 DownloadMap::iterator it = in_progress_.find(info.download_id); |
1001 DCHECK(it != in_progress_.end()); | 1017 DCHECK(it != in_progress_.end()); |
1002 | 1018 |
1003 DownloadItem* download = it->second; | 1019 DownloadItem* download = it->second; |
1004 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle | 1020 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle |
1005 << " download_id = " << info.download_id | 1021 << " download_id = " << info.download_id |
1006 << " download = " << download->DebugString(true); | 1022 << " download = " << download->DebugString(true); |
1007 | 1023 |
1008 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 1024 AddDownloadItemToHistory(download, db_handle); |
1009 // call this function with an invalid |db_handle|. For instance, this can | |
1010 // happen when the history database is offline. We cannot have multiple | |
1011 // DownloadItems with the same invalid db_handle, so we need to assign a | |
1012 // unique |db_handle| here. | |
1013 if (db_handle == DownloadHistory::kUninitializedHandle) | |
1014 db_handle = download_history_->GetNextFakeDbHandle(); | |
1015 | |
1016 DCHECK(download->db_handle() == DownloadHistory::kUninitializedHandle); | |
1017 download->set_db_handle(db_handle); | |
1018 | |
1019 // Insert into our full map. | |
1020 DCHECK(!ContainsKey(history_downloads_, download->db_handle())); | |
1021 history_downloads_[download->db_handle()] = download; | |
1022 | 1025 |
1023 // Show in the appropriate browser UI. | 1026 // Show in the appropriate browser UI. |
1024 // This includes buttons to save or cancel, for a dangerous download. | 1027 // This includes buttons to save or cancel, for a dangerous download. |
1025 ShowDownloadInBrowser(info, download); | 1028 ShowDownloadInBrowser(info, download); |
1026 | 1029 |
1027 // Inform interested objects about the new download. | 1030 // Inform interested objects about the new download. |
1028 NotifyModelChanged(); | 1031 NotifyModelChanged(); |
1029 | 1032 |
1030 // If this download has been cancelled before we've received the DB handle, | 1033 // If this download has been cancelled before we've received the DB handle, |
1031 // post one final message to the history service so that it can be properly | 1034 // post one final message to the history service so that it can be properly |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 observed_download_manager_->RemoveObserver(this); | 1153 observed_download_manager_->RemoveObserver(this); |
1151 } | 1154 } |
1152 | 1155 |
1153 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1156 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
1154 observing_download_manager_->NotifyModelChanged(); | 1157 observing_download_manager_->NotifyModelChanged(); |
1155 } | 1158 } |
1156 | 1159 |
1157 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1160 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
1158 observed_download_manager_ = NULL; | 1161 observed_download_manager_ = NULL; |
1159 } | 1162 } |
OLD | NEW |