| 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/thumbnail_database.h" | 5 #include "components/history/core/browser/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" |
| 11 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
| 12 #include "base/debug/dump_without_crashing.h" | 12 #include "base/debug/dump_without_crashing.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
| 15 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "components/history/core/browser/history_client.h" | 21 #include "components/history/core/browser/history_backend_client.h" |
| 22 #include "components/history/core/browser/url_database.h" | 22 #include "components/history/core/browser/url_database.h" |
| 23 #include "sql/recovery.h" | 23 #include "sql/recovery.h" |
| 24 #include "sql/statement.h" | 24 #include "sql/statement.h" |
| 25 #include "sql/transaction.h" | 25 #include "sql/transaction.h" |
| 26 #include "third_party/sqlite/sqlite3.h" | 26 #include "third_party/sqlite/sqlite3.h" |
| 27 | 27 |
| 28 #if defined(OS_MACOSX) && !defined(OS_IOS) | 28 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 29 #include "base/mac/mac_util.h" | 29 #include "base/mac/mac_util.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 static_cast<int>(favicon_bitmaps_rows_recovered)); | 543 static_cast<int>(favicon_bitmaps_rows_recovered)); |
| 544 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsIconMapping", | 544 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsIconMapping", |
| 545 static_cast<int>(icon_mapping_rows_recovered)); | 545 static_cast<int>(icon_mapping_rows_recovered)); |
| 546 | 546 |
| 547 RecordRecoveryEvent(RECOVERY_EVENT_RECOVERED); | 547 RecordRecoveryEvent(RECOVERY_EVENT_RECOVERED); |
| 548 } | 548 } |
| 549 | 549 |
| 550 void DatabaseErrorCallback(sql::Connection* db, | 550 void DatabaseErrorCallback(sql::Connection* db, |
| 551 const base::FilePath& db_path, | 551 const base::FilePath& db_path, |
| 552 size_t startup_kb, | 552 size_t startup_kb, |
| 553 HistoryClient* history_client, | 553 HistoryBackendClient* backend_client, |
| 554 int extended_error, | 554 int extended_error, |
| 555 sql::Statement* stmt) { | 555 sql::Statement* stmt) { |
| 556 // TODO(shess): Assert that this is running on a safe thread. | 556 // TODO(shess): Assert that this is running on a safe thread. |
| 557 // AFAICT, should be the history thread, but at this level I can't | 557 // AFAICT, should be the history thread, but at this level I can't |
| 558 // see how to reach that. | 558 // see how to reach that. |
| 559 | 559 |
| 560 if (history_client && history_client->ShouldReportDatabaseError()) { | 560 if (backend_client && backend_client->ShouldReportDatabaseError()) { |
| 561 GenerateDiagnostics(db, startup_kb, extended_error); | 561 GenerateDiagnostics(db, startup_kb, extended_error); |
| 562 } | 562 } |
| 563 | 563 |
| 564 // Attempt to recover corrupt databases. | 564 // Attempt to recover corrupt databases. |
| 565 int error = (extended_error & 0xFF); | 565 int error = (extended_error & 0xFF); |
| 566 if (error == SQLITE_CORRUPT || | 566 if (error == SQLITE_CORRUPT || |
| 567 error == SQLITE_CANTOPEN || | 567 error == SQLITE_CANTOPEN || |
| 568 error == SQLITE_NOTADB) { | 568 error == SQLITE_NOTADB) { |
| 569 RecoverDatabaseOrRaze(db, db_path); | 569 RecoverDatabaseOrRaze(db, db_path); |
| 570 } | 570 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 583 } | 583 } |
| 584 | 584 |
| 585 bool ThumbnailDatabase::IconMappingEnumerator::GetNextIconMapping( | 585 bool ThumbnailDatabase::IconMappingEnumerator::GetNextIconMapping( |
| 586 IconMapping* icon_mapping) { | 586 IconMapping* icon_mapping) { |
| 587 if (!statement_.Step()) | 587 if (!statement_.Step()) |
| 588 return false; | 588 return false; |
| 589 FillIconMapping(statement_, GURL(statement_.ColumnString(4)), icon_mapping); | 589 FillIconMapping(statement_, GURL(statement_.ColumnString(4)), icon_mapping); |
| 590 return true; | 590 return true; |
| 591 } | 591 } |
| 592 | 592 |
| 593 ThumbnailDatabase::ThumbnailDatabase(HistoryClient* history_client) | 593 ThumbnailDatabase::ThumbnailDatabase(HistoryBackendClient* backend_client) |
| 594 : history_client_(history_client) { | 594 : backend_client_(backend_client) { |
| 595 } | 595 } |
| 596 | 596 |
| 597 ThumbnailDatabase::~ThumbnailDatabase() { | 597 ThumbnailDatabase::~ThumbnailDatabase() { |
| 598 // The DBCloseScoper will delete the DB and the cache. | 598 // The DBCloseScoper will delete the DB and the cache. |
| 599 } | 599 } |
| 600 | 600 |
| 601 sql::InitStatus ThumbnailDatabase::Init(const base::FilePath& db_name) { | 601 sql::InitStatus ThumbnailDatabase::Init(const base::FilePath& db_name) { |
| 602 // TODO(shess): Consider separating database open from schema setup. | 602 // TODO(shess): Consider separating database open from schema setup. |
| 603 // With that change, this code could Raze() from outside the | 603 // With that change, this code could Raze() from outside the |
| 604 // transaction, rather than needing RazeAndClose() in InitImpl(). | 604 // transaction, rather than needing RazeAndClose() in InitImpl(). |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 | 1205 |
| 1206 sql::InitStatus ThumbnailDatabase::OpenDatabase(sql::Connection* db, | 1206 sql::InitStatus ThumbnailDatabase::OpenDatabase(sql::Connection* db, |
| 1207 const base::FilePath& db_name) { | 1207 const base::FilePath& db_name) { |
| 1208 size_t startup_kb = 0; | 1208 size_t startup_kb = 0; |
| 1209 int64 size_64; | 1209 int64 size_64; |
| 1210 if (base::GetFileSize(db_name, &size_64)) | 1210 if (base::GetFileSize(db_name, &size_64)) |
| 1211 startup_kb = static_cast<size_t>(size_64 / 1024); | 1211 startup_kb = static_cast<size_t>(size_64 / 1024); |
| 1212 | 1212 |
| 1213 db->set_histogram_tag("Thumbnail"); | 1213 db->set_histogram_tag("Thumbnail"); |
| 1214 db->set_error_callback(base::Bind(&DatabaseErrorCallback, | 1214 db->set_error_callback(base::Bind(&DatabaseErrorCallback, |
| 1215 db, db_name, startup_kb, history_client_)); | 1215 db, db_name, startup_kb, backend_client_)); |
| 1216 | 1216 |
| 1217 // Thumbnails db now only stores favicons, so we don't need that big a page | 1217 // Thumbnails db now only stores favicons, so we don't need that big a page |
| 1218 // size or cache. | 1218 // size or cache. |
| 1219 db->set_page_size(2048); | 1219 db->set_page_size(2048); |
| 1220 db->set_cache_size(32); | 1220 db->set_cache_size(32); |
| 1221 | 1221 |
| 1222 // Run the database in exclusive mode. Nobody else should be accessing the | 1222 // Run the database in exclusive mode. Nobody else should be accessing the |
| 1223 // database while we're running, and this will give somewhat improved perf. | 1223 // database while we're running, and this will give somewhat improved perf. |
| 1224 db->set_exclusive_locking(); | 1224 db->set_exclusive_locking(); |
| 1225 | 1225 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 meta_table_.SetVersionNumber(8); | 1378 meta_table_.SetVersionNumber(8); |
| 1379 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); | 1379 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); |
| 1380 return true; | 1380 return true; |
| 1381 } | 1381 } |
| 1382 | 1382 |
| 1383 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { | 1383 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { |
| 1384 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); | 1384 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); |
| 1385 } | 1385 } |
| 1386 | 1386 |
| 1387 } // namespace history | 1387 } // namespace history |
| OLD | NEW |