summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorohrn@opera.com <ohrn@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 19:39:45 +0000
committerohrn@opera.com <ohrn@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 19:39:45 +0000
commit0e648562e01b7d29b686f5787b9175a9661f244d (patch)
treee691a20a695d9be7a53dd23303919a90a5badb03
parent743530fb9594f6d0aa32e2dd05069bdb387c2940 (diff)
downloadchromium_src-0e648562e01b7d29b686f5787b9175a9661f244d.zip
chromium_src-0e648562e01b7d29b686f5787b9175a9661f244d.tar.gz
chromium_src-0e648562e01b7d29b686f5787b9175a9661f244d.tar.bz2
Add mime type information to the download database
BUG=328382 Review URL: https://codereview.chromium.org/319703002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276775 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/download/download_history.cc7
-rw-r--r--chrome/browser/download/download_history_unittest.cc16
-rw-r--r--chrome/browser/download/download_ui_controller_unittest.cc1
-rw-r--r--chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc1
-rw-r--r--chrome/browser/history/download_database.cc121
-rw-r--r--chrome/browser/history/download_database.h3
-rw-r--r--chrome/browser/history/download_row.cc4
-rw-r--r--chrome/browser/history/download_row.h9
-rw-r--r--chrome/browser/history/history_database.cc11
-rw-r--r--chrome/browser/history/history_unittest.cc74
-rw-r--r--chrome/browser/ui/webui/downloads_dom_handler_browsertest.cc2
-rw-r--r--chrome/test/data/History/history.28.sql25
-rw-r--r--content/browser/download/download_item_factory.h2
-rw-r--r--content/browser/download/download_item_impl.cc4
-rw-r--r--content/browser/download/download_item_impl.h2
-rw-r--r--content/browser/download/download_manager_impl.cc8
-rw-r--r--content/browser/download/download_manager_impl.h3
-rw-r--r--content/browser/download/download_manager_impl_unittest.cc6
-rw-r--r--content/public/browser/download_manager.h2
-rw-r--r--content/public/test/mock_download_manager.cc15
-rw-r--r--content/public/test/mock_download_manager.h7
21 files changed, 277 insertions, 46 deletions
diff --git a/chrome/browser/download/download_history.cc b/chrome/browser/download/download_history.cc
index 112ecac..6ca2a73 100644
--- a/chrome/browser/download/download_history.cc
+++ b/chrome/browser/download/download_history.cc
@@ -128,6 +128,8 @@ history::DownloadRow GetDownloadRow(
item->GetTargetFilePath(),
item->GetUrlChain(),
item->GetReferrerUrl(),
+ item->GetMimeType(),
+ item->GetOriginalMimeType(),
item->GetStartTime(),
item->GetEndTime(),
item->GetETag(),
@@ -145,7 +147,8 @@ history::DownloadRow GetDownloadRow(
bool ShouldUpdateHistory(const history::DownloadRow* previous,
const history::DownloadRow& current) {
- // Ignore url, referrer, start_time, id, which don't change.
+ // Ignore url, referrer, mime_type, original_mime_type, start_time,
+ // id, db_handle, which don't change.
return ((previous == NULL) ||
(previous->current_path != current.current_path) ||
(previous->target_path != current.target_path) ||
@@ -262,6 +265,8 @@ void DownloadHistory::QueryCallback(scoped_ptr<InfoVector> infos) {
it->target_path,
it->url_chain,
it->referrer_url,
+ it->mime_type,
+ it->original_mime_type,
it->start_time,
it->end_time,
it->etag,
diff --git a/chrome/browser/download/download_history_unittest.cc b/chrome/browser/download/download_history_unittest.cc
index 22059d4..923621f 100644
--- a/chrome/browser/download/download_history_unittest.cc
+++ b/chrome/browser/download/download_history_unittest.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <set>
#include <vector>
#include "base/memory/weak_ptr.h"
@@ -43,6 +42,8 @@ void CheckInfoEqual(const history::DownloadRow& left,
EXPECT_EQ(left.url_chain[i].spec(), right.url_chain[i].spec());
}
EXPECT_EQ(left.referrer_url.spec(), right.referrer_url.spec());
+ EXPECT_EQ(left.mime_type, right.mime_type);
+ EXPECT_EQ(left.original_mime_type, right.original_mime_type);
EXPECT_EQ(left.start_time.ToTimeT(), right.start_time.ToTimeT());
EXPECT_EQ(left.end_time.ToTimeT(), right.end_time.ToTimeT());
EXPECT_EQ(left.etag, right.etag);
@@ -238,6 +239,8 @@ class DownloadHistoryTest : public testing::Test {
infos->at(index).target_path,
infos->at(index).url_chain,
infos->at(index).referrer_url,
+ infos->at(index).mime_type,
+ infos->at(index).original_mime_type,
infos->at(index).start_time,
infos->at(index).end_time,
infos->at(index).etag,
@@ -351,6 +354,8 @@ class DownloadHistoryTest : public testing::Test {
base::FilePath(path),
url_chain,
referrer,
+ "application/octet-stream",
+ "application/octet-stream",
(base::Time::Now() - base::TimeDelta::FromMinutes(10)),
(base::Time::Now() - base::TimeDelta::FromMinutes(1)),
"Etag",
@@ -372,6 +377,8 @@ class DownloadHistoryTest : public testing::Test {
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
@@ -395,6 +402,8 @@ class DownloadHistoryTest : public testing::Test {
info->target_path = target_path;
info->url_chain = url_chain;
info->referrer_url = referrer;
+ info->mime_type = mime_type;
+ info->original_mime_type = original_mime_type;
info->start_time = start_time;
info->end_time = end_time;
info->etag = etag;
@@ -419,8 +428,9 @@ class DownloadHistoryTest : public testing::Test {
.WillRepeatedly(ReturnRefOfCopy(url_chain[0]));
EXPECT_CALL(item(index), GetUrlChain())
.WillRepeatedly(ReturnRefOfCopy(url_chain));
- EXPECT_CALL(item(index), GetMimeType())
- .WillRepeatedly(Return("application/octet-stream"));
+ EXPECT_CALL(item(index), GetMimeType()).WillRepeatedly(Return(mime_type));
+ EXPECT_CALL(item(index), GetOriginalMimeType()).WillRepeatedly(Return(
+ original_mime_type));
EXPECT_CALL(item(index), GetReferrerUrl())
.WillRepeatedly(ReturnRefOfCopy(referrer));
EXPECT_CALL(item(index), GetStartTime()).WillRepeatedly(Return(start_time));
diff --git a/chrome/browser/download/download_ui_controller_unittest.cc b/chrome/browser/download/download_ui_controller_unittest.cc
index d5dc4de..7cbd1e4 100644
--- a/chrome/browser/download/download_ui_controller_unittest.cc
+++ b/chrome/browser/download/download_ui_controller_unittest.cc
@@ -308,6 +308,7 @@ TEST_F(DownloadUIControllerTest, DownloadUIController_HistoryDownload) {
GURL url;
scoped_ptr<MockDownloadItem> item = CreateMockInProgressDownload();
+ EXPECT_CALL(*item, GetOriginalMimeType());
EXPECT_CALL(*manager(), CheckForHistoryFilesRemoval());
{
diff --git a/chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc b/chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc
index 688cec1..a08acf4 100644
--- a/chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc
+++ b/chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc
@@ -422,6 +422,7 @@ class DownloadExtensionTest : public ExtensionApiTest {
downloads_directory().Append(history_info[i].filename),
downloads_directory().Append(history_info[i].filename),
url_chain, GURL(), // URL Chain, referrer
+ std::string(), std::string(), // mime_type, original_mime_type
current, current, // start_time, end_time
std::string(), std::string(), // etag, last_modified
1, 1, // received_bytes, total_bytes
diff --git a/chrome/browser/history/download_database.cc b/chrome/browser/history/download_database.cc
index ae63f63..4fa418e 100644
--- a/chrome/browser/history/download_database.cc
+++ b/chrome/browser/history/download_database.cc
@@ -38,35 +38,6 @@ enum DroppedReason {
DROPPED_REASON_MAX
};
-static const char kSchema[] =
- "CREATE TABLE downloads ("
- "id INTEGER PRIMARY KEY," // Primary key.
- "current_path LONGVARCHAR NOT NULL," // Current disk location
- "target_path LONGVARCHAR NOT NULL," // Final disk location
- "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.
- "state INTEGER NOT NULL," // 1=complete, 4=interrupted
- "danger_type INTEGER NOT NULL, " // Danger type, validated.
- "interrupt_reason INTEGER NOT NULL," // content::DownloadInterruptReason
- "end_time INTEGER NOT NULL," // When the download completed.
- "opened INTEGER NOT NULL," // 1 if it has ever been opened else 0
- "referrer VARCHAR NOT NULL," // HTTP Referrer
- "by_ext_id VARCHAR NOT NULL," // ID of extension that started the
- // download
- "by_ext_name VARCHAR NOT NULL," // name of extension
- "etag VARCHAR NOT NULL," // ETag
- "last_modified VARCHAR NOT NULL)"; // Last-Modified header
-
-static const char kUrlChainSchema[] =
- "CREATE TABLE downloads_url_chains ("
- "id INTEGER NOT NULL," // downloads.id.
- "chain_index INTEGER NOT NULL," // Index of url in chain
- // 0 is initial target,
- // MAX is target after redirects.
- "url LONGVARCHAR NOT NULL, " // URL.
- "PRIMARY KEY (id, chain_index) )";
-
#if defined(OS_POSIX)
// Binds/reads the given file path to the given column of the given statement.
@@ -213,6 +184,13 @@ bool DownloadDatabase::EnsureColumnExists(
GetDB().Execute(add_col.c_str());
}
+bool DownloadDatabase::MigrateMimeType() {
+ return EnsureColumnExists("mime_type", "VARCHAR(255) NOT NULL"
+ " DEFAULT \"\"") &&
+ EnsureColumnExists("original_mime_type", "VARCHAR(255) NOT NULL"
+ " DEFAULT \"\"");
+}
+
bool DownloadDatabase::MigrateDownloadsState() {
sql::Statement statement(GetDB().GetUniqueStatement(
"UPDATE downloads SET state=? WHERE state=?"));
@@ -227,8 +205,32 @@ bool DownloadDatabase::MigrateDownloadsReasonPathsAndDangerType() {
if (!GetDB().Execute("ALTER TABLE downloads RENAME TO downloads_tmp"))
return false;
+ const char kReasonPathDangerSchema[] =
+ "CREATE TABLE downloads ("
+ "id INTEGER PRIMARY KEY,"
+ "current_path LONGVARCHAR NOT NULL,"
+ "target_path LONGVARCHAR NOT NULL,"
+ "start_time INTEGER NOT NULL,"
+ "received_bytes INTEGER NOT NULL,"
+ "total_bytes INTEGER NOT NULL,"
+ "state INTEGER NOT NULL,"
+ "danger_type INTEGER NOT NULL,"
+ "interrupt_reason INTEGER NOT NULL,"
+ "end_time INTEGER NOT NULL,"
+ "opened INTEGER NOT NULL)";
+
+ static const char kReasonPathDangerUrlChainSchema[] =
+ "CREATE TABLE downloads_url_chains ("
+ "id INTEGER NOT NULL," // downloads.id.
+ "chain_index INTEGER NOT NULL," // Index of url in chain
+ // 0 is initial target,
+ // MAX is target after redirects.
+ "url LONGVARCHAR NOT NULL, " // URL.
+ "PRIMARY KEY (id, chain_index) )";
+
+
// Recreate main table.
- if (!GetDB().Execute(kSchema))
+ if (!GetDB().Execute(kReasonPathDangerSchema))
return false;
// Populate it. As we do so, we transform the time values from time_t
@@ -238,8 +240,7 @@ bool DownloadDatabase::MigrateDownloadsReasonPathsAndDangerType() {
sql::Statement statement_populate(GetDB().GetUniqueStatement(
"INSERT INTO downloads "
"( id, current_path, target_path, start_time, received_bytes, "
- " total_bytes, state, danger_type, interrupt_reason, end_time, opened, "
- " referrer, by_ext_id, by_ext_name, etag, last_modified ) "
+ " total_bytes, state, danger_type, interrupt_reason, end_time, opened ) "
"SELECT id, full_path, full_path, "
" CASE start_time WHEN 0 THEN 0 ELSE "
" (start_time + 11644473600) * 1000000 END, "
@@ -247,7 +248,7 @@ bool DownloadDatabase::MigrateDownloadsReasonPathsAndDangerType() {
" state, ?, ?, "
" CASE end_time WHEN 0 THEN 0 ELSE "
" (end_time + 11644473600) * 1000000 END, "
- " opened, \"\", \"\", \"\", \"\", \"\" "
+ " opened "
"FROM downloads_tmp"));
statement_populate.BindInt(0, content::DOWNLOAD_INTERRUPT_REASON_NONE);
statement_populate.BindInt(1, kDangerTypeNotDangerous);
@@ -255,7 +256,7 @@ bool DownloadDatabase::MigrateDownloadsReasonPathsAndDangerType() {
return false;
// Create new chain table and populate it.
- if (!GetDB().Execute(kUrlChainSchema))
+ if (!GetDB().Execute(kReasonPathDangerUrlChainSchema))
return false;
if (!GetDB().Execute("INSERT INTO downloads_url_chains "
@@ -285,6 +286,38 @@ bool DownloadDatabase::MigrateDownloadValidators() {
}
bool DownloadDatabase::InitDownloadTable() {
+ const char kSchema[] =
+ "CREATE TABLE downloads ("
+ "id INTEGER PRIMARY KEY," // Primary key.
+ "current_path LONGVARCHAR NOT NULL," // Current disk location
+ "target_path LONGVARCHAR NOT NULL," // Final disk location
+ "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.
+ "state INTEGER NOT NULL," // 1=complete, 4=interrupted
+ "danger_type INTEGER NOT NULL," // Danger type, validated.
+ "interrupt_reason INTEGER NOT NULL," // content::DownloadInterruptReason
+ "end_time INTEGER NOT NULL," // When the download completed.
+ "opened INTEGER NOT NULL," // 1 if it has ever been opened
+ // else 0
+ "referrer VARCHAR NOT NULL," // HTTP Referrer
+ "by_ext_id VARCHAR NOT NULL," // ID of extension that started the
+ // download
+ "by_ext_name VARCHAR NOT NULL," // name of extension
+ "etag VARCHAR NOT NULL," // ETag
+ "last_modified VARCHAR NOT NULL," // Last-Modified header
+ "mime_type VARCHAR(255) NOT NULL," // MIME type.
+ "original_mime_type VARCHAR(255) NOT NULL)"; // Original MIME type.
+
+ const char kUrlChainSchema[] =
+ "CREATE TABLE downloads_url_chains ("
+ "id INTEGER NOT NULL," // downloads.id.
+ "chain_index INTEGER NOT NULL," // Index of url in chain
+ // 0 is initial target,
+ // MAX is target after redirects.
+ "url LONGVARCHAR NOT NULL, " // URL.
+ "PRIMARY KEY (id, chain_index) )";
+
if (GetDB().DoesTableExist("downloads")) {
return EnsureColumnExists("end_time", "INTEGER NOT NULL DEFAULT 0") &&
EnsureColumnExists("opened", "INTEGER NOT NULL DEFAULT 0");
@@ -327,7 +360,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"));
@@ -343,6 +378,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++);
@@ -463,13 +500,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);
@@ -519,16 +560,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);
diff --git a/chrome/browser/history/download_database.h b/chrome/browser/history/download_database.h
index 30a04bf..10ef59c 100644
--- a/chrome/browser/history/download_database.h
+++ b/chrome/browser/history/download_database.h
@@ -52,6 +52,9 @@ class DownloadDatabase {
// Returns the database for the functions in this interface.
virtual sql::Connection& GetDB() = 0;
+ // Returns true if able to successfully add mime types to the downloads table.
+ bool MigrateMimeType();
+
// Returns true if able to successfully rewrite the invalid values for the
// |state| field from 3 to 4. Returns false if there was an error fixing the
// database. See http://crbug.com/140687
diff --git a/chrome/browser/history/download_row.cc b/chrome/browser/history/download_row.cc
index fe44c13..6621dac6 100644
--- a/chrome/browser/history/download_row.cc
+++ b/chrome/browser/history/download_row.cc
@@ -21,6 +21,8 @@ DownloadRow::DownloadRow(
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start,
const base::Time& end,
const std::string& etag,
@@ -38,6 +40,8 @@ DownloadRow::DownloadRow(
target_path(target_path),
url_chain(url_chain),
referrer_url(referrer),
+ mime_type(mime_type),
+ original_mime_type(original_mime_type),
start_time(start),
end_time(end),
etag(etag),
diff --git a/chrome/browser/history/download_row.h b/chrome/browser/history/download_row.h
index d38eec5..a0c094f 100644
--- a/chrome/browser/history/download_row.h
+++ b/chrome/browser/history/download_row.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_HISTORY_DOWNLOAD_ROW_H_
#define CHROME_BROWSER_HISTORY_DOWNLOAD_ROW_H_
+#include <string>
#include <vector>
#include "base/files/file_path.h"
@@ -26,6 +27,8 @@ struct DownloadRow {
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start,
const base::Time& end,
const std::string& etag,
@@ -57,6 +60,12 @@ struct DownloadRow {
// The URL that referred us. Is not changed by UpdateDownload().
GURL referrer_url;
+ // The MIME type of the download, might be based on heuristics.
+ std::string mime_type;
+
+ // The original MIME type of the download.
+ std::string original_mime_type;
+
// The time when the download started. Is not changed by UpdateDownload().
base::Time start_time;
diff --git a/chrome/browser/history/history_database.cc b/chrome/browser/history/history_database.cc
index 0d66322..02f54d2 100644
--- a/chrome/browser/history/history_database.cc
+++ b/chrome/browser/history/history_database.cc
@@ -27,7 +27,7 @@ namespace {
// Current version number. We write databases at the "current" version number,
// but any previous version that can read the "compatible" one can make do with
// our database without *too* many bad effects.
-const int kCurrentVersionNumber = 28;
+const int kCurrentVersionNumber = 29;
const int kCompatibleVersionNumber = 16;
const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold";
@@ -422,6 +422,15 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() {
meta_table_.SetVersionNumber(cur_version);
}
+ if (cur_version == 28) {
+ if (!MigrateMimeType()) {
+ LOG(WARNING) << "Unable to migrate history to version 29";
+ return sql::INIT_FAILURE;
+ }
+ cur_version++;
+ meta_table_.SetVersionNumber(cur_version);
+ }
+
// When the version is too old, we just try to continue anyway, there should
// not be a released product that makes a database too old for us to handle.
LOG_IF(WARNING, cur_version < GetCurrentVersion()) <<
diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc
index 105e699..f5ba8b2 100644
--- a/chrome/browser/history/history_unittest.cc
+++ b/chrome/browser/history/history_unittest.cc
@@ -185,6 +185,8 @@ class HistoryBackendDBTest : public HistoryUnitTestBase {
base::FilePath(FILE_PATH_LITERAL("target-path")),
url_chain,
GURL("http://referrer.com/"),
+ "application/vnd.oasis.opendocument.text",
+ "application/octet-stream",
time,
time,
std::string(),
@@ -267,6 +269,8 @@ TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) {
EXPECT_FALSE(downloads[0].opened);
EXPECT_EQ("by_ext_id", downloads[0].by_ext_id);
EXPECT_EQ("by_ext_name", downloads[0].by_ext_name);
+ EXPECT_EQ("application/vnd.oasis.opendocument.text", downloads[0].mime_type);
+ EXPECT_EQ("application/octet-stream", downloads[0].original_mime_type);
db_->QueryDownloads(&downloads);
EXPECT_EQ(1U, downloads.size());
@@ -646,6 +650,74 @@ TEST_F(HistoryBackendDBTest, PurgeArchivedDatabase) {
history_dir_.Append(chrome::kArchivedHistoryFilename)));
}
+TEST_F(HistoryBackendDBTest, MigrateDownloadMimeType) {
+ Time now(base::Time::Now());
+ ASSERT_NO_FATAL_FAILURE(CreateDBVersion(28));
+ {
+ sql::Connection db;
+ ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
+ {
+ sql::Statement s(db.GetUniqueStatement(
+ "INSERT INTO downloads (id, current_path, target_path, 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 "
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
+ s.BindInt64(0, 1);
+ s.BindString(1, "current_path");
+ s.BindString(2, "target_path");
+ s.BindInt64(3, now.ToTimeT());
+ s.BindInt64(4, 100);
+ s.BindInt64(5, 100);
+ s.BindInt(6, 1);
+ s.BindInt(7, 0);
+ s.BindInt(8, 0);
+ s.BindInt64(9, now.ToTimeT());
+ s.BindInt(10, 1);
+ s.BindString(11, "referrer");
+ s.BindString(12, "by extension ID");
+ s.BindString(13, "by extension name");
+ s.BindString(14, "etag");
+ s.BindInt64(15, now.ToTimeT());
+ ASSERT_TRUE(s.Run());
+ }
+ {
+ sql::Statement s(db.GetUniqueStatement(
+ "INSERT INTO downloads_url_chains (id, chain_index, url) VALUES "
+ "(?, ?, ?)"));
+ s.BindInt64(0, 4);
+ s.BindInt64(1, 0);
+ s.BindString(2, "url");
+ ASSERT_TRUE(s.Run());
+ }
+ }
+ // Re-open the db using the HistoryDatabase, which should migrate to the
+ // current version, creating themime_type abd original_mime_type columns.
+ CreateBackendAndDatabase();
+ DeleteBackend();
+ {
+ // Re-open the db for manual manipulation.
+ sql::Connection db;
+ ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
+ // The version should have been updated.
+ int cur_version = HistoryDatabase::GetCurrentVersion();
+ ASSERT_LE(29, cur_version);
+ {
+ sql::Statement s(db.GetUniqueStatement(
+ "SELECT value FROM meta WHERE key = 'version'"));
+ EXPECT_TRUE(s.Step());
+ EXPECT_EQ(cur_version, s.ColumnInt(0));
+ }
+ {
+ sql::Statement s(db.GetUniqueStatement(
+ "SELECT mime_type, original_mime_type from downloads"));
+ EXPECT_TRUE(s.Step());
+ EXPECT_EQ(std::string(), s.ColumnString(0));
+ EXPECT_EQ(std::string(), s.ColumnString(1));
+ }
+ }
+}
+
TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
// Create the DB.
CreateBackendAndDatabase();
@@ -702,6 +774,8 @@ TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) {
base::FilePath(FILE_PATH_LITERAL("foo-path")),
url_chain,
GURL(std::string()),
+ "application/octet-stream",
+ "application/octet-stream",
now,
now,
std::string(),
diff --git a/chrome/browser/ui/webui/downloads_dom_handler_browsertest.cc b/chrome/browser/ui/webui/downloads_dom_handler_browsertest.cc
index 34c5619..d2773f3 100644
--- a/chrome/browser/ui/webui/downloads_dom_handler_browsertest.cc
+++ b/chrome/browser/ui/webui/downloads_dom_handler_browsertest.cc
@@ -144,6 +144,8 @@ class DownloadsDOMHandlerTest : public InProcessBrowserTest {
base::FilePath(FILE_PATH_LITERAL("/path/to/file")),
url_chain,
GURL(std::string()),
+ "application/octet-stream",
+ "application/octet-stream",
current,
current,
std::string(),
diff --git a/chrome/test/data/History/history.28.sql b/chrome/test/data/History/history.28.sql
new file mode 100644
index 0000000..d1356d4
--- /dev/null
+++ b/chrome/test/data/History/history.28.sql
@@ -0,0 +1,25 @@
+PRAGMA foreign_keys=OFF;
+BEGIN TRANSACTION;
+CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY, value LONGVARCHAR);
+INSERT INTO "meta" VALUES('version','28');
+INSERT INTO "meta" VALUES('last_compatible_version','16');
+CREATE TABLE urls(id INTEGER PRIMARY KEY,url LONGVARCHAR,title LONGVARCHAR,visit_count INTEGER DEFAULT 0 NOT NULL,typed_count INTEGER DEFAULT 0 NOT NULL,last_visit_time INTEGER NOT NULL,hidden INTEGER DEFAULT 0 NOT NULL,favicon_id INTEGER DEFAULT 0 NOT NULL);
+CREATE TABLE visits(id INTEGER PRIMARY KEY,url INTEGER NOT NULL,visit_time INTEGER NOT NULL,from_visit INTEGER,transition INTEGER DEFAULT 0 NOT NULL,segment_id INTEGER,visit_duration INTEGER DEFAULT 0 NOT NULL);
+CREATE TABLE visit_source(id INTEGER PRIMARY KEY,source INTEGER NOT NULL);
+CREATE TABLE keyword_search_terms (keyword_id INTEGER NOT NULL,url_id INTEGER NOT NULL,lower_term LONGVARCHAR NOT NULL,term LONGVARCHAR NOT NULL);
+CREATE TABLE downloads (id INTEGER PRIMARY KEY,current_path LONGVARCHAR NOT NULL,target_path LONGVARCHAR NOT NULL,start_time INTEGER NOT NULL,received_bytes INTEGER NOT NULL,total_bytes INTEGER NOT NULL,state INTEGER NOT NULL,danger_type INTEGER NOT NULL, interrupt_reason INTEGER NOT NULL,end_time INTEGER NOT NULL,opened INTEGER NOT NULL,referrer VARCHAR NOT NULL,by_ext_id VARCHAR NOT NULL,by_ext_name VARCHAR NOT NULL,etag VARCHAR NOT NULL,last_modified VARCHAR NOT NULL);
+CREATE TABLE downloads_url_chains (id INTEGER NOT NULL,chain_index INTEGER NOT NULL,url LONGVARCHAR NOT NULL, PRIMARY KEY (id, chain_index) );
+CREATE TABLE segments (id INTEGER PRIMARY KEY,name VARCHAR,url_id INTEGER NON NULL);
+CREATE TABLE segment_usage (id INTEGER PRIMARY KEY,segment_id INTEGER NOT NULL,time_slot INTEGER NOT NULL,visit_count INTEGER DEFAULT 0 NOT NULL);
+CREATE INDEX visits_url_index ON visits (url);
+CREATE INDEX visits_from_index ON visits (from_visit);
+CREATE INDEX visits_time_index ON visits (visit_time);
+CREATE INDEX segments_name ON segments(name);
+CREATE INDEX segments_url_id ON segments(url_id);
+CREATE INDEX segment_usage_time_slot_segment_id ON segment_usage(time_slot, segment_id);
+CREATE INDEX segments_usage_seg_id ON segment_usage(segment_id);
+CREATE INDEX urls_url_index ON urls (url);
+CREATE INDEX keyword_search_terms_index1 ON keyword_search_terms (keyword_id, lower_term);
+CREATE INDEX keyword_search_terms_index2 ON keyword_search_terms (url_id);
+CREATE INDEX keyword_search_terms_index3 ON keyword_search_terms (term);
+COMMIT;
diff --git a/content/browser/download/download_item_factory.h b/content/browser/download/download_item_factory.h
index c5e03f5..d4198cb 100644
--- a/content/browser/download/download_item_factory.h
+++ b/content/browser/download/download_item_factory.h
@@ -44,6 +44,8 @@ public:
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc
index 0fbd270..433ac78 100644
--- a/content/browser/download/download_item_impl.cc
+++ b/content/browser/download/download_item_impl.cc
@@ -113,6 +113,8 @@ DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
@@ -133,6 +135,8 @@ DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
referrer_url_(referrer_url),
transition_type_(PAGE_TRANSITION_LINK),
has_user_gesture_(false),
+ mime_type_(mime_type),
+ original_mime_type_(original_mime_type),
total_bytes_(total_bytes),
received_bytes_(received_bytes),
bytes_per_sec_(0),
diff --git a/content/browser/download/download_item_impl.h b/content/browser/download/download_item_impl.h
index e660262..34916ff 100644
--- a/content/browser/download/download_item_impl.h
+++ b/content/browser/download/download_item_impl.h
@@ -56,6 +56,8 @@ class CONTENT_EXPORT DownloadItemImpl
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index 4619807..2bd747d 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -169,6 +169,8 @@ class DownloadItemFactoryImpl : public DownloadItemFactory {
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
@@ -187,6 +189,8 @@ class DownloadItemFactoryImpl : public DownloadItemFactory {
target_path,
url_chain,
referrer_url,
+ mime_type,
+ original_mime_type,
start_time,
end_time,
etag,
@@ -619,6 +623,8 @@ DownloadItem* DownloadManagerImpl::CreateDownloadItem(
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
@@ -640,6 +646,8 @@ DownloadItem* DownloadManagerImpl::CreateDownloadItem(
target_path,
url_chain,
referrer_url,
+ mime_type,
+ original_mime_type,
start_time,
end_time,
etag,
diff --git a/content/browser/download/download_manager_impl.h b/content/browser/download/download_manager_impl.h
index 6381417..630c832 100644
--- a/content/browser/download/download_manager_impl.h
+++ b/content/browser/download/download_manager_impl.h
@@ -7,6 +7,7 @@
#include <map>
#include <set>
+#include <string>
#include "base/containers/hash_tables.h"
#include "base/memory/ref_counted.h"
@@ -78,6 +79,8 @@ class CONTENT_EXPORT DownloadManagerImpl : public DownloadManager,
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc
index 091a7f8..ef23777 100644
--- a/content/browser/download/download_manager_impl_unittest.cc
+++ b/content/browser/download/download_manager_impl_unittest.cc
@@ -76,6 +76,8 @@ class MockDownloadItemImpl : public DownloadItemImpl {
base::FilePath(),
std::vector<GURL>(),
GURL(),
+ "application/octet-stream",
+ "application/octet-stream",
base::Time(),
base::Time(),
std::string(),
@@ -234,6 +236,8 @@ class MockDownloadItemFactory
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
@@ -299,6 +303,8 @@ DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem(
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
diff --git a/content/public/browser/download_manager.h b/content/public/browser/download_manager.h
index 6bb1f35..0c9bbac 100644
--- a/content/public/browser/download_manager.h
+++ b/content/public/browser/download_manager.h
@@ -142,6 +142,8 @@ class CONTENT_EXPORT DownloadManager : public base::SupportsUserData::Data {
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
diff --git a/content/public/test/mock_download_manager.cc b/content/public/test/mock_download_manager.cc
index ef5a9f5..a5d7cf9 100644
--- a/content/public/test/mock_download_manager.cc
+++ b/content/public/test/mock_download_manager.cc
@@ -15,6 +15,8 @@ MockDownloadManager::CreateDownloadItemAdapter::CreateDownloadItemAdapter(
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
@@ -30,6 +32,8 @@ MockDownloadManager::CreateDownloadItemAdapter::CreateDownloadItemAdapter(
target_path(target_path),
url_chain(url_chain),
referrer_url(referrer_url),
+ mime_type(mime_type),
+ original_mime_type(original_mime_type),
start_time(start_time),
end_time(end_time),
received_bytes(received_bytes),
@@ -66,6 +70,8 @@ bool MockDownloadManager::CreateDownloadItemAdapter::operator==(
target_path == rhs.target_path &&
url_chain == rhs.url_chain &&
referrer_url == rhs.referrer_url &&
+ mime_type == rhs.mime_type &&
+ original_mime_type == rhs.original_mime_type &&
start_time == rhs.start_time &&
end_time == rhs.end_time &&
etag == rhs.etag &&
@@ -95,6 +101,8 @@ DownloadItem* MockDownloadManager::CreateDownloadItem(
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
@@ -106,9 +114,10 @@ DownloadItem* MockDownloadManager::CreateDownloadItem(
DownloadInterruptReason interrupt_reason,
bool opened) {
CreateDownloadItemAdapter adapter(
- id, current_path, target_path, url_chain, referrer_url, start_time,
- end_time, etag, last_modified, received_bytes, total_bytes, state,
- danger_type, interrupt_reason, opened);
+ id, current_path, target_path, url_chain, referrer_url, mime_type,
+ original_mime_type, start_time, end_time, etag, last_modified,
+ received_bytes, total_bytes, state, danger_type, interrupt_reason,
+ opened);
return MockCreateDownloadItem(adapter);
}
diff --git a/content/public/test/mock_download_manager.h b/content/public/test/mock_download_manager.h
index abf0305..1ab4ca5 100644
--- a/content/public/test/mock_download_manager.h
+++ b/content/public/test/mock_download_manager.h
@@ -5,6 +5,7 @@
#ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_MOCK_DOWNLOAD_MANAGER_H_
#define CONTENT_PUBLIC_BROWSER_DOWNLOAD_MOCK_DOWNLOAD_MANAGER_H_
+#include <string>
#include <vector>
#include "content/public/browser/download_manager.h"
@@ -31,6 +32,8 @@ class MockDownloadManager : public DownloadManager {
base::FilePath target_path;
std::vector<GURL> url_chain;
GURL referrer_url;
+ std::string mime_type;
+ std::string original_mime_type;
base::Time start_time;
base::Time end_time;
std::string etag;
@@ -48,6 +51,8 @@ class MockDownloadManager : public DownloadManager {
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,
@@ -101,6 +106,8 @@ class MockDownloadManager : public DownloadManager {
const base::FilePath& target_path,
const std::vector<GURL>& url_chain,
const GURL& referrer_url,
+ const std::string& mime_type,
+ const std::string& original_mime_type,
const base::Time& start_time,
const base::Time& end_time,
const std::string& etag,