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

Side by Side Diff: chrome/browser/download/download_manager.cc

Issue 6312027: Add files saved using 'Save page as' to the download history.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 10 months 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 "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 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 int DownloadManager::RemoveAllDownloads() { 822 int DownloadManager::RemoveAllDownloads() {
823 if (this != profile_->GetOriginalProfile()->GetDownloadManager()) { 823 if (this != profile_->GetOriginalProfile()->GetDownloadManager()) {
824 // This is an incognito downloader. Clear All should clear main download 824 // This is an incognito downloader. Clear All should clear main download
825 // manager as well. 825 // manager as well.
826 profile_->GetOriginalProfile()->GetDownloadManager()->RemoveAllDownloads(); 826 profile_->GetOriginalProfile()->GetDownloadManager()->RemoveAllDownloads();
827 } 827 }
828 // The null times make the date range unbounded. 828 // The null times make the date range unbounded.
829 return RemoveDownloadsBetween(base::Time(), base::Time()); 829 return RemoveDownloadsBetween(base::Time(), base::Time());
830 } 830 }
831 831
832 void DownloadManager::AddDownloadItemToHistory(DownloadItem* item,
833 int64 db_handle) {
834 // It's not immediately obvious, but HistoryBackend::CreateDownload() can
835 // call this function with an invalid |db_handle|. For instance, this can
836 // happen when the history database is offline. We cannot have multiple
837 // DownloadItems with the same invalid db_handle, so we need to assign a
838 // unique |db_handle| here.
839 if (db_handle == DownloadHistory::kUninitializedHandle)
840 db_handle = download_history_->GetNextFakeDbHandle();
841
842 DCHECK(item->db_handle() == DownloadHistory::kUninitializedHandle);
843 item->set_db_handle(db_handle);
844
845 // Insert into our full map.
Paweł Hajdan Jr. 2011/02/11 19:17:49 nit: This comment doesn't add value, could you rem
magnus 2011/02/13 03:32:41 Done.
846 DCHECK(!ContainsKey(history_downloads_, db_handle));
847 history_downloads_[db_handle] = item;
848 }
849
832 void DownloadManager::SavePageAsDownloadStarted(DownloadItem* download_item) { 850 void DownloadManager::SavePageAsDownloadStarted(DownloadItem* download_item) {
833 #if !defined(NDEBUG) 851 #if !defined(NDEBUG)
834 save_page_as_downloads_.insert(download_item); 852 save_page_as_downloads_.insert(download_item);
835 #endif 853 #endif
836 downloads_.insert(download_item); 854 downloads_.insert(download_item);
837 } 855 }
838 856
839 // Initiate a download of a specific URL. We send the request to the 857 // Initiate a download of a specific URL. We send the request to the
840 // ResourceDispatcherHost, and let it send us responses like a regular 858 // ResourceDispatcherHost, and let it send us responses like a regular
841 // download. 859 // download.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 int64 db_handle) { 998 int64 db_handle) {
981 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 999 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
982 DownloadMap::iterator it = in_progress_.find(info.download_id); 1000 DownloadMap::iterator it = in_progress_.find(info.download_id);
983 DCHECK(it != in_progress_.end()); 1001 DCHECK(it != in_progress_.end());
984 1002
985 DownloadItem* download = it->second; 1003 DownloadItem* download = it->second;
986 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle 1004 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle
987 << " download_id = " << info.download_id 1005 << " download_id = " << info.download_id
988 << " download = " << download->DebugString(true); 1006 << " download = " << download->DebugString(true);
989 1007
990 // It's not immediately obvious, but HistoryBackend::CreateDownload() can 1008 AddDownloadItemToHistory(download, db_handle);
991 // call this function with an invalid |db_handle|. For instance, this can
992 // happen when the history database is offline. We cannot have multiple
993 // DownloadItems with the same invalid db_handle, so we need to assign a
994 // unique |db_handle| here.
995 if (db_handle == DownloadHistory::kUninitializedHandle)
996 db_handle = download_history_->GetNextFakeDbHandle();
997
998 DCHECK(download->db_handle() == DownloadHistory::kUninitializedHandle);
999 download->set_db_handle(db_handle);
1000
1001 // Insert into our full map.
1002 DCHECK(!ContainsKey(history_downloads_, download->db_handle()));
1003 history_downloads_[download->db_handle()] = download;
1004 1009
1005 // Show in the appropriate browser UI. 1010 // Show in the appropriate browser UI.
1006 ShowDownloadInBrowser(info, download); 1011 ShowDownloadInBrowser(info, download);
1007 1012
1008 // Inform interested objects about the new download. 1013 // Inform interested objects about the new download.
1009 NotifyModelChanged(); 1014 NotifyModelChanged();
1010 1015
1011 // If this download has been cancelled before we've received the DB handle, 1016 // If this download has been cancelled before we've received the DB handle,
1012 // post one final message to the history service so that it can be properly 1017 // post one final message to the history service so that it can be properly
1013 // in sync with the DownloadItem's completion status, and also inform any 1018 // in sync with the DownloadItem's completion status, and also inform any
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 observed_download_manager_->RemoveObserver(this); 1136 observed_download_manager_->RemoveObserver(this);
1132 } 1137 }
1133 1138
1134 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1139 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1135 observing_download_manager_->NotifyModelChanged(); 1140 observing_download_manager_->NotifyModelChanged();
1136 } 1141 }
1137 1142
1138 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1143 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1139 observed_download_manager_ = NULL; 1144 observed_download_manager_ = NULL;
1140 } 1145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698