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

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

Issue 102683004: Add mime type information to the download database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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/history/download_database.cc
diff --git a/chrome/browser/history/download_database.cc b/chrome/browser/history/download_database.cc
index 369c8c2751706f8bad9b9ad290545924e2cfd880..de344624f1b81d0878086340911fd415590779b9 100644
--- a/chrome/browser/history/download_database.cc
+++ b/chrome/browser/history/download_database.cc
@@ -43,6 +43,8 @@ static const char kSchema[] =
"id INTEGER PRIMARY KEY," // Primary key.
"current_path LONGVARCHAR NOT NULL," // Current disk location
"target_path LONGVARCHAR NOT NULL," // Final disk location
+ "mime_type VARCHAR(255) NOT NULL," // Mime type.
asanka 2013/12/16 21:51:48 Why VARCHAR(255) ? I don't think length constraint
+ "original_mime_type VARCHAR(255) NOT NULL," // Original mime type.
"start_time INTEGER NOT NULL," // When the download was started.
"received_bytes INTEGER NOT NULL," // Total size downloaded.
"total_bytes INTEGER NOT NULL," // Total size of the download.
@@ -287,7 +289,12 @@ bool DownloadDatabase::MigrateDownloadValidators() {
bool DownloadDatabase::InitDownloadTable() {
if (GetDB().DoesTableExist("downloads")) {
return EnsureColumnExists("end_time", "INTEGER NOT NULL DEFAULT 0") &&
- EnsureColumnExists("opened", "INTEGER NOT NULL DEFAULT 0");
+ EnsureColumnExists("opened", "INTEGER NOT NULL DEFAULT 0") &&
+ EnsureColumnExists("mime_type", "VARCHAR(255) NOT NULL"
+ " DEFAULT ''") &&
asanka 2013/12/16 21:51:48 Nit: \"\" for consistency. Also as Randy asked, th
+ EnsureColumnExists("original_mime_type", "VARCHAR(255) NOT NULL"
+ " DEFAULT ''");
+
} else {
// If the "downloads" table doesn't exist, the downloads_url_chain
// table better not.
@@ -330,7 +337,9 @@ void DownloadDatabase::QueryDownloads(
std::map<uint32, DownloadRow*> info_map;
sql::Statement statement_main(GetDB().GetCachedStatement(SQL_FROM_HERE,
- "SELECT id, current_path, target_path, start_time, received_bytes, "
+ "SELECT id, current_path, target_path, "
+ "mime_type, original_mime_type, "
+ "start_time, received_bytes, "
"total_bytes, state, danger_type, interrupt_reason, end_time, opened, "
"referrer, by_ext_id, by_ext_name, etag, last_modified "
"FROM downloads ORDER BY start_time"));
@@ -346,6 +355,8 @@ void DownloadDatabase::QueryDownloads(
info->id = static_cast<uint32>(signed_id);
info->current_path = ColumnFilePath(statement_main, column++);
info->target_path = ColumnFilePath(statement_main, column++);
+ info->mime_type = statement_main.ColumnString(column++);
+ info->original_mime_type = statement_main.ColumnString(column++);
info->start_time = base::Time::FromInternalValue(
statement_main.ColumnInt64(column++));
info->received_bytes = statement_main.ColumnInt64(column++);
@@ -466,13 +477,17 @@ bool DownloadDatabase::UpdateDownload(const DownloadRow& data) {
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"UPDATE downloads "
- "SET current_path=?, target_path=?, received_bytes=?, state=?, "
+ "SET current_path=?, target_path=?, "
+ "mime_type=?, original_mime_type=?, "
+ "received_bytes=?, state=?, "
"danger_type=?, interrupt_reason=?, end_time=?, total_bytes=?, "
"opened=?, by_ext_id=?, by_ext_name=?, etag=?, last_modified=? "
"WHERE id=?"));
int column = 0;
BindFilePath(statement, data.current_path, column++);
BindFilePath(statement, data.target_path, column++);
+ statement.BindString(column++, data.mime_type);
+ statement.BindString(column++, data.original_mime_type);
statement.BindInt64(column++, data.received_bytes);
statement.BindInt(column++, state);
statement.BindInt(column++, danger_type);
@@ -522,16 +537,20 @@ bool DownloadDatabase::CreateDownload(const DownloadRow& info) {
sql::Statement statement_insert(GetDB().GetCachedStatement(
SQL_FROM_HERE,
"INSERT INTO downloads "
- "(id, current_path, target_path, start_time, "
+ "(id, current_path, target_path, "
+ "mime_type, original_mime_type, "
+ "start_time, "
" received_bytes, total_bytes, state, danger_type, interrupt_reason, "
" end_time, opened, referrer, by_ext_id, by_ext_name, etag, "
" last_modified) "
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
int column = 0;
statement_insert.BindInt(column++, info.id);
BindFilePath(statement_insert, info.current_path, column++);
BindFilePath(statement_insert, info.target_path, column++);
+ statement_insert.BindString(column++, info.mime_type);
+ statement_insert.BindString(column++, info.original_mime_type);
statement_insert.BindInt64(column++, info.start_time.ToInternalValue());
statement_insert.BindInt64(column++, info.received_bytes);
statement_insert.BindInt64(column++, info.total_bytes);

Powered by Google App Engine
This is Rietveld 408576698