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

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

Issue 7793003: Revert 98656 - Make a new integer field in sql::MetaTable (a per-profile db) containing a counter... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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
« no previous file with comments | « chrome/browser/history/download_database.h ('k') | chrome/browser/history/history.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
59 } // namespace 55 } // namespace
60 56
61 DownloadDatabase::DownloadDatabase() 57 DownloadDatabase::DownloadDatabase() {
62 : next_id_(0) {
63 } 58 }
64 59
65 DownloadDatabase::~DownloadDatabase() { 60 DownloadDatabase::~DownloadDatabase() {
66 } 61 }
67 62
68 bool DownloadDatabase::InitDownloadTable() { 63 bool DownloadDatabase::InitDownloadTable() {
69 if (!GetDB().DoesTableExist("downloads")) { 64 if (!GetDB().DoesTableExist("downloads")) {
70 if (!GetDB().Execute( 65 if (!GetDB().Execute(
71 "CREATE TABLE downloads (" 66 "CREATE TABLE downloads ("
72 "id INTEGER PRIMARY KEY," 67 "id INTEGER PRIMARY KEY,"
73 "full_path LONGVARCHAR NOT NULL," 68 "full_path LONGVARCHAR NOT NULL,"
74 "url LONGVARCHAR NOT NULL," 69 "url LONGVARCHAR NOT NULL,"
75 "start_time INTEGER NOT NULL," 70 "start_time INTEGER NOT NULL,"
76 "received_bytes INTEGER NOT NULL," 71 "received_bytes INTEGER NOT NULL,"
77 "total_bytes INTEGER NOT NULL," 72 "total_bytes INTEGER NOT NULL,"
78 "state INTEGER NOT NULL)")) 73 "state INTEGER NOT NULL)"))
79 return false; 74 return false;
80 } 75 }
81 meta_table_.Init(&GetDB(), 0, 0);
82 meta_table_.GetValue(kNextDownloadId, &next_id_);
83 return true; 76 return true;
84 } 77 }
85 78
86 bool DownloadDatabase::DropDownloadTable() { 79 bool DownloadDatabase::DropDownloadTable() {
87 return GetDB().Execute("DROP TABLE downloads"); 80 return GetDB().Execute("DROP TABLE downloads");
88 } 81 }
89 82
90 void DownloadDatabase::QueryDownloads( 83 void DownloadDatabase::QueryDownloads(
91 std::vector<DownloadPersistentStoreInfo>* results) { 84 std::vector<DownloadPersistentStoreInfo>* results) {
92 results->clear(); 85 results->clear();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 if (!statement) 154 if (!statement)
162 return 0; 155 return 0;
163 156
164 BindFilePath(statement, info.path, 0); 157 BindFilePath(statement, info.path, 0);
165 statement.BindString(1, info.url.spec()); 158 statement.BindString(1, info.url.spec());
166 statement.BindInt64(2, info.start_time.ToTimeT()); 159 statement.BindInt64(2, info.start_time.ToTimeT());
167 statement.BindInt64(3, info.received_bytes); 160 statement.BindInt64(3, info.received_bytes);
168 statement.BindInt64(4, info.total_bytes); 161 statement.BindInt64(4, info.total_bytes);
169 statement.BindInt(5, info.state); 162 statement.BindInt(5, info.state);
170 163
171 if (statement.Run()) { 164 if (statement.Run())
172 int64 db_handle = GetDB().GetLastInsertRowId(); 165 return 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 }
177 return 0; 166 return 0;
178 } 167 }
179 168
180 void DownloadDatabase::RemoveDownload(DownloadID db_handle) { 169 void DownloadDatabase::RemoveDownload(DownloadID db_handle) {
181 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 170 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
182 "DELETE FROM downloads WHERE id=?")); 171 "DELETE FROM downloads WHERE id=?"));
183 if (!statement) 172 if (!statement)
184 return; 173 return;
185 174
186 statement.BindInt64(0, db_handle); 175 statement.BindInt64(0, db_handle);
(...skipping 16 matching lines...) Expand all
203 statement.BindInt64( 192 statement.BindInt64(
204 1, 193 1,
205 end_time ? end_time : std::numeric_limits<int64>::max()); 194 end_time ? end_time : std::numeric_limits<int64>::max());
206 statement.BindInt(2, DownloadItem::COMPLETE); 195 statement.BindInt(2, DownloadItem::COMPLETE);
207 statement.BindInt(3, DownloadItem::CANCELLED); 196 statement.BindInt(3, DownloadItem::CANCELLED);
208 statement.BindInt(4, DownloadItem::INTERRUPTED); 197 statement.BindInt(4, DownloadItem::INTERRUPTED);
209 statement.Run(); 198 statement.Run();
210 } 199 }
211 200
212 } // namespace history 201 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/download_database.h ('k') | chrome/browser/history/history.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698