| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/history/download_database.h" | 5 #include "chrome/browser/history/download_database.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 statement.BindString(col, path.value()); | 52 statement.BindString(col, path.value()); |
| 53 } | 53 } |
| 54 FilePath ColumnFilePath(sql::Statement& statement, int col) { | 54 FilePath ColumnFilePath(sql::Statement& statement, int col) { |
| 55 return FilePath(statement.ColumnString(col)); | 55 return FilePath(statement.ColumnString(col)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 #else | 58 #else |
| 59 | 59 |
| 60 // See above. | 60 // See above. |
| 61 void BindFilePath(sql::Statement& statement, const FilePath& path, int col) { | 61 void BindFilePath(sql::Statement& statement, const FilePath& path, int col) { |
| 62 statement.BindString(col, UTF16ToUTF8(path.value())); | 62 statement.BindString16(col, path.value()); |
| 63 } | 63 } |
| 64 FilePath ColumnFilePath(sql::Statement& statement, int col) { | 64 FilePath ColumnFilePath(sql::Statement& statement, int col) { |
| 65 return FilePath(UTF8ToUTF16(statement.ColumnString(col))); | 65 return FilePath(statement.ColumnString16(col)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 // Key in the meta_table containing the next id to use for a new download in | 70 // Key in the meta_table containing the next id to use for a new download in |
| 71 // this profile. | 71 // this profile. |
| 72 static const char kNextDownloadId[] = "next_download_id"; | 72 static const char kNextDownloadId[] = "next_download_id"; |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // TODO(benjhayden) if(info.id>next_id_){setvalue;next_id_=info.id;} | 218 // TODO(benjhayden) if(info.id>next_id_){setvalue;next_id_=info.id;} |
| 219 meta_table_.SetValue(kNextDownloadId, ++next_id_); | 219 meta_table_.SetValue(kNextDownloadId, ++next_id_); |
| 220 | 220 |
| 221 return db_handle; | 221 return db_handle; |
| 222 } | 222 } |
| 223 return 0; | 223 return 0; |
| 224 } | 224 } |
| 225 | 225 |
| 226 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { | 226 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { |
| 227 CheckThread(); | 227 CheckThread(); |
| 228 |
| 228 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 229 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 229 "DELETE FROM downloads WHERE id=?")); | 230 "DELETE FROM downloads WHERE id=?")); |
| 230 statement.BindInt64(0, db_handle); | 231 statement.BindInt64(0, db_handle); |
| 232 |
| 231 statement.Run(); | 233 statement.Run(); |
| 232 } | 234 } |
| 233 | 235 |
| 234 bool DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin, | 236 bool DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin, |
| 235 base::Time delete_end) { | 237 base::Time delete_end) { |
| 236 CheckThread(); | 238 CheckThread(); |
| 237 time_t start_time = delete_begin.ToTimeT(); | 239 time_t start_time = delete_begin.ToTimeT(); |
| 238 time_t end_time = delete_end.ToTimeT(); | 240 time_t end_time = delete_end.ToTimeT(); |
| 239 | 241 |
| 240 // This does not use an index. We currently aren't likely to have enough | 242 // This does not use an index. We currently aren't likely to have enough |
| 241 // downloads where an index by time will give us a lot of benefit. | 243 // downloads where an index by time will give us a lot of benefit. |
| 242 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 244 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 243 "DELETE FROM downloads WHERE start_time >= ? AND start_time < ? " | 245 "DELETE FROM downloads WHERE start_time >= ? AND start_time < ? " |
| 244 "AND (State = ? OR State = ? OR State = ?)")); | 246 "AND (State = ? OR State = ? OR State = ?)")); |
| 245 statement.BindInt64(0, start_time); | 247 statement.BindInt64(0, start_time); |
| 246 statement.BindInt64( | 248 statement.BindInt64( |
| 247 1, | 249 1, |
| 248 end_time ? end_time : std::numeric_limits<int64>::max()); | 250 end_time ? end_time : std::numeric_limits<int64>::max()); |
| 249 statement.BindInt(2, DownloadItem::COMPLETE); | 251 statement.BindInt(2, DownloadItem::COMPLETE); |
| 250 statement.BindInt(3, DownloadItem::CANCELLED); | 252 statement.BindInt(3, DownloadItem::CANCELLED); |
| 251 statement.BindInt(4, DownloadItem::INTERRUPTED); | 253 statement.BindInt(4, DownloadItem::INTERRUPTED); |
| 252 | 254 |
| 253 return statement.Run(); | 255 return statement.Run(); |
| 254 } | 256 } |
| 255 | 257 |
| 256 } // namespace history | 258 } // namespace history |
| OLD | NEW |