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

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

Powered by Google App Engine
This is Rietveld 408576698