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 <inttypes.h> | 7 #include <inttypes.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 270 } |
271 | 271 |
272 bool DownloadDatabase::MigrateDownloadSiteInstanceUrl() { | 272 bool DownloadDatabase::MigrateDownloadSiteInstanceUrl() { |
273 return EnsureColumnExists("site_url", "VARCHAR NOT NULL DEFAULT ''"); | 273 return EnsureColumnExists("site_url", "VARCHAR NOT NULL DEFAULT ''"); |
274 } | 274 } |
275 | 275 |
276 bool DownloadDatabase::MigrateDownloadLastAccessTime() { | 276 bool DownloadDatabase::MigrateDownloadLastAccessTime() { |
277 return EnsureColumnExists("last_access_time", "INTEGER NOT NULL DEFAULT 0"); | 277 return EnsureColumnExists("last_access_time", "INTEGER NOT NULL DEFAULT 0"); |
278 } | 278 } |
279 | 279 |
| 280 bool DownloadDatabase::MigrateDownloadTransient() { |
| 281 return EnsureColumnExists("transient", "INTEGER NOT NULL DEFAULT 0"); |
| 282 } |
| 283 |
280 bool DownloadDatabase::InitDownloadTable() { | 284 bool DownloadDatabase::InitDownloadTable() { |
281 const char kSchema[] = | 285 const char kSchema[] = |
282 "CREATE TABLE downloads (" | 286 "CREATE TABLE downloads (" |
283 "id INTEGER PRIMARY KEY," // Primary key. | 287 "id INTEGER PRIMARY KEY," // Primary key. |
284 "guid VARCHAR NOT NULL," // GUID. | 288 "guid VARCHAR NOT NULL," // GUID. |
285 "current_path LONGVARCHAR NOT NULL," // Current disk location | 289 "current_path LONGVARCHAR NOT NULL," // Current disk location |
286 "target_path LONGVARCHAR NOT NULL," // Final disk location | 290 "target_path LONGVARCHAR NOT NULL," // Final disk location |
287 "start_time INTEGER NOT NULL," // When the download was started. | 291 "start_time INTEGER NOT NULL," // When the download was started. |
288 "received_bytes INTEGER NOT NULL," // Total size downloaded. | 292 "received_bytes INTEGER NOT NULL," // Total size downloaded. |
289 "total_bytes INTEGER NOT NULL," // Total size of the download. | 293 "total_bytes INTEGER NOT NULL," // Total size of the download. |
290 "state INTEGER NOT NULL," // 1=complete, 4=interrupted | 294 "state INTEGER NOT NULL," // 1=complete, 4=interrupted |
291 "danger_type INTEGER NOT NULL," // Danger type, validated. | 295 "danger_type INTEGER NOT NULL," // Danger type, validated. |
292 "interrupt_reason INTEGER NOT NULL," // DownloadInterruptReason | 296 "interrupt_reason INTEGER NOT NULL," // DownloadInterruptReason |
293 "hash BLOB NOT NULL," // Raw SHA-256 hash of contents. | 297 "hash BLOB NOT NULL," // Raw SHA-256 hash of contents. |
294 "end_time INTEGER NOT NULL," // When the download completed. | 298 "end_time INTEGER NOT NULL," // When the download completed. |
295 "opened INTEGER NOT NULL," // 1 if it has ever been opened | 299 "opened INTEGER NOT NULL," // 1 if it has ever been opened |
296 // else 0 | 300 // else 0 |
297 "last_access_time INTEGER NOT NULL," // The last time it was accessed. | 301 "last_access_time INTEGER NOT NULL," // The last time it was accessed. |
| 302 "transient INTEGER NOT NULL," // 1 if it is transient, else 0. |
298 "referrer VARCHAR NOT NULL," // HTTP Referrer | 303 "referrer VARCHAR NOT NULL," // HTTP Referrer |
299 "site_url VARCHAR NOT NULL," // Site URL for initiating site | 304 "site_url VARCHAR NOT NULL," // Site URL for initiating site |
300 // instance. | 305 // instance. |
301 "tab_url VARCHAR NOT NULL," // Tab URL for initiator. | 306 "tab_url VARCHAR NOT NULL," // Tab URL for initiator. |
302 "tab_referrer_url VARCHAR NOT NULL," // Tag referrer URL for initiator. | 307 "tab_referrer_url VARCHAR NOT NULL," // Tag referrer URL for initiator. |
303 "http_method VARCHAR NOT NULL," // HTTP method. | 308 "http_method VARCHAR NOT NULL," // HTTP method. |
304 "by_ext_id VARCHAR NOT NULL," // ID of extension that started the | 309 "by_ext_id VARCHAR NOT NULL," // ID of extension that started the |
305 // download | 310 // download |
306 "by_ext_name VARCHAR NOT NULL," // name of extension | 311 "by_ext_name VARCHAR NOT NULL," // name of extension |
307 "etag VARCHAR NOT NULL," // ETag | 312 "etag VARCHAR NOT NULL," // ETag |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 results->clear(); | 384 results->clear(); |
380 std::set<uint32_t> ids; | 385 std::set<uint32_t> ids; |
381 | 386 |
382 DownloadRowMap info_map; | 387 DownloadRowMap info_map; |
383 | 388 |
384 sql::Statement statement_main(GetDB().GetCachedStatement( | 389 sql::Statement statement_main(GetDB().GetCachedStatement( |
385 SQL_FROM_HERE, | 390 SQL_FROM_HERE, |
386 "SELECT id, guid, current_path, target_path, mime_type, " | 391 "SELECT id, guid, current_path, target_path, mime_type, " |
387 "original_mime_type, start_time, received_bytes, total_bytes, state, " | 392 "original_mime_type, start_time, received_bytes, total_bytes, state, " |
388 "danger_type, interrupt_reason, hash, end_time, opened, " | 393 "danger_type, interrupt_reason, hash, end_time, opened, " |
389 "last_access_time, referrer, site_url, tab_url, tab_referrer_url, " | 394 "last_access_time, transient, referrer, site_url, tab_url, " |
390 "http_method, by_ext_id, by_ext_name, etag, last_modified " | 395 "tab_referrer_url, http_method, by_ext_id, by_ext_name, etag, " |
391 "FROM downloads ORDER BY start_time")); | 396 "last_modified FROM downloads ORDER BY start_time")); |
392 | 397 |
393 while (statement_main.Step()) { | 398 while (statement_main.Step()) { |
394 std::unique_ptr<DownloadRow> info(new DownloadRow()); | 399 std::unique_ptr<DownloadRow> info(new DownloadRow()); |
395 int column = 0; | 400 int column = 0; |
396 | 401 |
397 // SQLITE does not have unsigned integers, so explicitly handle negative | 402 // SQLITE does not have unsigned integers, so explicitly handle negative |
398 // |id|s instead of casting them to very large uint32s, which would break | 403 // |id|s instead of casting them to very large uint32s, which would break |
399 // the max(id) logic in GetNextDownloadId(). | 404 // the max(id) logic in GetNextDownloadId(). |
400 int64_t signed_id = statement_main.ColumnInt64(column++); | 405 int64_t signed_id = statement_main.ColumnInt64(column++); |
401 bool valid = ConvertIntToDownloadId(signed_id, &(info->id)); | 406 bool valid = ConvertIntToDownloadId(signed_id, &(info->id)); |
(...skipping 13 matching lines...) Expand all Loading... |
415 info->danger_type = | 420 info->danger_type = |
416 IntToDownloadDangerType(statement_main.ColumnInt(column++)); | 421 IntToDownloadDangerType(statement_main.ColumnInt(column++)); |
417 info->interrupt_reason = | 422 info->interrupt_reason = |
418 IntToDownloadInterruptReason(statement_main.ColumnInt(column++)); | 423 IntToDownloadInterruptReason(statement_main.ColumnInt(column++)); |
419 statement_main.ColumnBlobAsString(column++, &info->hash); | 424 statement_main.ColumnBlobAsString(column++, &info->hash); |
420 info->end_time = | 425 info->end_time = |
421 base::Time::FromInternalValue(statement_main.ColumnInt64(column++)); | 426 base::Time::FromInternalValue(statement_main.ColumnInt64(column++)); |
422 info->opened = statement_main.ColumnInt(column++) != 0; | 427 info->opened = statement_main.ColumnInt(column++) != 0; |
423 info->last_access_time = | 428 info->last_access_time = |
424 base::Time::FromInternalValue(statement_main.ColumnInt64(column++)); | 429 base::Time::FromInternalValue(statement_main.ColumnInt64(column++)); |
| 430 info->transient = statement_main.ColumnInt(column++) != 0; |
425 info->referrer_url = GURL(statement_main.ColumnString(column++)); | 431 info->referrer_url = GURL(statement_main.ColumnString(column++)); |
426 info->site_url = GURL(statement_main.ColumnString(column++)); | 432 info->site_url = GURL(statement_main.ColumnString(column++)); |
427 info->tab_url = GURL(statement_main.ColumnString(column++)); | 433 info->tab_url = GURL(statement_main.ColumnString(column++)); |
428 info->tab_referrer_url = GURL(statement_main.ColumnString(column++)); | 434 info->tab_referrer_url = GURL(statement_main.ColumnString(column++)); |
429 info->http_method = statement_main.ColumnString(column++); | 435 info->http_method = statement_main.ColumnString(column++); |
430 info->by_ext_id = statement_main.ColumnString(column++); | 436 info->by_ext_id = statement_main.ColumnString(column++); |
431 info->by_ext_name = statement_main.ColumnString(column++); | 437 info->by_ext_name = statement_main.ColumnString(column++); |
432 info->etag = statement_main.ColumnString(column++); | 438 info->etag = statement_main.ColumnString(column++); |
433 info->last_modified = statement_main.ColumnString(column++); | 439 info->last_modified = statement_main.ColumnString(column++); |
434 | 440 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 return false; | 538 return false; |
533 } | 539 } |
534 | 540 |
535 sql::Statement statement(GetDB().GetCachedStatement( | 541 sql::Statement statement(GetDB().GetCachedStatement( |
536 SQL_FROM_HERE, | 542 SQL_FROM_HERE, |
537 "UPDATE downloads " | 543 "UPDATE downloads " |
538 "SET current_path=?, target_path=?, " | 544 "SET current_path=?, target_path=?, " |
539 "mime_type=?, original_mime_type=?, " | 545 "mime_type=?, original_mime_type=?, " |
540 "received_bytes=?, state=?, " | 546 "received_bytes=?, state=?, " |
541 "danger_type=?, interrupt_reason=?, hash=?, end_time=?, total_bytes=?, " | 547 "danger_type=?, interrupt_reason=?, hash=?, end_time=?, total_bytes=?, " |
542 "opened=?, last_access_time=?, by_ext_id=?, by_ext_name=?, etag=?, " | 548 "opened=?, last_access_time=?, transient=?, by_ext_id=?, by_ext_name=?, " |
543 "last_modified=? WHERE id=?")); | 549 "etag=?, last_modified=? WHERE id=?")); |
544 int column = 0; | 550 int column = 0; |
545 BindFilePath(statement, data.current_path, column++); | 551 BindFilePath(statement, data.current_path, column++); |
546 BindFilePath(statement, data.target_path, column++); | 552 BindFilePath(statement, data.target_path, column++); |
547 statement.BindString(column++, data.mime_type); | 553 statement.BindString(column++, data.mime_type); |
548 statement.BindString(column++, data.original_mime_type); | 554 statement.BindString(column++, data.original_mime_type); |
549 statement.BindInt64(column++, data.received_bytes); | 555 statement.BindInt64(column++, data.received_bytes); |
550 statement.BindInt(column++, DownloadStateToInt(data.state)); | 556 statement.BindInt(column++, DownloadStateToInt(data.state)); |
551 statement.BindInt(column++, DownloadDangerTypeToInt(data.danger_type)); | 557 statement.BindInt(column++, DownloadDangerTypeToInt(data.danger_type)); |
552 statement.BindInt(column++, | 558 statement.BindInt(column++, |
553 DownloadInterruptReasonToInt(data.interrupt_reason)); | 559 DownloadInterruptReasonToInt(data.interrupt_reason)); |
554 statement.BindBlob(column++, data.hash.data(), data.hash.size()); | 560 statement.BindBlob(column++, data.hash.data(), data.hash.size()); |
555 statement.BindInt64(column++, data.end_time.ToInternalValue()); | 561 statement.BindInt64(column++, data.end_time.ToInternalValue()); |
556 statement.BindInt64(column++, data.total_bytes); | 562 statement.BindInt64(column++, data.total_bytes); |
557 statement.BindInt(column++, (data.opened ? 1 : 0)); | 563 statement.BindInt(column++, (data.opened ? 1 : 0)); |
558 statement.BindInt64(column++, data.last_access_time.ToInternalValue()); | 564 statement.BindInt64(column++, data.last_access_time.ToInternalValue()); |
| 565 statement.BindInt(column++, (data.transient ? 1 : 0)); |
559 statement.BindString(column++, data.by_ext_id); | 566 statement.BindString(column++, data.by_ext_id); |
560 statement.BindString(column++, data.by_ext_name); | 567 statement.BindString(column++, data.by_ext_name); |
561 statement.BindString(column++, data.etag); | 568 statement.BindString(column++, data.etag); |
562 statement.BindString(column++, data.last_modified); | 569 statement.BindString(column++, data.last_modified); |
563 statement.BindInt(column++, DownloadIdToInt(data.id)); | 570 statement.BindInt(column++, DownloadIdToInt(data.id)); |
564 | 571 |
565 if (!statement.Run()) | 572 if (!statement.Run()) |
566 return false; | 573 return false; |
567 | 574 |
568 if (data.download_slice_info.size() == 0) { | 575 if (data.download_slice_info.size() == 0) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 if (info.danger_type == DownloadDangerType::INVALID) | 614 if (info.danger_type == DownloadDangerType::INVALID) |
608 return false; | 615 return false; |
609 | 616 |
610 { | 617 { |
611 sql::Statement statement_insert(GetDB().GetCachedStatement( | 618 sql::Statement statement_insert(GetDB().GetCachedStatement( |
612 SQL_FROM_HERE, | 619 SQL_FROM_HERE, |
613 "INSERT INTO downloads " | 620 "INSERT INTO downloads " |
614 "(id, guid, current_path, target_path, mime_type, original_mime_type, " | 621 "(id, guid, current_path, target_path, mime_type, original_mime_type, " |
615 " start_time, received_bytes, total_bytes, state, danger_type, " | 622 " start_time, received_bytes, total_bytes, state, danger_type, " |
616 " interrupt_reason, hash, end_time, opened, last_access_time, " | 623 " interrupt_reason, hash, end_time, opened, last_access_time, " |
617 " referrer, site_url, tab_url, tab_referrer_url, http_method, " | 624 "transient, referrer, site_url, tab_url, tab_referrer_url, " |
| 625 "http_method, " |
618 " by_ext_id, by_ext_name, etag, last_modified) " | 626 " by_ext_id, by_ext_name, etag, last_modified) " |
619 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " | 627 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " |
620 " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " | 628 " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " |
621 " ?, ?, ?, ?, ?)")); | 629 " ?, ?, ?, ?, ?, ?)")); |
622 | 630 |
623 int column = 0; | 631 int column = 0; |
624 statement_insert.BindInt(column++, DownloadIdToInt(info.id)); | 632 statement_insert.BindInt(column++, DownloadIdToInt(info.id)); |
625 statement_insert.BindString(column++, info.guid); | 633 statement_insert.BindString(column++, info.guid); |
626 BindFilePath(statement_insert, info.current_path, column++); | 634 BindFilePath(statement_insert, info.current_path, column++); |
627 BindFilePath(statement_insert, info.target_path, column++); | 635 BindFilePath(statement_insert, info.target_path, column++); |
628 statement_insert.BindString(column++, info.mime_type); | 636 statement_insert.BindString(column++, info.mime_type); |
629 statement_insert.BindString(column++, info.original_mime_type); | 637 statement_insert.BindString(column++, info.original_mime_type); |
630 statement_insert.BindInt64(column++, info.start_time.ToInternalValue()); | 638 statement_insert.BindInt64(column++, info.start_time.ToInternalValue()); |
631 statement_insert.BindInt64(column++, info.received_bytes); | 639 statement_insert.BindInt64(column++, info.received_bytes); |
632 statement_insert.BindInt64(column++, info.total_bytes); | 640 statement_insert.BindInt64(column++, info.total_bytes); |
633 statement_insert.BindInt(column++, DownloadStateToInt(info.state)); | 641 statement_insert.BindInt(column++, DownloadStateToInt(info.state)); |
634 statement_insert.BindInt(column++, | 642 statement_insert.BindInt(column++, |
635 DownloadDangerTypeToInt(info.danger_type)); | 643 DownloadDangerTypeToInt(info.danger_type)); |
636 statement_insert.BindInt( | 644 statement_insert.BindInt( |
637 column++, DownloadInterruptReasonToInt(info.interrupt_reason)); | 645 column++, DownloadInterruptReasonToInt(info.interrupt_reason)); |
638 statement_insert.BindBlob(column++, info.hash.data(), info.hash.size()); | 646 statement_insert.BindBlob(column++, info.hash.data(), info.hash.size()); |
639 statement_insert.BindInt64(column++, info.end_time.ToInternalValue()); | 647 statement_insert.BindInt64(column++, info.end_time.ToInternalValue()); |
640 statement_insert.BindInt(column++, info.opened ? 1 : 0); | 648 statement_insert.BindInt(column++, info.opened ? 1 : 0); |
641 statement_insert.BindInt64(column++, | 649 statement_insert.BindInt64(column++, |
642 info.last_access_time.ToInternalValue()); | 650 info.last_access_time.ToInternalValue()); |
| 651 statement_insert.BindInt(column++, info.transient ? 1 : 0); |
643 statement_insert.BindString(column++, info.referrer_url.spec()); | 652 statement_insert.BindString(column++, info.referrer_url.spec()); |
644 statement_insert.BindString(column++, info.site_url.spec()); | 653 statement_insert.BindString(column++, info.site_url.spec()); |
645 statement_insert.BindString(column++, info.tab_url.spec()); | 654 statement_insert.BindString(column++, info.tab_url.spec()); |
646 statement_insert.BindString(column++, info.tab_referrer_url.spec()); | 655 statement_insert.BindString(column++, info.tab_referrer_url.spec()); |
647 statement_insert.BindString(column++, info.http_method); | 656 statement_insert.BindString(column++, info.http_method); |
648 statement_insert.BindString(column++, info.by_ext_id); | 657 statement_insert.BindString(column++, info.by_ext_id); |
649 statement_insert.BindString(column++, info.by_ext_name); | 658 statement_insert.BindString(column++, info.by_ext_name); |
650 statement_insert.BindString(column++, info.etag); | 659 statement_insert.BindString(column++, info.etag); |
651 statement_insert.BindString(column++, info.last_modified); | 660 statement_insert.BindString(column++, info.last_modified); |
652 if (!statement_insert.Run()) { | 661 if (!statement_insert.Run()) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 "Download.DatabaseDownloadExistsForDownloadSlice", found); | 800 "Download.DatabaseDownloadExistsForDownloadSlice", found); |
792 if (!found) { | 801 if (!found) { |
793 RemoveDownloadSlices(info.download_id); | 802 RemoveDownloadSlices(info.download_id); |
794 continue; | 803 continue; |
795 } | 804 } |
796 it->second->download_slice_info.push_back(info); | 805 it->second->download_slice_info.push_back(info); |
797 } | 806 } |
798 } | 807 } |
799 | 808 |
800 } // namespace history | 809 } // namespace history |
OLD | NEW |