| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 bool DownloadDatabase::EnsureColumnExists( | 97 bool DownloadDatabase::EnsureColumnExists( |
| 98 const std::string& name, const std::string& type) { | 98 const std::string& name, const std::string& type) { |
| 99 std::string add_col = "ALTER TABLE downloads ADD COLUMN " + name + " " + type; | 99 std::string add_col = "ALTER TABLE downloads ADD COLUMN " + name + " " + type; |
| 100 return GetDB().DoesColumnExist("downloads", name.c_str()) || | 100 return GetDB().DoesColumnExist("downloads", name.c_str()) || |
| 101 GetDB().Execute(add_col.c_str()); | 101 GetDB().Execute(add_col.c_str()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool DownloadDatabase::InitDownloadTable() { | 104 bool DownloadDatabase::InitDownloadTable() { |
| 105 CheckThread(); | 105 CheckThread(); |
| 106 bool success = meta_table_.Init(&GetDB(), 0, 0); | 106 GetMetaTable().GetValue(kNextDownloadId, &next_id_); |
| 107 DCHECK(success); | |
| 108 meta_table_.GetValue(kNextDownloadId, &next_id_); | |
| 109 if (GetDB().DoesTableExist("downloads")) { | 107 if (GetDB().DoesTableExist("downloads")) { |
| 110 return EnsureColumnExists("end_time", "INTEGER NOT NULL DEFAULT 0") && | 108 return EnsureColumnExists("end_time", "INTEGER NOT NULL DEFAULT 0") && |
| 111 EnsureColumnExists("opened", "INTEGER NOT NULL DEFAULT 0"); | 109 EnsureColumnExists("opened", "INTEGER NOT NULL DEFAULT 0"); |
| 112 } else { | 110 } else { |
| 113 return GetDB().Execute(kSchema); | 111 return GetDB().Execute(kSchema); |
| 114 } | 112 } |
| 115 } | 113 } |
| 116 | 114 |
| 117 bool DownloadDatabase::DropDownloadTable() { | 115 bool DownloadDatabase::DropDownloadTable() { |
| 118 CheckThread(); | 116 CheckThread(); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 statement.BindString(2, info.url.spec()); | 215 statement.BindString(2, info.url.spec()); |
| 218 statement.BindInt64(3, info.start_time.ToTimeT()); | 216 statement.BindInt64(3, info.start_time.ToTimeT()); |
| 219 statement.BindInt64(4, info.received_bytes); | 217 statement.BindInt64(4, info.received_bytes); |
| 220 statement.BindInt64(5, info.total_bytes); | 218 statement.BindInt64(5, info.total_bytes); |
| 221 statement.BindInt(6, info.state); | 219 statement.BindInt(6, info.state); |
| 222 statement.BindInt64(7, info.end_time.ToTimeT()); | 220 statement.BindInt64(7, info.end_time.ToTimeT()); |
| 223 statement.BindInt(8, info.opened ? 1 : 0); | 221 statement.BindInt(8, info.opened ? 1 : 0); |
| 224 | 222 |
| 225 if (statement.Run()) { | 223 if (statement.Run()) { |
| 226 // TODO(benjhayden) if(info.id>next_id_){setvalue;next_id_=info.id;} | 224 // TODO(benjhayden) if(info.id>next_id_){setvalue;next_id_=info.id;} |
| 227 meta_table_.SetValue(kNextDownloadId, ++next_id_); | 225 GetMetaTable().SetValue(kNextDownloadId, ++next_id_); |
| 228 | 226 |
| 229 return db_handle; | 227 return db_handle; |
| 230 } | 228 } |
| 231 return 0; | 229 return 0; |
| 232 } | 230 } |
| 233 | 231 |
| 234 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { | 232 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { |
| 235 CheckThread(); | 233 CheckThread(); |
| 236 | 234 |
| 237 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 235 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 if (num_downloads_deleted > 0) { | 291 if (num_downloads_deleted > 0) { |
| 294 UMA_HISTOGRAM_TIMES("Download.DatabaseRemoveDownloadsTimePerRecord", | 292 UMA_HISTOGRAM_TIMES("Download.DatabaseRemoveDownloadsTimePerRecord", |
| 295 (1000 * micros) / num_downloads_deleted); | 293 (1000 * micros) / num_downloads_deleted); |
| 296 } | 294 } |
| 297 } | 295 } |
| 298 | 296 |
| 299 return success; | 297 return success; |
| 300 } | 298 } |
| 301 | 299 |
| 302 } // namespace history | 300 } // namespace history |
| OLD | NEW |