| 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 "chrome/browser/history/thumbnail_database.h" | 5 #include "chrome/browser/history/thumbnail_database.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 DCHECK_EQ(7, kCurrentVersionNumber); | 445 DCHECK_EQ(7, kCurrentVersionNumber); |
| 446 | 446 |
| 447 // TODO(shess): Reset back after? | 447 // TODO(shess): Reset back after? |
| 448 db->reset_error_callback(); | 448 db->reset_error_callback(); |
| 449 | 449 |
| 450 // For histogram purposes. | 450 // For histogram purposes. |
| 451 size_t favicons_rows_recovered = 0; | 451 size_t favicons_rows_recovered = 0; |
| 452 size_t favicon_bitmaps_rows_recovered = 0; | 452 size_t favicon_bitmaps_rows_recovered = 0; |
| 453 size_t icon_mapping_rows_recovered = 0; | 453 size_t icon_mapping_rows_recovered = 0; |
| 454 int64 original_size = 0; | 454 int64 original_size = 0; |
| 455 file_util::GetFileSize(db_path, &original_size); | 455 base::GetFileSize(db_path, &original_size); |
| 456 | 456 |
| 457 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(db, db_path); | 457 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(db, db_path); |
| 458 if (!recovery) { | 458 if (!recovery) { |
| 459 // TODO(shess): Unable to create recovery connection. This | 459 // TODO(shess): Unable to create recovery connection. This |
| 460 // implies something substantial is wrong. At this point |db| has | 460 // implies something substantial is wrong. At this point |db| has |
| 461 // been poisoned so there is nothing really to do. | 461 // been poisoned so there is nothing really to do. |
| 462 // | 462 // |
| 463 // Possible responses are unclear. If the failure relates to a | 463 // Possible responses are unclear. If the failure relates to a |
| 464 // problem somehow specific to the temporary file used to back the | 464 // problem somehow specific to the temporary file used to back the |
| 465 // database, then an in-memory database could possibly be used. | 465 // database, then an in-memory database could possibly be used. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 517 |
| 518 // TODO(shess): Could this code be shared with the v6/7 code | 518 // TODO(shess): Could this code be shared with the v6/7 code |
| 519 // without requiring too much state to be carried? | 519 // without requiring too much state to be carried? |
| 520 | 520 |
| 521 // Track the size of the recovered database relative to the size of | 521 // Track the size of the recovered database relative to the size of |
| 522 // the input database. The size should almost always be smaller, | 522 // the input database. The size should almost always be smaller, |
| 523 // unless the input database was empty to start with. If the | 523 // unless the input database was empty to start with. If the |
| 524 // percentage results are very low, something is awry. | 524 // percentage results are very low, something is awry. |
| 525 int64 final_size = 0; | 525 int64 final_size = 0; |
| 526 if (original_size > 0 && | 526 if (original_size > 0 && |
| 527 file_util::GetFileSize(db_path, &final_size) && | 527 base::GetFileSize(db_path, &final_size) && |
| 528 final_size > 0) { | 528 final_size > 0) { |
| 529 int percentage = static_cast<int>(original_size * 100 / final_size); | 529 int percentage = static_cast<int>(original_size * 100 / final_size); |
| 530 UMA_HISTOGRAM_PERCENTAGE("History.FaviconsRecoveredPercentage", | 530 UMA_HISTOGRAM_PERCENTAGE("History.FaviconsRecoveredPercentage", |
| 531 std::max(100, percentage)); | 531 std::max(100, percentage)); |
| 532 } | 532 } |
| 533 | 533 |
| 534 // Using 10,000 because these cases mostly care about "none | 534 // Using 10,000 because these cases mostly care about "none |
| 535 // recovered" and "lots recovered". More than 10,000 rows recovered | 535 // recovered" and "lots recovered". More than 10,000 rows recovered |
| 536 // probably means there's something wrong with the profile. | 536 // probably means there's something wrong with the profile. |
| 537 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsFavicons", | 537 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsFavicons", |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_COMMIT); | 620 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_COMMIT); |
| 621 return; | 621 return; |
| 622 } | 622 } |
| 623 | 623 |
| 624 // Track the size of the recovered database relative to the size of | 624 // Track the size of the recovered database relative to the size of |
| 625 // the input database. The size should almost always be smaller, | 625 // the input database. The size should almost always be smaller, |
| 626 // unless the input database was empty to start with. If the | 626 // unless the input database was empty to start with. If the |
| 627 // percentage results are very low, something is awry. | 627 // percentage results are very low, something is awry. |
| 628 int64 final_size = 0; | 628 int64 final_size = 0; |
| 629 if (original_size > 0 && | 629 if (original_size > 0 && |
| 630 file_util::GetFileSize(db_path, &final_size) && | 630 base::GetFileSize(db_path, &final_size) && |
| 631 final_size > 0) { | 631 final_size > 0) { |
| 632 int percentage = static_cast<int>(original_size * 100 / final_size); | 632 int percentage = static_cast<int>(original_size * 100 / final_size); |
| 633 UMA_HISTOGRAM_PERCENTAGE("History.FaviconsRecoveredPercentage", | 633 UMA_HISTOGRAM_PERCENTAGE("History.FaviconsRecoveredPercentage", |
| 634 std::max(100, percentage)); | 634 std::max(100, percentage)); |
| 635 } | 635 } |
| 636 | 636 |
| 637 // Using 10,000 because these cases mostly care about "none | 637 // Using 10,000 because these cases mostly care about "none |
| 638 // recovered" and "lots recovered". More than 10,000 rows recovered | 638 // recovered" and "lots recovered". More than 10,000 rows recovered |
| 639 // probably means there's something wrong with the profile. | 639 // probably means there's something wrong with the profile. |
| 640 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsFavicons", | 640 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsFavicons", |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 if (!db_.Execute(kIconMappingDrop)) | 1234 if (!db_.Execute(kIconMappingDrop)) |
| 1235 return false; | 1235 return false; |
| 1236 | 1236 |
| 1237 return transaction.Commit(); | 1237 return transaction.Commit(); |
| 1238 } | 1238 } |
| 1239 | 1239 |
| 1240 sql::InitStatus ThumbnailDatabase::OpenDatabase(sql::Connection* db, | 1240 sql::InitStatus ThumbnailDatabase::OpenDatabase(sql::Connection* db, |
| 1241 const base::FilePath& db_name) { | 1241 const base::FilePath& db_name) { |
| 1242 size_t startup_kb = 0; | 1242 size_t startup_kb = 0; |
| 1243 int64 size_64; | 1243 int64 size_64; |
| 1244 if (file_util::GetFileSize(db_name, &size_64)) | 1244 if (base::GetFileSize(db_name, &size_64)) |
| 1245 startup_kb = static_cast<size_t>(size_64 / 1024); | 1245 startup_kb = static_cast<size_t>(size_64 / 1024); |
| 1246 | 1246 |
| 1247 db->set_histogram_tag("Thumbnail"); | 1247 db->set_histogram_tag("Thumbnail"); |
| 1248 db->set_error_callback(base::Bind(&DatabaseErrorCallback, | 1248 db->set_error_callback(base::Bind(&DatabaseErrorCallback, |
| 1249 db, db_name, startup_kb)); | 1249 db, db_name, startup_kb)); |
| 1250 | 1250 |
| 1251 // Thumbnails db now only stores favicons, so we don't need that big a page | 1251 // Thumbnails db now only stores favicons, so we don't need that big a page |
| 1252 // size or cache. | 1252 // size or cache. |
| 1253 db->set_page_size(2048); | 1253 db->set_page_size(2048); |
| 1254 db->set_cache_size(32); | 1254 db->set_cache_size(32); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 meta_table_.SetVersionNumber(7); | 1427 meta_table_.SetVersionNumber(7); |
| 1428 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); | 1428 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); |
| 1429 return true; | 1429 return true; |
| 1430 } | 1430 } |
| 1431 | 1431 |
| 1432 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { | 1432 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { |
| 1433 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); | 1433 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); |
| 1434 } | 1434 } |
| 1435 | 1435 |
| 1436 } // namespace history | 1436 } // namespace history |
| OLD | NEW |