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

Side by Side Diff: chrome/browser/history/download_database.cc

Issue 7237034: sql::MetaTable.next_download_id, DownloadManager::GetNextId() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: sql::MetaTable.next_download_id, DownloadId, DownloadManager::GetNextId() Created 9 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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<DownloadHistoryInfo>* results) { 91 std::vector<DownloadHistoryInfo>* results) {
85 results->clear(); 92 results->clear();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 if (!statement) 160 if (!statement)
154 return 0; 161 return 0;
155 162
156 BindFilePath(statement, info.path, 0); 163 BindFilePath(statement, info.path, 0);
157 statement.BindString(1, info.url.spec()); 164 statement.BindString(1, info.url.spec());
158 statement.BindInt64(2, info.start_time.ToTimeT()); 165 statement.BindInt64(2, info.start_time.ToTimeT());
159 statement.BindInt64(3, info.received_bytes); 166 statement.BindInt64(3, info.received_bytes);
160 statement.BindInt64(4, info.total_bytes); 167 statement.BindInt64(4, info.total_bytes);
161 statement.BindInt(5, info.state); 168 statement.BindInt(5, info.state);
162 169
163 if (statement.Run()) 170 if (statement.Run()) {
164 return GetDB().GetLastInsertRowId(); 171 int64 db_handle = GetDB().GetLastInsertRowId();
172 // TODO(benjhayden) if(info.id>next_id_){setvalue;next_id_=info.id;}
173 meta_table_.SetValue(kNextDownloadId, ++next_id_);
Randy Smith (Not in Mondays) 2011/07/25 20:20:12 Is there a reason why it's safe not to implement t
benjhayden 2011/07/27 19:40:54 This next_id_ is only communicated to DownloadMana
Randy Smith (Not in Mondays) 2011/07/28 21:03:16 Sorry, still having problems distinguishing non-pe
benjhayden 2011/08/03 17:44:46 Done.
174 return db_handle;
175 }
165 return 0; 176 return 0;
166 } 177 }
167 178
168 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { 179 void DownloadDatabase::RemoveDownload(DownloadID db_handle) {
169 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 180 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
170 "DELETE FROM downloads WHERE id=?")); 181 "DELETE FROM downloads WHERE id=?"));
171 if (!statement) 182 if (!statement)
172 return; 183 return;
173 184
174 statement.BindInt64(0, db_handle); 185 statement.BindInt64(0, db_handle);
(...skipping 16 matching lines...) Expand all
191 statement.BindInt64( 202 statement.BindInt64(
192 1, 203 1,
193 end_time ? end_time : std::numeric_limits<int64>::max()); 204 end_time ? end_time : std::numeric_limits<int64>::max());
194 statement.BindInt(2, DownloadItem::COMPLETE); 205 statement.BindInt(2, DownloadItem::COMPLETE);
195 statement.BindInt(3, DownloadItem::CANCELLED); 206 statement.BindInt(3, DownloadItem::CANCELLED);
196 statement.BindInt(4, DownloadItem::INTERRUPTED); 207 statement.BindInt(4, DownloadItem::INTERRUPTED);
197 statement.Run(); 208 statement.Run();
198 } 209 }
199 210
200 } // namespace history 211 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698