| Index: chrome/browser/history/download_database.cc
|
| diff --git a/chrome/browser/history/download_database.cc b/chrome/browser/history/download_database.cc
|
| index 5039e186765eb606500d8cd6f5e8715703a1a14f..eee42913330b2551419a476c6fd58d3b2ea4a088 100644
|
| --- a/chrome/browser/history/download_database.cc
|
| +++ b/chrome/browser/history/download_database.cc
|
| @@ -76,15 +76,6 @@ DownloadDatabase::DownloadDatabase()
|
| DownloadDatabase::~DownloadDatabase() {
|
| }
|
|
|
| -void DownloadDatabase::CheckThread() {
|
| - if (owning_thread_set_) {
|
| - DCHECK(owning_thread_ == base::PlatformThread::CurrentId());
|
| - } else {
|
| - owning_thread_ = base::PlatformThread::CurrentId();
|
| - owning_thread_set_ = true;
|
| - }
|
| -}
|
| -
|
| bool DownloadDatabase::EnsureColumnExists(
|
| const std::string& name, const std::string& type) {
|
| std::string add_col = "ALTER TABLE downloads ADD COLUMN " + name + " " + type;
|
| @@ -93,7 +84,6 @@ bool DownloadDatabase::EnsureColumnExists(
|
| }
|
|
|
| bool DownloadDatabase::InitDownloadTable() {
|
| - CheckThread();
|
| GetMetaTable().GetValue(kNextDownloadId, &next_id_);
|
| if (GetDB().DoesTableExist("downloads")) {
|
| return EnsureColumnExists("end_time", "INTEGER NOT NULL DEFAULT 0") &&
|
| @@ -104,13 +94,11 @@ bool DownloadDatabase::InitDownloadTable() {
|
| }
|
|
|
| bool DownloadDatabase::DropDownloadTable() {
|
| - CheckThread();
|
| return GetDB().Execute("DROP TABLE downloads");
|
| }
|
|
|
| void DownloadDatabase::QueryDownloads(
|
| std::vector<DownloadPersistentStoreInfo>* results) {
|
| - CheckThread();
|
| results->clear();
|
| if (next_db_handle_ < 1)
|
| next_db_handle_ = 1;
|
| @@ -145,7 +133,6 @@ void DownloadDatabase::QueryDownloads(
|
| }
|
|
|
| bool DownloadDatabase::UpdateDownload(const DownloadPersistentStoreInfo& data) {
|
| - CheckThread();
|
| DCHECK(data.db_handle > 0);
|
| sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
|
| "UPDATE downloads "
|
| @@ -161,7 +148,6 @@ bool DownloadDatabase::UpdateDownload(const DownloadPersistentStoreInfo& data) {
|
|
|
| bool DownloadDatabase::UpdateDownloadPath(const FilePath& path,
|
| DownloadID db_handle) {
|
| - CheckThread();
|
| DCHECK(db_handle > 0);
|
| sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
|
| "UPDATE downloads SET full_path=? WHERE id=?"));
|
| @@ -172,7 +158,6 @@ bool DownloadDatabase::UpdateDownloadPath(const FilePath& path,
|
| }
|
|
|
| bool DownloadDatabase::CleanUpInProgressEntries() {
|
| - CheckThread();
|
| sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
|
| "UPDATE downloads SET state=? WHERE state=?"));
|
| statement.BindInt(0, DownloadItem::CANCELLED);
|
| @@ -183,7 +168,6 @@ bool DownloadDatabase::CleanUpInProgressEntries() {
|
|
|
| int64 DownloadDatabase::CreateDownload(
|
| const DownloadPersistentStoreInfo& info) {
|
| - CheckThread();
|
|
|
| if (next_db_handle_ == 0) {
|
| // This is unlikely. All current known tests and users already call
|
| @@ -220,61 +204,18 @@ int64 DownloadDatabase::CreateDownload(
|
| return 0;
|
| }
|
|
|
| -void DownloadDatabase::RemoveDownload(DownloadID db_handle) {
|
| - CheckThread();
|
| -
|
| - sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
|
| - "DELETE FROM downloads WHERE id=?"));
|
| - statement.BindInt64(0, db_handle);
|
| -
|
| - statement.Run();
|
| -}
|
| -
|
| -bool DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin,
|
| - base::Time delete_end) {
|
| - CheckThread();
|
| - time_t start_time = delete_begin.ToTimeT();
|
| - time_t end_time = delete_end.ToTimeT();
|
| -
|
| - int num_downloads_deleted = -1;
|
| - {
|
| - sql::Statement count(GetDB().GetCachedStatement(SQL_FROM_HERE,
|
| - "SELECT count(*) FROM downloads WHERE start_time >= ? "
|
| - "AND start_time < ? AND (State = ? OR State = ? OR State = ?)"));
|
| - count.BindInt64(0, start_time);
|
| - count.BindInt64(
|
| - 1,
|
| - end_time ? end_time : std::numeric_limits<int64>::max());
|
| - count.BindInt(2, DownloadItem::COMPLETE);
|
| - count.BindInt(3, DownloadItem::CANCELLED);
|
| - count.BindInt(4, DownloadItem::INTERRUPTED);
|
| - if (count.Step())
|
| - num_downloads_deleted = count.ColumnInt(0);
|
| - }
|
| -
|
| -
|
| - bool success = false;
|
| +void DownloadDatabase::RemoveDownloads(const std::set<DownloadID>& handles) {
|
| base::TimeTicks started_removing = base::TimeTicks::Now();
|
| - {
|
| - // This does not use an index. We currently aren't likely to have enough
|
| - // downloads where an index by time will give us a lot of benefit.
|
| + for (std::set<DownloadID>::const_iterator it = handles.begin();
|
| + it != handles.end(); ++it) {
|
| sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
|
| - "DELETE FROM downloads WHERE start_time >= ? AND start_time < ? "
|
| - "AND (State = ? OR State = ? OR State = ?)"));
|
| - statement.BindInt64(0, start_time);
|
| - statement.BindInt64(
|
| - 1,
|
| - end_time ? end_time : std::numeric_limits<int64>::max());
|
| - statement.BindInt(2, DownloadItem::COMPLETE);
|
| - statement.BindInt(3, DownloadItem::CANCELLED);
|
| - statement.BindInt(4, DownloadItem::INTERRUPTED);
|
| -
|
| - success = statement.Run();
|
| + "DELETE FROM downloads WHERE id=?"));
|
| + statement.BindInt64(0, *it);
|
| + statement.Run();
|
| }
|
| -
|
| - base::TimeTicks finished_removing = base::TimeTicks::Now();
|
| -
|
| + int num_downloads_deleted = handles.size(); // TODO(benjhayden) measure
|
| if (num_downloads_deleted >= 0) {
|
| + base::TimeTicks finished_removing = base::TimeTicks::Now();
|
| UMA_HISTOGRAM_COUNTS("Download.DatabaseRemoveDownloadsCount",
|
| num_downloads_deleted);
|
| base::TimeDelta micros = (1000 * (finished_removing - started_removing));
|
| @@ -284,8 +225,6 @@ bool DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin,
|
| (1000 * micros) / num_downloads_deleted);
|
| }
|
| }
|
| -
|
| - return success;
|
| }
|
|
|
| } // namespace history
|
|
|