| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 // See above. | 46 // See above. |
| 47 void BindFilePath(sql::Statement& statement, const FilePath& path, int col) { | 47 void BindFilePath(sql::Statement& statement, const FilePath& path, int col) { |
| 48 statement.BindString(col, UTF16ToUTF8(path.value())); | 48 statement.BindString(col, UTF16ToUTF8(path.value())); |
| 49 } | 49 } |
| 50 FilePath ColumnFilePath(sql::Statement& statement, int col) { | 50 FilePath ColumnFilePath(sql::Statement& statement, int col) { |
| 51 return FilePath(UTF8ToUTF16(statement.ColumnString(col))); | 51 return FilePath(UTF8ToUTF16(statement.ColumnString(col))); |
| 52 } | 52 } |
| 53 | 53 |
| 54 #endif | 54 #endif |
| 55 | 55 |
| 56 // Key in the meta_table containing the next id to use for a new download in |
| 57 // this profile. |
| 58 static const char kNextDownloadId[] = "next_download_id"; |
| 59 |
| 56 } // namespace | 60 } // namespace |
| 57 | 61 |
| 58 DownloadDatabase::DownloadDatabase() | 62 DownloadDatabase::DownloadDatabase() |
| 59 : owning_thread_set_(false) { | 63 : owning_thread_set_(false), |
| 64 next_id_(0) { |
| 60 } | 65 } |
| 61 | 66 |
| 62 DownloadDatabase::~DownloadDatabase() { | 67 DownloadDatabase::~DownloadDatabase() { |
| 63 } | 68 } |
| 64 | 69 |
| 65 bool DownloadDatabase::InitDownloadTable() { | 70 bool DownloadDatabase::InitDownloadTable() { |
| 66 if (!GetDB().DoesTableExist("downloads")) { | 71 if (!GetDB().DoesTableExist("downloads")) { |
| 67 if (!GetDB().Execute( | 72 if (!GetDB().Execute( |
| 68 "CREATE TABLE downloads (" | 73 "CREATE TABLE downloads (" |
| 69 "id INTEGER PRIMARY KEY," | 74 "id INTEGER PRIMARY KEY," |
| 70 "full_path LONGVARCHAR NOT NULL," | 75 "full_path LONGVARCHAR NOT NULL," |
| 71 "url LONGVARCHAR NOT NULL," | 76 "url LONGVARCHAR NOT NULL," |
| 72 "start_time INTEGER NOT NULL," | 77 "start_time INTEGER NOT NULL," |
| 73 "received_bytes INTEGER NOT NULL," | 78 "received_bytes INTEGER NOT NULL," |
| 74 "total_bytes INTEGER NOT NULL," | 79 "total_bytes INTEGER NOT NULL," |
| 75 "state INTEGER NOT NULL)")) | 80 "state INTEGER NOT NULL)")) |
| 76 return false; | 81 return false; |
| 77 } | 82 } |
| 83 meta_table_.Init(&GetDB(), 0, 0); |
| 84 meta_table_.GetValue(kNextDownloadId, &next_id_); |
| 78 return true; | 85 return true; |
| 79 } | 86 } |
| 80 | 87 |
| 81 bool DownloadDatabase::DropDownloadTable() { | 88 bool DownloadDatabase::DropDownloadTable() { |
| 82 return GetDB().Execute("DROP TABLE downloads"); | 89 return GetDB().Execute("DROP TABLE downloads"); |
| 83 } | 90 } |
| 84 | 91 |
| 85 void DownloadDatabase::QueryDownloads( | 92 void DownloadDatabase::QueryDownloads( |
| 86 std::vector<DownloadPersistentStoreInfo>* results) { | 93 std::vector<DownloadPersistentStoreInfo>* results) { |
| 87 results->clear(); | 94 results->clear(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 statement.BindInt64(3, info.received_bytes); | 176 statement.BindInt64(3, info.received_bytes); |
| 170 statement.BindInt64(4, info.total_bytes); | 177 statement.BindInt64(4, info.total_bytes); |
| 171 statement.BindInt(5, info.state); | 178 statement.BindInt(5, info.state); |
| 172 | 179 |
| 173 if (statement.Run()) { | 180 if (statement.Run()) { |
| 174 int64 id = GetDB().GetLastInsertRowId(); | 181 int64 id = GetDB().GetLastInsertRowId(); |
| 175 | 182 |
| 176 CHECK_EQ(0u, returned_ids_.count(id)); | 183 CHECK_EQ(0u, returned_ids_.count(id)); |
| 177 returned_ids_.insert(id); | 184 returned_ids_.insert(id); |
| 178 | 185 |
| 186 // TODO(benjhayden) if(info.id>next_id_){setvalue;next_id_=info.id;} |
| 187 meta_table_.SetValue(kNextDownloadId, ++next_id_); |
| 188 |
| 179 return id; | 189 return id; |
| 180 } | 190 } |
| 181 return 0; | 191 return 0; |
| 182 } | 192 } |
| 183 | 193 |
| 184 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { | 194 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { |
| 185 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 195 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 186 "DELETE FROM downloads WHERE id=?")); | 196 "DELETE FROM downloads WHERE id=?")); |
| 187 if (!statement) | 197 if (!statement) |
| 188 return; | 198 return; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 statement.BindInt64( | 241 statement.BindInt64( |
| 232 1, | 242 1, |
| 233 end_time ? end_time : std::numeric_limits<int64>::max()); | 243 end_time ? end_time : std::numeric_limits<int64>::max()); |
| 234 statement.BindInt(2, DownloadItem::COMPLETE); | 244 statement.BindInt(2, DownloadItem::COMPLETE); |
| 235 statement.BindInt(3, DownloadItem::CANCELLED); | 245 statement.BindInt(3, DownloadItem::CANCELLED); |
| 236 statement.BindInt(4, DownloadItem::INTERRUPTED); | 246 statement.BindInt(4, DownloadItem::INTERRUPTED); |
| 237 statement.Run(); | 247 statement.Run(); |
| 238 } | 248 } |
| 239 | 249 |
| 240 } // namespace history | 250 } // namespace history |
| OLD | NEW |