summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history
diff options
context:
space:
mode:
authorgeorgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-30 22:51:46 +0000
committergeorgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-30 22:51:46 +0000
commit024f2f060ad0bdab9b0e8008973bde64bf04bd28 (patch)
tree7b0241021bb0731f41d387e0d42a6db6127a6008 /chrome/browser/history
parent2afe4b18b33efe4751d04d0cfc7a512e746654ad (diff)
downloadchromium_src-024f2f060ad0bdab9b0e8008973bde64bf04bd28.zip
chromium_src-024f2f060ad0bdab9b0e8008973bde64bf04bd28.tar.gz
chromium_src-024f2f060ad0bdab9b0e8008973bde64bf04bd28.tar.bz2
Fix for bug 37909: "Clear All" in incognito downloads window will clear all, including non-incognito downloads.
BUG=37909 TEST=Open regular and incognito download pages. "Clear all" on incognito will clear all, but pending downloads. In regular window it would clear all, but pending and incognito. Review URL: http://codereview.chromium.org/1807007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46141 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
-rw-r--r--chrome/browser/history/download_database.cc10
-rw-r--r--chrome/browser/history/download_database.h6
-rw-r--r--chrome/browser/history/history.cc7
-rw-r--r--chrome/browser/history/history.h4
-rw-r--r--chrome/browser/history/history_backend.cc9
-rw-r--r--chrome/browser/history/history_backend.h1
-rw-r--r--chrome/browser/history/history_unittest.cc16
7 files changed, 53 insertions, 0 deletions
diff --git a/chrome/browser/history/download_database.cc b/chrome/browser/history/download_database.cc
index 8bf4a95..ea0649d 100644
--- a/chrome/browser/history/download_database.cc
+++ b/chrome/browser/history/download_database.cc
@@ -135,6 +135,16 @@ bool DownloadDatabase::UpdateDownloadPath(const std::wstring& path,
return statement.Run();
}
+bool DownloadDatabase::CleanUpInProgressEntries() {
+ sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
+ "UPDATE downloads SET state=? WHERE state=?"));
+ if (!statement)
+ return false;
+ statement.BindInt(0, DownloadItem::CANCELLED);
+ statement.BindInt(1, DownloadItem::IN_PROGRESS);
+ return statement.Run();
+}
+
int64 DownloadDatabase::CreateDownload(const DownloadCreateInfo& info) {
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"INSERT INTO downloads "
diff --git a/chrome/browser/history/download_database.h b/chrome/browser/history/download_database.h
index 1efb6d4..8ba2e7a 100644
--- a/chrome/browser/history/download_database.h
+++ b/chrome/browser/history/download_database.h
@@ -31,6 +31,12 @@ class DownloadDatabase {
// Update the path of one download. Returns true if successful.
bool UpdateDownloadPath(const std::wstring& path, DownloadID db_handle);
+ // Fixes state of the download entries. Sometimes entries with IN_PROGRESS
+ // state are not updated during browser shutdown (particularly when crashing).
+ // On the next start such entries are considered canceled. This functions
+ // fixes such entries.
+ bool CleanUpInProgressEntries();
+
// Create a new database entry for one download and return its primary db id.
int64 CreateDownload(const DownloadCreateInfo& info);
diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc
index fe85e5f..0e685748 100644
--- a/chrome/browser/history/history.cc
+++ b/chrome/browser/history/history.cc
@@ -488,6 +488,13 @@ HistoryService::Handle HistoryService::QueryDownloads(
new history::DownloadQueryRequest(callback));
}
+// Changes all IN_PROGRESS in the database entries to CANCELED.
+// IN_PROGRESS entries are the corrupted entries, not updated by next function
+// because of the crash or some other extremal exit.
+void HistoryService::CleanUpInProgressEntries() {
+ ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::CleanUpInProgressEntries);
+}
+
// Handle updates for a particular download. This is a 'fire and forget'
// operation, so we don't need to be called back.
void HistoryService::UpdateDownload(int64 received_bytes,
diff --git a/chrome/browser/history/history.h b/chrome/browser/history/history.h
index 2326f8b..3507817 100644
--- a/chrome/browser/history/history.h
+++ b/chrome/browser/history/history.h
@@ -406,6 +406,10 @@ class HistoryService : public CancelableRequestProvider,
Handle QueryDownloads(CancelableRequestConsumerBase* consumer,
DownloadQueryCallback* callback);
+ // Begins a request to clean up entries that has been corrupted (because of
+ // the crash, for example).
+ void CleanUpInProgressEntries();
+
// Called to update the history service about the current state of a download.
// This is a 'fire and forget' query, so just pass the relevant state info to
// the database with no need for a callback.
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 4be006a..caaec96 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -1040,6 +1040,15 @@ void HistoryBackend::QueryDownloads(
request->ForwardResult(DownloadQueryRequest::TupleType(&request->value));
}
+// Clean up entries that has been corrupted (because of the crash, for example).
+void HistoryBackend::CleanUpInProgressEntries() {
+ if (db_.get()) {
+ // If some "in progress" entries were not updated when Chrome exited, they
+ // need to be cleaned up.
+ db_->CleanUpInProgressEntries();
+ }
+}
+
// Update a particular download entry.
void HistoryBackend::UpdateDownload(int64 received_bytes,
int32 state,
diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h
index 7289b5a..4b37f29 100644
--- a/chrome/browser/history/history_backend.h
+++ b/chrome/browser/history/history_backend.h
@@ -201,6 +201,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// Downloads -----------------------------------------------------------------
void QueryDownloads(scoped_refptr<DownloadQueryRequest> request);
+ void CleanUpInProgressEntries();
void UpdateDownload(int64 received_bytes, int32 state, int64 db_handle);
void UpdateDownloadPath(const std::wstring& path, int64 db_handle);
void CreateDownload(scoped_refptr<DownloadCreateRequest> request,
diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc
index 00e9154..c0b65b3 100644
--- a/chrome/browser/history/history_unittest.cc
+++ b/chrome/browser/history/history_unittest.cc
@@ -382,6 +382,22 @@ TEST_F(HistoryTest, ClearBrowsingData_Downloads) {
db_->RemoveDownloadsBetween(Time(), Time());
db_->QueryDownloads(&downloads);
EXPECT_EQ(0U, downloads.size());
+
+ // Check removal of downloads stuck in IN_PROGRESS state.
+ EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago));
+ EXPECT_NE(0, AddDownload(DownloadItem::IN_PROGRESS, month_ago));
+ db_->QueryDownloads(&downloads);
+ EXPECT_EQ(2U, downloads.size());
+ db_->RemoveDownloadsBetween(Time(), Time());
+ db_->QueryDownloads(&downloads);
+ // IN_PROGRESS download should remain. It it indicated as "Canceled"
+ EXPECT_EQ(1U, downloads.size());
+ db_->CleanUpInProgressEntries();
+ db_->QueryDownloads(&downloads);
+ EXPECT_EQ(1U, downloads.size());
+ db_->RemoveDownloadsBetween(Time(), Time());
+ db_->QueryDownloads(&downloads);
+ EXPECT_EQ(0U, downloads.size());
}
TEST_F(HistoryTest, AddPage) {