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" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "chrome/browser/download/download_item.h" | 14 #include "chrome/browser/download/download_item.h" |
15 #include "chrome/browser/history/download_create_info.h" | 15 #include "chrome/browser/history/download_history_info.h" |
16 | 16 |
17 // Download schema: | 17 // Download schema: |
18 // | 18 // |
19 // id SQLite-generated primary key. | 19 // id SQLite-generated primary key. |
20 // full_path Location of the download on disk. | 20 // full_path Location of the download on disk. |
21 // url URL of the downloaded file. | 21 // url URL of the downloaded file. |
22 // start_time When the download was started. | 22 // start_time When the download was started. |
23 // received_bytes Total size downloaded. | 23 // received_bytes Total size downloaded. |
24 // total_bytes Total size of the download. | 24 // total_bytes Total size of the download. |
25 // state Identifies if this download is completed or not. Not used | 25 // state Identifies if this download is completed or not. Not used |
(...skipping 48 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 = 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 } |
107 } | 107 } |
108 | 108 |
109 bool DownloadDatabase::UpdateDownload(int64 received_bytes, | 109 bool DownloadDatabase::UpdateDownload(int64 received_bytes, |
110 int32 state, | 110 int32 state, |
(...skipping 27 matching lines...) Expand all 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()); |
159 statement.BindInt64(3, info.received_bytes); | 159 statement.BindInt64(3, info.received_bytes); |
160 statement.BindInt64(4, info.total_bytes); | 160 statement.BindInt64(4, info.total_bytes); |
161 statement.BindInt(5, info.state); | 161 statement.BindInt(5, info.state); |
162 | 162 |
163 if (statement.Run()) | 163 if (statement.Run()) |
164 return GetDB().GetLastInsertRowId(); | 164 return GetDB().GetLastInsertRowId(); |
165 return 0; | 165 return 0; |
166 } | 166 } |
167 | 167 |
(...skipping 23 matching lines...) Expand all 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 |