| 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/predictors/predictor_database.h" | 5 #include "chrome/browser/predictors/predictor_database.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "chrome/browser/predictors/autocomplete_action_predictor_table.h" | 13 #include "chrome/browser/predictors/autocomplete_action_predictor_table.h" |
| 14 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 14 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 15 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "sql/connection.h" | 18 #include "sql/connection.h" |
| 18 #include "sql/statement.h" | 19 #include "sql/statement.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // TODO(shishir): This should move to a more generic name. | 23 // TODO(shishir): This should move to a more generic name. |
| 23 const FilePath::CharType kPredictorDatabaseName[] = | 24 const FilePath::CharType kPredictorDatabaseName[] = |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 void PredictorDatabaseInternal::LogDatabaseStats() { | 93 void PredictorDatabaseInternal::LogDatabaseStats() { |
| 93 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); | 94 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); |
| 94 | 95 |
| 95 int64 db_size; | 96 int64 db_size; |
| 96 bool success = file_util::GetFileSize(db_path_, &db_size); | 97 bool success = file_util::GetFileSize(db_path_, &db_size); |
| 97 DCHECK(success) << "Failed to get file size for " << db_path_.value(); | 98 DCHECK(success) << "Failed to get file size for " << db_path_.value(); |
| 98 UMA_HISTOGRAM_MEMORY_KB("PredictorDatabase.DatabaseSizeKB", | 99 UMA_HISTOGRAM_MEMORY_KB("PredictorDatabase.DatabaseSizeKB", |
| 99 static_cast<int>(db_size / 1024)); | 100 static_cast<int>(db_size / 1024)); |
| 100 | 101 |
| 101 autocomplete_table_->LogDatabaseStats(); | 102 autocomplete_table_->LogDatabaseStats(); |
| 102 resource_prefetch_tables_->LogDatabaseStats(); | 103 if (ResourcePrefetchPredictor::IsEnabled()) |
| 104 resource_prefetch_tables_->LogDatabaseStats(); |
| 103 } | 105 } |
| 104 | 106 |
| 105 PredictorDatabase::PredictorDatabase(Profile* profile) | 107 PredictorDatabase::PredictorDatabase(Profile* profile) |
| 106 : db_(new PredictorDatabaseInternal(profile)) { | 108 : db_(new PredictorDatabaseInternal(profile)) { |
| 107 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, | 109 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, |
| 108 base::Bind(&PredictorDatabaseInternal::Initialize, db_)); | 110 base::Bind(&PredictorDatabaseInternal::Initialize, db_)); |
| 109 } | 111 } |
| 110 | 112 |
| 111 PredictorDatabase::~PredictorDatabase() { | 113 PredictorDatabase::~PredictorDatabase() { |
| 112 } | 114 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 123 scoped_refptr<ResourcePrefetchPredictorTables> | 125 scoped_refptr<ResourcePrefetchPredictorTables> |
| 124 PredictorDatabase::resource_prefetch_tables() { | 126 PredictorDatabase::resource_prefetch_tables() { |
| 125 return db_->resource_prefetch_tables_; | 127 return db_->resource_prefetch_tables_; |
| 126 } | 128 } |
| 127 | 129 |
| 128 sql::Connection* PredictorDatabase::GetDatabase() { | 130 sql::Connection* PredictorDatabase::GetDatabase() { |
| 129 return &db_->db_; | 131 return &db_->db_; |
| 130 } | 132 } |
| 131 | 133 |
| 132 } // namespace predictors | 134 } // namespace predictors |
| OLD | NEW |