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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // See above. | 45 // See above. |
46 void BindFilePath(sql::Statement& statement, const FilePath& path, int col) { | 46 void BindFilePath(sql::Statement& statement, const FilePath& path, int col) { |
47 statement.BindString(col, UTF16ToUTF8(path.value())); | 47 statement.BindString(col, UTF16ToUTF8(path.value())); |
48 } | 48 } |
49 FilePath ColumnFilePath(sql::Statement& statement, int col) { | 49 FilePath ColumnFilePath(sql::Statement& statement, int col) { |
50 return FilePath(UTF8ToUTF16(statement.ColumnString(col))); | 50 return FilePath(UTF8ToUTF16(statement.ColumnString(col))); |
51 } | 51 } |
52 | 52 |
53 #endif | 53 #endif |
54 | 54 |
| 55 // Key in the meta_table containing the next id to use for a new download in |
| 56 // this profile. |
| 57 static const char kNextDownloadId[] = "next_download_id"; |
| 58 |
55 } // namespace | 59 } // namespace |
56 | 60 |
57 DownloadDatabase::DownloadDatabase() { | 61 DownloadDatabase::DownloadDatabase() |
| 62 : next_id_(0) { |
58 } | 63 } |
59 | 64 |
60 DownloadDatabase::~DownloadDatabase() { | 65 DownloadDatabase::~DownloadDatabase() { |
61 } | 66 } |
62 | 67 |
63 bool DownloadDatabase::InitDownloadTable() { | 68 bool DownloadDatabase::InitDownloadTable() { |
64 if (!GetDB().DoesTableExist("downloads")) { | 69 if (!GetDB().DoesTableExist("downloads")) { |
65 if (!GetDB().Execute( | 70 if (!GetDB().Execute( |
66 "CREATE TABLE downloads (" | 71 "CREATE TABLE downloads (" |
67 "id INTEGER PRIMARY KEY," | 72 "id INTEGER PRIMARY KEY," |
68 "full_path LONGVARCHAR NOT NULL," | 73 "full_path LONGVARCHAR NOT NULL," |
69 "url LONGVARCHAR NOT NULL," | 74 "url LONGVARCHAR NOT NULL," |
70 "start_time INTEGER NOT NULL," | 75 "start_time INTEGER NOT NULL," |
71 "received_bytes INTEGER NOT NULL," | 76 "received_bytes INTEGER NOT NULL," |
72 "total_bytes INTEGER NOT NULL," | 77 "total_bytes INTEGER NOT NULL," |
73 "state INTEGER NOT NULL)")) | 78 "state INTEGER NOT NULL)")) |
74 return false; | 79 return false; |
75 } | 80 } |
| 81 meta_table_.Init(&GetDB(), 0, 0); |
| 82 meta_table_.GetValue(kNextDownloadId, &next_id_); |
76 return true; | 83 return true; |
77 } | 84 } |
78 | 85 |
79 bool DownloadDatabase::DropDownloadTable() { | 86 bool DownloadDatabase::DropDownloadTable() { |
80 return GetDB().Execute("DROP TABLE downloads"); | 87 return GetDB().Execute("DROP TABLE downloads"); |
81 } | 88 } |
82 | 89 |
83 void DownloadDatabase::QueryDownloads( | 90 void DownloadDatabase::QueryDownloads( |
84 std::vector<DownloadPersistentStoreInfo>* results) { | 91 std::vector<DownloadPersistentStoreInfo>* results) { |
85 results->clear(); | 92 results->clear(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (!statement) | 161 if (!statement) |
155 return 0; | 162 return 0; |
156 | 163 |
157 BindFilePath(statement, info.path, 0); | 164 BindFilePath(statement, info.path, 0); |
158 statement.BindString(1, info.url.spec()); | 165 statement.BindString(1, info.url.spec()); |
159 statement.BindInt64(2, info.start_time.ToTimeT()); | 166 statement.BindInt64(2, info.start_time.ToTimeT()); |
160 statement.BindInt64(3, info.received_bytes); | 167 statement.BindInt64(3, info.received_bytes); |
161 statement.BindInt64(4, info.total_bytes); | 168 statement.BindInt64(4, info.total_bytes); |
162 statement.BindInt(5, info.state); | 169 statement.BindInt(5, info.state); |
163 | 170 |
164 if (statement.Run()) | 171 if (statement.Run()) { |
165 return GetDB().GetLastInsertRowId(); | 172 int64 db_handle = GetDB().GetLastInsertRowId(); |
| 173 // TODO(benjhayden) if(info.id>next_id_){setvalue;next_id_=info.id;} |
| 174 meta_table_.SetValue(kNextDownloadId, ++next_id_); |
| 175 return db_handle; |
| 176 } |
166 return 0; | 177 return 0; |
167 } | 178 } |
168 | 179 |
169 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { | 180 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { |
170 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 181 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
171 "DELETE FROM downloads WHERE id=?")); | 182 "DELETE FROM downloads WHERE id=?")); |
172 if (!statement) | 183 if (!statement) |
173 return; | 184 return; |
174 | 185 |
175 statement.BindInt64(0, db_handle); | 186 statement.BindInt64(0, db_handle); |
(...skipping 16 matching lines...) Expand all Loading... |
192 statement.BindInt64( | 203 statement.BindInt64( |
193 1, | 204 1, |
194 end_time ? end_time : std::numeric_limits<int64>::max()); | 205 end_time ? end_time : std::numeric_limits<int64>::max()); |
195 statement.BindInt(2, DownloadItem::COMPLETE); | 206 statement.BindInt(2, DownloadItem::COMPLETE); |
196 statement.BindInt(3, DownloadItem::CANCELLED); | 207 statement.BindInt(3, DownloadItem::CANCELLED); |
197 statement.BindInt(4, DownloadItem::INTERRUPTED); | 208 statement.BindInt(4, DownloadItem::INTERRUPTED); |
198 statement.Run(); | 209 statement.Run(); |
199 } | 210 } |
200 | 211 |
201 } // namespace history | 212 } // namespace history |
OLD | NEW |