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 "app/sql/statement.h" | 10 #include "app/sql/statement.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 return false; | 74 return false; |
75 } | 75 } |
76 return true; | 76 return true; |
77 } | 77 } |
78 | 78 |
79 bool DownloadDatabase::DropDownloadTable() { | 79 bool DownloadDatabase::DropDownloadTable() { |
80 return GetDB().Execute("DROP TABLE downloads"); | 80 return GetDB().Execute("DROP TABLE downloads"); |
81 } | 81 } |
82 | 82 |
83 void DownloadDatabase::QueryDownloads( | 83 void DownloadDatabase::QueryDownloads( |
84 std::vector<DownloadCreateInfo>* results) { | 84 std::vector<DownloadHistoryInfo>* results) { |
85 results->clear(); | 85 results->clear(); |
86 | 86 |
87 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 87 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
88 "SELECT id, full_path, url, start_time, received_bytes, " | 88 "SELECT id, full_path, url, start_time, received_bytes, " |
89 "total_bytes, state " | 89 "total_bytes, state " |
90 "FROM downloads " | 90 "FROM downloads " |
91 "ORDER BY start_time")); | 91 "ORDER BY start_time")); |
92 if (!statement) | 92 if (!statement) |
93 return; | 93 return; |
94 | 94 |
95 while (statement.Step()) { | 95 while (statement.Step()) { |
96 DownloadCreateInfo info; | 96 DownloadHistoryInfo info; |
97 info.db_handle = statement.ColumnInt64(0); | 97 info.db_handle = statement.ColumnInt64(0); |
98 | 98 |
99 info.path = ColumnFilePath(statement, 1); | 99 info.path = ColumnFilePath(statement, 1); |
100 info.url_chain.push_back(GURL(statement.ColumnString(2))); | 100 info.url_chain.push_back(GURL(statement.ColumnString(2))); |
101 info.start_time = base::Time::FromTimeT(statement.ColumnInt64(3)); | 101 info.start_time = base::Time::FromTimeT(statement.ColumnInt64(3)); |
102 info.received_bytes = statement.ColumnInt64(4); | 102 info.received_bytes = statement.ColumnInt64(4); |
103 info.total_bytes = statement.ColumnInt64(5); | 103 info.total_bytes = statement.ColumnInt64(5); |
104 info.state = statement.ColumnInt(6); | 104 info.state = statement.ColumnInt(6); |
105 results->push_back(info); | 105 results->push_back(info); |
106 } | 106 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 bool DownloadDatabase::CleanUpInProgressEntries() { | 138 bool DownloadDatabase::CleanUpInProgressEntries() { |
139 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 139 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
140 "UPDATE downloads SET state=? WHERE state=?")); | 140 "UPDATE downloads SET state=? WHERE state=?")); |
141 if (!statement) | 141 if (!statement) |
142 return false; | 142 return false; |
143 statement.BindInt(0, DownloadItem::CANCELLED); | 143 statement.BindInt(0, DownloadItem::CANCELLED); |
144 statement.BindInt(1, DownloadItem::IN_PROGRESS); | 144 statement.BindInt(1, DownloadItem::IN_PROGRESS); |
145 return statement.Run(); | 145 return statement.Run(); |
146 } | 146 } |
147 | 147 |
148 int64 DownloadDatabase::CreateDownload(const DownloadCreateInfo& info) { | 148 int64 DownloadDatabase::CreateDownload(const DownloadHistoryInfo& info) { |
149 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 149 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
150 "INSERT INTO downloads " | 150 "INSERT INTO downloads " |
151 "(full_path, url, start_time, received_bytes, total_bytes, state) " | 151 "(full_path, url, start_time, received_bytes, total_bytes, state) " |
152 "VALUES (?, ?, ?, ?, ?, ?)")); | 152 "VALUES (?, ?, ?, ?, ?, ?)")); |
153 if (!statement) | 153 if (!statement) |
154 return 0; | 154 return 0; |
155 | 155 |
156 BindFilePath(statement, info.path, 0); | 156 BindFilePath(statement, info.path, 0); |
157 statement.BindString(1, info.url().spec()); | 157 statement.BindString(1, info.url().spec()); |
158 statement.BindInt64(2, info.start_time.ToTimeT()); | 158 statement.BindInt64(2, info.start_time.ToTimeT()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 statement.BindInt64( | 191 statement.BindInt64( |
192 1, | 192 1, |
193 end_time ? end_time : std::numeric_limits<int64>::max()); | 193 end_time ? end_time : std::numeric_limits<int64>::max()); |
194 statement.BindInt(2, DownloadItem::COMPLETE); | 194 statement.BindInt(2, DownloadItem::COMPLETE); |
195 statement.BindInt(3, DownloadItem::CANCELLED); | 195 statement.BindInt(3, DownloadItem::CANCELLED); |
196 statement.BindInt(4, DownloadItem::INTERRUPTED); | 196 statement.BindInt(4, DownloadItem::INTERRUPTED); |
197 statement.Run(); | 197 statement.Run(); |
198 } | 198 } |
199 | 199 |
200 } // namespace history | 200 } // namespace history |
OLD | NEW |