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

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

Issue 7277073: Support for adding save page download items into downloads history. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 } 968 }
969 // The null times make the date range unbounded. 969 // The null times make the date range unbounded.
970 return RemoveDownloadsBetween(base::Time(), base::Time()); 970 return RemoveDownloadsBetween(base::Time(), base::Time());
971 } 971 }
972 972
973 void DownloadManager::SavePageAsDownloadStarted(DownloadItem* download) { 973 void DownloadManager::SavePageAsDownloadStarted(DownloadItem* download) {
974 #if !defined(NDEBUG) 974 #if !defined(NDEBUG)
975 save_page_as_downloads_.insert(download); 975 save_page_as_downloads_.insert(download);
976 #endif 976 #endif
977 downloads_.insert(download); 977 downloads_.insert(download);
978 // Add to history and notify observers.
979 AddDownloadItemToHistory(download, DownloadHistory::kUninitializedHandle);
980 NotifyModelChanged();
981 } 978 }
982 979
983 // Initiate a download of a specific URL. We send the request to the 980 // Initiate a download of a specific URL. We send the request to the
984 // ResourceDispatcherHost, and let it send us responses like a regular 981 // ResourceDispatcherHost, and let it send us responses like a regular
985 // download. 982 // download.
986 void DownloadManager::DownloadUrl(const GURL& url, 983 void DownloadManager::DownloadUrl(const GURL& url,
987 const GURL& referrer, 984 const GURL& referrer,
988 const std::string& referrer_charset, 985 const std::string& referrer_charset,
989 TabContents* tab_contents) { 986 TabContents* tab_contents) {
990 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(), 987 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(),
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 1172
1176 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508 1173 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/84508
1177 // is fixed. 1174 // is fixed.
1178 CHECK_NE(DownloadHistory::kUninitializedHandle, db_handle); 1175 CHECK_NE(DownloadHistory::kUninitializedHandle, db_handle);
1179 1176
1180 DCHECK(download->db_handle() == DownloadHistory::kUninitializedHandle); 1177 DCHECK(download->db_handle() == DownloadHistory::kUninitializedHandle);
1181 download->set_db_handle(db_handle); 1178 download->set_db_handle(db_handle);
1182 1179
1183 DCHECK(!ContainsKey(history_downloads_, download->db_handle())); 1180 DCHECK(!ContainsKey(history_downloads_, download->db_handle()));
1184 history_downloads_[download->db_handle()] = download; 1181 history_downloads_[download->db_handle()] = download;
1182
1183 // Show in the appropriate browser UI.
1184 // This includes buttons to save or cancel, for a dangerous download.
1185 ShowDownloadInBrowser(download);
1186
1187 // Inform interested objects about the new download.
1188 NotifyModelChanged();
1185 } 1189 }
1186 1190
1187 // Once the new DownloadItem's creation info has been committed to the history 1191 // Once the new DownloadItem's creation info has been committed to the history
1188 // service, we associate the DownloadItem with the db handle, update our 1192 // service, we associate the DownloadItem with the db handle, update our
1189 // 'history_downloads_' map and inform observers. 1193 // 'history_downloads_' map and inform observers.
1190 void DownloadManager::OnCreateDownloadEntryComplete(int32 download_id, 1194 void DownloadManager::OnCreateDownloadEntryComplete(int32 download_id,
1191 int64 db_handle) { 1195 int64 db_handle) {
1192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1193 DownloadItem* download = GetActiveDownloadItem(download_id); 1197 DownloadItem* download = GetActiveDownloadItem(download_id);
1194 if (!download) 1198 if (!download)
1195 return; 1199 return;
1196 1200
1197 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle 1201 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle
1198 << " download_id = " << download_id 1202 << " download_id = " << download_id
1199 << " download = " << download->DebugString(true); 1203 << " download = " << download->DebugString(true);
1200 1204
1201 AddDownloadItemToHistory(download, db_handle); 1205 AddDownloadItemToHistory(download, db_handle);
1202 1206
1203 // Show in the appropriate browser UI.
1204 // This includes buttons to save or cancel, for a dangerous download.
1205 ShowDownloadInBrowser(download);
1206
1207 // Inform interested objects about the new download.
1208 NotifyModelChanged();
1209
1210 // If the download is still in progress, try to complete it. 1207 // If the download is still in progress, try to complete it.
1211 // 1208 //
1212 // Otherwise, download has been cancelled or interrupted before we've 1209 // Otherwise, download has been cancelled or interrupted before we've
1213 // received the DB handle. We post one final message to the history 1210 // received the DB handle. We post one final message to the history
1214 // service so that it can be properly in sync with the DownloadItem's 1211 // service so that it can be properly in sync with the DownloadItem's
1215 // completion status, and also inform any observers so that they get 1212 // completion status, and also inform any observers so that they get
1216 // more than just the start notification. 1213 // more than just the start notification.
1217 if (download->IsInProgress()) { 1214 if (download->IsInProgress()) {
1218 MaybeCompleteDownload(download); 1215 MaybeCompleteDownload(download);
1219 } else { 1216 } else {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 observed_download_manager_->RemoveObserver(this); 1342 observed_download_manager_->RemoveObserver(this);
1346 } 1343 }
1347 1344
1348 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1345 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1349 observing_download_manager_->NotifyModelChanged(); 1346 observing_download_manager_->NotifyModelChanged();
1350 } 1347 }
1351 1348
1352 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1349 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1353 observed_download_manager_ = NULL; 1350 observed_download_manager_ = NULL;
1354 } 1351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698