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

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

Issue 9071014: Database usage adjustment for .../history (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 12 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
Index: chrome/browser/history/download_database.cc
diff --git a/chrome/browser/history/download_database.cc b/chrome/browser/history/download_database.cc
index 6cf6f3a9c8b5c5eb70c97a52a55d5289f6993cf5..5cc5aef2f3863184ed9d0eeab39c77d66b9aed17 100644
--- a/chrome/browser/history/download_database.cc
+++ b/chrome/browser/history/download_database.cc
@@ -115,8 +115,6 @@ void DownloadDatabase::QueryDownloads(
"total_bytes, state, end_time, opened "
"FROM downloads "
"ORDER BY start_time"));
- if (!statement)
- return;
while (statement.Step()) {
DownloadPersistentStoreInfo info;
@@ -148,14 +146,12 @@ bool DownloadDatabase::UpdateDownload(const DownloadPersistentStoreInfo& data) {
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"UPDATE downloads "
"SET received_bytes=?, state=?, end_time=?, opened=? WHERE id=?"));
- if (!statement)
- return false;
-
statement.BindInt64(0, data.received_bytes);
statement.BindInt(1, data.state);
statement.BindInt64(2, data.end_time.ToTimeT());
statement.BindInt(3, (data.opened ? 1 : 0));
statement.BindInt64(4, data.db_handle);
+
return statement.Run();
}
@@ -165,11 +161,9 @@ bool DownloadDatabase::UpdateDownloadPath(const FilePath& path,
DCHECK(db_handle > 0);
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"UPDATE downloads SET full_path=? WHERE id=?"));
- if (!statement)
- return false;
-
BindFilePath(statement, path, 0);
statement.BindInt64(1, db_handle);
+
return statement.Run();
}
@@ -177,10 +171,9 @@ bool DownloadDatabase::CleanUpInProgressEntries() {
CheckThread();
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();
}
@@ -193,9 +186,6 @@ int64 DownloadDatabase::CreateDownload(
"(full_path, url, start_time, received_bytes, total_bytes, state, "
"end_time, opened) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)"));
- if (!statement)
- return 0;
-
BindFilePath(statement, info.path, 0);
statement.BindString(1, info.url.spec());
statement.BindInt64(2, info.start_time.ToTimeT());
@@ -216,7 +206,7 @@ int64 DownloadDatabase::CreateDownload(
sql::Statement dbg_statement(GetDB().GetCachedStatement(
SQL_FROM_HERE,
"SELECT id FROM downloads;"));
- CHECK(dbg_statement);
+ CHECK(dbg_statement.is_valid());
std::set<int64> database_ids;
while (dbg_statement.Step()) {
@@ -240,16 +230,16 @@ void DownloadDatabase::RemoveDownload(DownloadID db_handle) {
CheckThread();
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"DELETE FROM downloads WHERE id=?"));
- if (!statement)
+ statement.BindInt64(0, db_handle);
+
+ // TODO(rdsmith): Remove when http://crbug.com/96627 is resolved.
Scott Hess - ex-Googler 2012/01/03 23:41:57 The target of this TODO seems ambiguous, now. May
Greg Billock 2012/01/04 19:20:20 I think I misplaced it. Should be by the erase I t
Randy Smith (Not in Mondays) 2012/01/04 19:34:18 Yes, it should.
+ if (!statement.Run())
return;
- statement.BindInt64(0, db_handle);
- if (statement.Run())
- // TODO(rdsmith): Remove when http://crbug.com/96627 is resolved.
- returned_ids_.erase(db_handle);
+ returned_ids_.erase(db_handle);
}
-void DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin,
+bool DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin,
base::Time delete_end) {
CheckThread();
time_t start_time = delete_begin.ToTimeT();
@@ -261,8 +251,6 @@ void DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin,
SQL_FROM_HERE,
"SELECT id FROM downloads WHERE start_time >= ? AND start_time < ? "
"AND (State = ? OR State = ? OR State = ?)"));
- if (!dbg_statement)
- return;
dbg_statement.BindInt64(0, start_time);
dbg_statement.BindInt64(
1,
@@ -270,6 +258,10 @@ void DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin,
dbg_statement.BindInt(2, DownloadItem::COMPLETE);
dbg_statement.BindInt(3, DownloadItem::CANCELLED);
dbg_statement.BindInt(4, DownloadItem::INTERRUPTED);
+
+ if (!dbg_statement.is_valid())
+ return false;
+
while (dbg_statement.Step()) {
int64 id_to_delete = dbg_statement.ColumnInt64(0);
returned_ids_.erase(id_to_delete);
@@ -282,9 +274,6 @@ void DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin,
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"DELETE FROM downloads WHERE start_time >= ? AND start_time < ? "
"AND (State = ? OR State = ? OR State = ?)"));
- if (!statement)
- return;
-
statement.BindInt64(0, start_time);
statement.BindInt64(
1,
@@ -292,7 +281,8 @@ void DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin,
statement.BindInt(2, DownloadItem::COMPLETE);
statement.BindInt(3, DownloadItem::CANCELLED);
statement.BindInt(4, DownloadItem::INTERRUPTED);
- statement.Run();
+
+ return statement.Run();
}
} // namespace history

Powered by Google App Engine
This is Rietveld 408576698