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

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

Powered by Google App Engine
This is Rietveld 408576698