OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/history/core/browser/download_database.h" | 5 #include "components/history/core/browser/download_database.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 // assumes that the likelihood of a collision with a GUID generated via | 232 // assumes that the likelihood of a collision with a GUID generated via |
233 // base::GenerateGUID() will be vanishingly small. | 233 // base::GenerateGUID() will be vanishingly small. |
234 // | 234 // |
235 // A previous version of this code generated GUIDs that used random bits for | 235 // A previous version of this code generated GUIDs that used random bits for |
236 // all but the first 32-bits. I.e. the scheme didn't respect the 6 fixed bits | 236 // all but the first 32-bits. I.e. the scheme didn't respect the 6 fixed bits |
237 // as prescribed for type 4 GUIDs. The resulting GUIDs are not believed to | 237 // as prescribed for type 4 GUIDs. The resulting GUIDs are not believed to |
238 // have an elevated risk of collision with GUIDs generated via | 238 // have an elevated risk of collision with GUIDs generated via |
239 // base::GenerateGUID() and are considered valid by all known consumers. Hence | 239 // base::GenerateGUID() and are considered valid by all known consumers. Hence |
240 // no additional migration logic is being introduced to fix those GUIDs. | 240 // no additional migration logic is being introduced to fix those GUIDs. |
241 const char kMigrateGuidsQuery[] = | 241 const char kMigrateGuidsQuery[] = |
242 "UPDATE downloads SET guid = printf" | 242 "UPDATE downloads SET guid = " |
243 "(\"%08X-%s-4%s-%01X%s-%s\"," | 243 "substr(hex(char( id>>28) ),2) || substr(hex(char((id>>24)&15)),2) || " |
Scott Hess - ex-Googler
2016/04/21 02:32:55
Since SQLite integers are 64-bit, I'd throw in the
| |
244 " id," | 244 "substr(hex(char((id>>20)&15)),2) || substr(hex(char((id>>16)&15)),2) || " |
245 " hex(randomblob(2))," | 245 "substr(hex(char((id>>12)&15)),2) || substr(hex(char((id>> 8)&15)),2) || " |
246 " substr(hex(randomblob(2)),2)," | 246 "substr(hex(char((id>> 4)&15)),2) || substr(hex(char( id &15)),2) || " |
247 " (8 | (random() & 3))," | 247 "'-' || hex(randomblob(2)) || " |
248 " substr(hex(randomblob(2)),2)," | 248 "'-4' || substr(hex(randomblob(2)),2) || " |
249 " hex(randomblob(6)))"; | 249 "'-' || substr('89AB',1+(random()&3),1) || " |
250 " substr(hex(randomblob(2)),2) || " | |
251 "'-' || hex(randomblob(6))"; | |
Scott Hess - ex-Googler
2016/04/21 02:32:55
Wow. I assume you have golden tests for this so y
| |
250 return GetDB().Execute(kMigrateGuidsQuery); | 252 return GetDB().Execute(kMigrateGuidsQuery); |
251 } | 253 } |
252 | 254 |
253 bool DownloadDatabase::MigrateDownloadTabUrl() { | 255 bool DownloadDatabase::MigrateDownloadTabUrl() { |
254 return EnsureColumnExists("tab_url", "VARCHAR NOT NULL DEFAULT ''") && | 256 return EnsureColumnExists("tab_url", "VARCHAR NOT NULL DEFAULT ''") && |
255 EnsureColumnExists("tab_referrer_url", "VARCHAR NOT NULL DEFAULT ''"); | 257 EnsureColumnExists("tab_referrer_url", "VARCHAR NOT NULL DEFAULT ''"); |
256 } | 258 } |
257 | 259 |
258 bool DownloadDatabase::InitDownloadTable() { | 260 bool DownloadDatabase::InitDownloadTable() { |
259 const char kSchema[] = | 261 const char kSchema[] = |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 size_t DownloadDatabase::CountDownloads() { | 662 size_t DownloadDatabase::CountDownloads() { |
661 EnsureInProgressEntriesCleanedUp(); | 663 EnsureInProgressEntriesCleanedUp(); |
662 | 664 |
663 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 665 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
664 "SELECT count(*) from downloads")); | 666 "SELECT count(*) from downloads")); |
665 statement.Step(); | 667 statement.Step(); |
666 return statement.ColumnInt(0); | 668 return statement.ColumnInt(0); |
667 } | 669 } |
668 | 670 |
669 } // namespace history | 671 } // namespace history |
OLD | NEW |