| 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 <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include <algorithm> | 10 #include <algorithm> |
| 8 #include <string> | 11 #include <string> |
| 9 | 12 |
| 10 #include "base/bind.h" | 13 #include "base/bind.h" |
| 11 #include "base/debug/alias.h" | 14 #include "base/debug/alias.h" |
| 12 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 13 #include "base/memory/ref_counted_memory.h" | 16 #include "base/memory/ref_counted_memory.h" |
| 14 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 16 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 18 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "build/build_config.h" |
| 19 #include "components/history/core/browser/history_backend_client.h" | 23 #include "components/history/core/browser/history_backend_client.h" |
| 20 #include "components/history/core/browser/url_database.h" | 24 #include "components/history/core/browser/url_database.h" |
| 21 #include "sql/recovery.h" | 25 #include "sql/recovery.h" |
| 22 #include "sql/statement.h" | 26 #include "sql/statement.h" |
| 23 #include "sql/transaction.h" | 27 #include "sql/transaction.h" |
| 24 #include "third_party/sqlite/sqlite3.h" | 28 #include "third_party/sqlite/sqlite3.h" |
| 25 | 29 |
| 26 #if defined(OS_MACOSX) && !defined(OS_IOS) | 30 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 27 #include "base/mac/mac_util.h" | 31 #include "base/mac/mac_util.h" |
| 28 #endif | 32 #endif |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // once per Chrome run. | 132 // once per Chrome run. |
| 129 static bool reported = false; | 133 static bool reported = false; |
| 130 if (reported) | 134 if (reported) |
| 131 return; | 135 return; |
| 132 reported = true; | 136 reported = true; |
| 133 | 137 |
| 134 // Only pass 5% of new reports to prevent a thundering herd of dumps. | 138 // Only pass 5% of new reports to prevent a thundering herd of dumps. |
| 135 // TODO(shess): If this could be related to the time in the channel, then the | 139 // TODO(shess): If this could be related to the time in the channel, then the |
| 136 // rate could ramp up over time. Perhaps could remember the timestamp the | 140 // rate could ramp up over time. Perhaps could remember the timestamp the |
| 137 // first time upload is considered, and ramp up 1% per day? | 141 // first time upload is considered, and ramp up 1% per day? |
| 138 static const uint64 kReportPercent = 5; | 142 static const uint64_t kReportPercent = 5; |
| 139 uint64 rand = base::RandGenerator(100); | 143 uint64_t rand = base::RandGenerator(100); |
| 140 if (rand <= kReportPercent) | 144 if (rand <= kReportPercent) |
| 141 db->ReportDiagnosticInfo(extended_error, stmt); | 145 db->ReportDiagnosticInfo(extended_error, stmt); |
| 142 } | 146 } |
| 143 | 147 |
| 144 // NOTE(shess): Schema modifications must consider initial creation in | 148 // NOTE(shess): Schema modifications must consider initial creation in |
| 145 // |InitImpl()|, recovery in |RecoverDatabaseOrRaze()|, and history pruning in | 149 // |InitImpl()|, recovery in |RecoverDatabaseOrRaze()|, and history pruning in |
| 146 // |RetainDataForPageUrls()|. | 150 // |RetainDataForPageUrls()|. |
| 147 bool InitTables(sql::Connection* db) { | 151 bool InitTables(sql::Connection* db) { |
| 148 const char kIconMappingSql[] = | 152 const char kIconMappingSql[] = |
| 149 "CREATE TABLE IF NOT EXISTS icon_mapping" | 153 "CREATE TABLE IF NOT EXISTS icon_mapping" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // dependency, meanwhile contact me if you need to bump the version. | 269 // dependency, meanwhile contact me if you need to bump the version. |
| 266 DCHECK_EQ(8, kCurrentVersionNumber); | 270 DCHECK_EQ(8, kCurrentVersionNumber); |
| 267 | 271 |
| 268 // TODO(shess): Reset back after? | 272 // TODO(shess): Reset back after? |
| 269 db->reset_error_callback(); | 273 db->reset_error_callback(); |
| 270 | 274 |
| 271 // For histogram purposes. | 275 // For histogram purposes. |
| 272 size_t favicons_rows_recovered = 0; | 276 size_t favicons_rows_recovered = 0; |
| 273 size_t favicon_bitmaps_rows_recovered = 0; | 277 size_t favicon_bitmaps_rows_recovered = 0; |
| 274 size_t icon_mapping_rows_recovered = 0; | 278 size_t icon_mapping_rows_recovered = 0; |
| 275 int64 original_size = 0; | 279 int64_t original_size = 0; |
| 276 base::GetFileSize(db_path, &original_size); | 280 base::GetFileSize(db_path, &original_size); |
| 277 | 281 |
| 278 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(db, db_path); | 282 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(db, db_path); |
| 279 if (!recovery) { | 283 if (!recovery) { |
| 280 // TODO(shess): Unable to create recovery connection. This | 284 // TODO(shess): Unable to create recovery connection. This |
| 281 // implies something substantial is wrong. At this point |db| has | 285 // implies something substantial is wrong. At this point |db| has |
| 282 // been poisoned so there is nothing really to do. | 286 // been poisoned so there is nothing really to do. |
| 283 // | 287 // |
| 284 // Possible responses are unclear. If the failure relates to a | 288 // Possible responses are unclear. If the failure relates to a |
| 285 // problem somehow specific to the temporary file used to back the | 289 // problem somehow specific to the temporary file used to back the |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 | 382 |
| 379 if (!sql::Recovery::Recovered(recovery.Pass())) { | 383 if (!sql::Recovery::Recovered(recovery.Pass())) { |
| 380 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_COMMIT); | 384 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_COMMIT); |
| 381 return; | 385 return; |
| 382 } | 386 } |
| 383 | 387 |
| 384 // Track the size of the recovered database relative to the size of | 388 // Track the size of the recovered database relative to the size of |
| 385 // the input database. The size should almost always be smaller, | 389 // the input database. The size should almost always be smaller, |
| 386 // unless the input database was empty to start with. If the | 390 // unless the input database was empty to start with. If the |
| 387 // percentage results are very low, something is awry. | 391 // percentage results are very low, something is awry. |
| 388 int64 final_size = 0; | 392 int64_t final_size = 0; |
| 389 if (original_size > 0 && | 393 if (original_size > 0 && |
| 390 base::GetFileSize(db_path, &final_size) && | 394 base::GetFileSize(db_path, &final_size) && |
| 391 final_size > 0) { | 395 final_size > 0) { |
| 392 int percentage = static_cast<int>(original_size * 100 / final_size); | 396 int percentage = static_cast<int>(original_size * 100 / final_size); |
| 393 UMA_HISTOGRAM_PERCENTAGE("History.FaviconsRecoveredPercentage", | 397 UMA_HISTOGRAM_PERCENTAGE("History.FaviconsRecoveredPercentage", |
| 394 std::max(100, percentage)); | 398 std::max(100, percentage)); |
| 395 } | 399 } |
| 396 | 400 |
| 397 // Using 10,000 because these cases mostly care about "none | 401 // Using 10,000 because these cases mostly care about "none |
| 398 // recovered" and "lots recovered". More than 10,000 rows recovered | 402 // recovered" and "lots recovered". More than 10,000 rows recovered |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 return status; | 481 return status; |
| 478 } | 482 } |
| 479 | 483 |
| 480 void ThumbnailDatabase::ComputeDatabaseMetrics() { | 484 void ThumbnailDatabase::ComputeDatabaseMetrics() { |
| 481 base::TimeTicks start_time = base::TimeTicks::Now(); | 485 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 482 | 486 |
| 483 // Calculate the size of the favicon database. | 487 // Calculate the size of the favicon database. |
| 484 { | 488 { |
| 485 sql::Statement page_count( | 489 sql::Statement page_count( |
| 486 db_.GetCachedStatement(SQL_FROM_HERE, "PRAGMA page_count")); | 490 db_.GetCachedStatement(SQL_FROM_HERE, "PRAGMA page_count")); |
| 487 int64 page_count_bytes = page_count.Step() ? page_count.ColumnInt64(0) : 0; | 491 int64_t page_count_bytes = |
| 492 page_count.Step() ? page_count.ColumnInt64(0) : 0; |
| 488 sql::Statement page_size( | 493 sql::Statement page_size( |
| 489 db_.GetCachedStatement(SQL_FROM_HERE, "PRAGMA page_size")); | 494 db_.GetCachedStatement(SQL_FROM_HERE, "PRAGMA page_size")); |
| 490 int64 page_size_bytes = page_size.Step() ? page_size.ColumnInt64(0) : 0; | 495 int64_t page_size_bytes = page_size.Step() ? page_size.ColumnInt64(0) : 0; |
| 491 int size_mb = static_cast<int>( | 496 int size_mb = static_cast<int>( |
| 492 (page_count_bytes * page_size_bytes) / (1024 * 1024)); | 497 (page_count_bytes * page_size_bytes) / (1024 * 1024)); |
| 493 UMA_HISTOGRAM_MEMORY_MB("History.FaviconDatabaseSizeMB", size_mb); | 498 UMA_HISTOGRAM_MEMORY_MB("History.FaviconDatabaseSizeMB", size_mb); |
| 494 } | 499 } |
| 495 | 500 |
| 496 // Count all icon URLs referenced by the DB. | 501 // Count all icon URLs referenced by the DB. |
| 497 { | 502 { |
| 498 sql::Statement favicon_count( | 503 sql::Statement favicon_count( |
| 499 db_.GetCachedStatement(SQL_FROM_HERE, "SELECT COUNT(*) FROM favicons")); | 504 db_.GetCachedStatement(SQL_FROM_HERE, "SELECT COUNT(*) FROM favicons")); |
| 500 UMA_HISTOGRAM_COUNTS_10000( | 505 UMA_HISTOGRAM_COUNTS_10000( |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 meta_table_.SetVersionNumber(8); | 1237 meta_table_.SetVersionNumber(8); |
| 1233 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); | 1238 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); |
| 1234 return true; | 1239 return true; |
| 1235 } | 1240 } |
| 1236 | 1241 |
| 1237 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { | 1242 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { |
| 1238 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); | 1243 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); |
| 1239 } | 1244 } |
| 1240 | 1245 |
| 1241 } // namespace history | 1246 } // namespace history |
| OLD | NEW |