| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } else if (info->state == DownloadState::INVALID) { | 418 } else if (info->state == DownloadState::INVALID) { |
| 419 dropped_reason = DROPPED_REASON_BAD_STATE; | 419 dropped_reason = DROPPED_REASON_BAD_STATE; |
| 420 } else if (info->danger_type == DownloadDangerType::INVALID) { | 420 } else if (info->danger_type == DownloadDangerType::INVALID) { |
| 421 dropped_reason = DROPPED_REASON_BAD_DANGER_TYPE; | 421 dropped_reason = DROPPED_REASON_BAD_DANGER_TYPE; |
| 422 } | 422 } |
| 423 if (dropped_reason != DROPPED_REASON_MAX) { | 423 if (dropped_reason != DROPPED_REASON_MAX) { |
| 424 UMA_HISTOGRAM_ENUMERATION("Download.DatabaseRecordDropped", | 424 UMA_HISTOGRAM_ENUMERATION("Download.DatabaseRecordDropped", |
| 425 dropped_reason, | 425 dropped_reason, |
| 426 DROPPED_REASON_MAX + 1); | 426 DROPPED_REASON_MAX + 1); |
| 427 } else { | 427 } else { |
| 428 DCHECK(!ContainsKey(info_map, info->id)); | 428 DCHECK(!base::ContainsKey(info_map, info->id)); |
| 429 uint32_t id = info->id; | 429 uint32_t id = info->id; |
| 430 info_map[id] = info.release(); | 430 info_map[id] = info.release(); |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 | 433 |
| 434 sql::Statement statement_chain(GetDB().GetCachedStatement( | 434 sql::Statement statement_chain(GetDB().GetCachedStatement( |
| 435 SQL_FROM_HERE, | 435 SQL_FROM_HERE, |
| 436 "SELECT id, chain_index, url FROM downloads_url_chains " | 436 "SELECT id, chain_index, url FROM downloads_url_chains " |
| 437 "ORDER BY id, chain_index")); | 437 "ORDER BY id, chain_index")); |
| 438 | 438 |
| 439 while (statement_chain.Step()) { | 439 while (statement_chain.Step()) { |
| 440 int column = 0; | 440 int column = 0; |
| 441 // See the comment above about SQLITE lacking unsigned integers. | 441 // See the comment above about SQLITE lacking unsigned integers. |
| 442 int64_t signed_id = statement_chain.ColumnInt64(column++); | 442 int64_t signed_id = statement_chain.ColumnInt64(column++); |
| 443 int chain_index = statement_chain.ColumnInt(column++); | 443 int chain_index = statement_chain.ColumnInt(column++); |
| 444 | 444 |
| 445 if (signed_id <= static_cast<int64_t>(kInvalidDownloadId)) | 445 if (signed_id <= static_cast<int64_t>(kInvalidDownloadId)) |
| 446 continue; | 446 continue; |
| 447 uint32_t id = IntToDownloadId(signed_id); | 447 uint32_t id = IntToDownloadId(signed_id); |
| 448 | 448 |
| 449 // Note that these DCHECKs may trip as a result of corrupted databases. | 449 // Note that these DCHECKs may trip as a result of corrupted databases. |
| 450 // We have them because in debug builds the chances are higher there's | 450 // We have them because in debug builds the chances are higher there's |
| 451 // an actual bug than that the database is corrupt, but we handle the | 451 // an actual bug than that the database is corrupt, but we handle the |
| 452 // DB corruption case in production code. | 452 // DB corruption case in production code. |
| 453 | 453 |
| 454 // Confirm the id has already been seen--if it hasn't, discard the | 454 // Confirm the id has already been seen--if it hasn't, discard the |
| 455 // record. | 455 // record. |
| 456 DCHECK(ContainsKey(info_map, id)); | 456 DCHECK(base::ContainsKey(info_map, id)); |
| 457 if (!ContainsKey(info_map, id)) | 457 if (!base::ContainsKey(info_map, id)) |
| 458 continue; | 458 continue; |
| 459 | 459 |
| 460 // Confirm all previous URLs in the chain have already been seen; | 460 // Confirm all previous URLs in the chain have already been seen; |
| 461 // if not, fill in with null or discard record. | 461 // if not, fill in with null or discard record. |
| 462 int current_chain_size = static_cast<int>(info_map[id]->url_chain.size()); | 462 int current_chain_size = static_cast<int>(info_map[id]->url_chain.size()); |
| 463 std::vector<GURL>* url_chain(&info_map[id]->url_chain); | 463 std::vector<GURL>* url_chain(&info_map[id]->url_chain); |
| 464 DCHECK_EQ(chain_index, current_chain_size); | 464 DCHECK_EQ(chain_index, current_chain_size); |
| 465 while (current_chain_size < chain_index) { | 465 while (current_chain_size < chain_index) { |
| 466 url_chain->push_back(GURL()); | 466 url_chain->push_back(GURL()); |
| 467 current_chain_size++; | 467 current_chain_size++; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 size_t DownloadDatabase::CountDownloads() { | 681 size_t DownloadDatabase::CountDownloads() { |
| 682 EnsureInProgressEntriesCleanedUp(); | 682 EnsureInProgressEntriesCleanedUp(); |
| 683 | 683 |
| 684 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 684 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 685 "SELECT count(*) from downloads")); | 685 "SELECT count(*) from downloads")); |
| 686 statement.Step(); | 686 statement.Step(); |
| 687 return statement.ColumnInt(0); | 687 return statement.ColumnInt(0); |
| 688 } | 688 } |
| 689 | 689 |
| 690 } // namespace history | 690 } // namespace history |
| OLD | NEW |