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

Unified Diff: chrome/browser/download/download_history.cc

Issue 722953002: downloads: add the ability to undo download removal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dcheck Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_history.cc
diff --git a/chrome/browser/download/download_history.cc b/chrome/browser/download/download_history.cc
index 9e960824d6ea007b7b4a6d3db06d8268c5263d66..0d6da87e7b51e65d955fca19f58e0a573ab74f7a 100644
--- a/chrome/browser/download/download_history.cc
+++ b/chrome/browser/download/download_history.cc
@@ -71,7 +71,8 @@ class DownloadHistoryData : public base::SupportsUserData::Data {
explicit DownloadHistoryData(content::DownloadItem* item)
: state_(NOT_PERSISTED),
- was_restored_from_history_(false) {
+ was_restored_from_history_(false),
+ was_revived_(false) {
item->SetUserData(kKey, this);
}
@@ -85,6 +86,9 @@ class DownloadHistoryData : public base::SupportsUserData::Data {
was_restored_from_history_ = value;
}
+ bool was_revived() const { return was_revived_; }
+ void set_was_revived(bool revived) { was_revived_ = revived; }
+
// This allows DownloadHistory::OnDownloadUpdated() to see what changed in a
// DownloadItem if anything, in order to prevent writing to the database
// unnecessarily. It is nullified when the item is no longer in progress in
@@ -103,6 +107,7 @@ class DownloadHistoryData : public base::SupportsUserData::Data {
PersistenceState state_;
scoped_ptr<history::DownloadRow> info_;
bool was_restored_from_history_;
+ bool was_revived_;
DISALLOW_COPY_AND_ASSIGN(DownloadHistoryData);
};
@@ -372,8 +377,12 @@ void DownloadHistory::OnDownloadCreated(
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
// All downloads should pass through OnDownloadCreated exactly once.
- CHECK(!DownloadHistoryData::Get(item));
- DownloadHistoryData* data = new DownloadHistoryData(item);
+ DownloadHistoryData* data = DownloadHistoryData::Get(item);
+ CHECK(!data || data->was_revived());
+
+ if (!data)
+ data = new DownloadHistoryData(item);
+
if (item->GetId() == loading_id_) {
data->SetState(DownloadHistoryData::PERSISTED);
data->set_was_restored_from_history(true);
@@ -385,6 +394,15 @@ void DownloadHistory::OnDownloadCreated(
MaybeAddToHistory(item);
}
+void DownloadHistory::OnDownloadRevived(
+ content::DownloadManager* manager, content::DownloadItem* item) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ DownloadHistoryData* data = DownloadHistoryData::Get(item);
+ if (data)
+ data->set_was_revived(true);
+}
+
void DownloadHistory::OnDownloadUpdated(
content::DownloadManager* manager, content::DownloadItem* item) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));

Powered by Google App Engine
This is Rietveld 408576698