| 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/resource_prefetch_predictor_tables.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "sql/statement.h" | 12 #include "sql/statement.h" |
| 12 | 13 |
| 13 using content::BrowserThread; | 14 using content::BrowserThread; |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 const char kResourcePredictorUrlTableName[] = "resource_prefetch_predictor_url"; | 18 const char kResourcePredictorUrlTableName[] = "resource_prefetch_predictor_url"; |
| 18 | 19 |
| 19 // The maximum length allowed for strings in the database. | 20 // The maximum length allowed for strings in the database. |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 "consecutive_misses INTEGER, " | 238 "consecutive_misses INTEGER, " |
| 238 "average_position DOUBLE, " | 239 "average_position DOUBLE, " |
| 239 "PRIMARY KEY(main_page_url, resource_url))", | 240 "PRIMARY KEY(main_page_url, resource_url))", |
| 240 kResourcePredictorUrlTableName); | 241 kResourcePredictorUrlTableName); |
| 241 | 242 |
| 242 if (!DB()->DoesTableExist(kResourcePredictorUrlTableName) && | 243 if (!DB()->DoesTableExist(kResourcePredictorUrlTableName) && |
| 243 !DB()->Execute(url_table_creation_statement.c_str())) | 244 !DB()->Execute(url_table_creation_statement.c_str())) |
| 244 ResetDB(); | 245 ResetDB(); |
| 245 } | 246 } |
| 246 | 247 |
| 247 void ResourcePrefetchPredictorTables::LogDatabaseStats() { | 248 void ResourcePrefetchPredictorTables::LogDatabaseStats(Profile* profile) { |
| 248 CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 249 CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 250 |
| 251 if (!ResourcePrefetchPredictor::IsEnabled(profile)) |
| 252 return; |
| 253 |
| 249 if (CantAccessDatabase()) | 254 if (CantAccessDatabase()) |
| 250 return; | 255 return; |
| 251 | 256 |
| 252 sql::Statement url_statement(DB()->GetUniqueStatement( | 257 sql::Statement total_rows_statement(DB()->GetUniqueStatement( |
| 253 base::StringPrintf("SELECT count(*) FROM %s", | 258 base::StringPrintf("SELECT count(*) FROM %s", |
| 254 kResourcePredictorUrlTableName).c_str())); | 259 kResourcePredictorUrlTableName).c_str())); |
| 255 if (url_statement.Step()) | 260 if (total_rows_statement.Step()) |
| 256 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.UrlTableRowCount", | 261 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.UrlTableRowCount", |
| 257 url_statement.ColumnInt(0)); | 262 total_rows_statement.ColumnInt(0)); |
| 258 } | 263 } |
| 259 | 264 |
| 260 } // namespace predictors | 265 } // namespace predictors |
| OLD | NEW |