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

Unified Diff: chrome/browser/history/download_database.h

Issue 13044019: Clean up entries left by crashes in the DownloadDB. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to r192579 Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/history/download_database.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/download_database.h
diff --git a/chrome/browser/history/download_database.h b/chrome/browser/history/download_database.h
index 533af26729663b97579264139b2818f528dba8b0..afb5fd0a4642500f65cf838ab8735b30db121daf 100644
--- a/chrome/browser/history/download_database.h
+++ b/chrome/browser/history/download_database.h
@@ -8,7 +8,9 @@
#include <string>
#include <vector>
+#include "base/gtest_prod_util.h"
#include "base/threading/platform_thread.h"
+#include "content/public/browser/download_item.h"
#include "sql/meta_table.h"
namespace sql {
@@ -41,12 +43,6 @@ class DownloadDatabase {
// to select the row in the database table to update.
bool UpdateDownload(const DownloadRow& data);
- // 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 DownloadRow& info);
@@ -79,16 +75,59 @@ class DownloadDatabase {
bool DropDownloadTable();
private:
+ FRIEND_TEST_ALL_PREFIXES(
+ HistoryBackendDBTest, ConfirmDownloadInProgressCleanup);
+
+ // Values used in the database for DownloadItem::State.
+ static const int kStateInvalid;
+ static const int kStateInProgress;
+ static const int kStateComplete;
+ static const int kStateCancelled;
+ static const int kStateBug140687;
+ static const int kStateInterrupted;
+
+ // Values used in the database for DownloadItem::DangerType
+ static const int kDangerTypeInvalid;
+ static const int kDangerTypeNotDangerous;
+ static const int kDangerTypeDangerousFile;
+ static const int kDangerTypeDangerousUrl;
+ static const int kDangerTypeDangerousContent;
+ static const int kDangerTypeMaybeDangerousContent;
+ static const int kDangerTypeUncommonContent;
+ static const int kDangerTypeUserValidated;
+ static const int kDangerTypeDangerousHost;
+
+ // 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 interrupted with
+ // interrupt reason |DOWNLOAD_INTERRUPT_REASON_CRASH|. This function
+ // fixes such entries.
+ void EnsureInProgressEntriesCleanedUp();
+
bool EnsureColumnExists(const std::string& name, const std::string& type);
void RemoveDownloadURLs(int64 handle);
+ // Utility functions for conversion between DownloadItem types
+ // and DownloadDatabase constants.
+ static int StateToInt(content::DownloadItem::DownloadState state);
+ static content::DownloadItem::DownloadState IntToState(int state);
+ static int DangerTypeToInt(content::DownloadDangerType danger_type);
+ static content::DownloadDangerType IntToDangerType(int danger_type);
+
bool owning_thread_set_;
base::PlatformThreadId owning_thread_;
int next_id_;
int next_db_handle_;
+ // Initialized to false on construction, and checked in all functional
+ // routines post-migration in the database for a possible call to
+ // CleanUpInProgressEntries(). This allows us to avoid
+ // doing the cleanup until after any DB migration and unless we are
+ // actually use the downloads database.
+ bool in_progress_entry_cleanup_completed_;
+
DISALLOW_COPY_AND_ASSIGN(DownloadDatabase);
};
« no previous file with comments | « no previous file | chrome/browser/history/download_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698