| Index: chrome/browser/predictors/autocomplete_action_predictor_database.cc
|
| diff --git a/chrome/browser/autocomplete/network_action_predictor_database.cc b/chrome/browser/predictors/autocomplete_action_predictor_database.cc
|
| similarity index 69%
|
| rename from chrome/browser/autocomplete/network_action_predictor_database.cc
|
| rename to chrome/browser/predictors/autocomplete_action_predictor_database.cc
|
| index a1454f439e0166e0c08fa3b9d903fd391354c793..7fe9add22f38736dc85a7ae0861dee89509b6b69 100644
|
| --- a/chrome/browser/autocomplete/network_action_predictor_database.cc
|
| +++ b/chrome/browser/predictors/autocomplete_action_predictor_database.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/autocomplete/network_action_predictor_database.h"
|
| +#include "chrome/browser/predictors/autocomplete_action_predictor_database.h"
|
|
|
| #include "base/bind.h"
|
| #include "base/file_util.h"
|
| @@ -17,14 +17,14 @@
|
|
|
| namespace {
|
|
|
| -const char kNetworkActionPredictorTableName[] = "network_action_predictor";
|
| -const FilePath::CharType kNetworkActionPredictorDatabaseName[] =
|
| +const char kAutocompleteActionPredictorTableName[] = "network_action_predictor";
|
| +const FilePath::CharType kAutocompleteActionPredictorDatabaseName[] =
|
| FILE_PATH_LITERAL("Network Action Predictor");
|
|
|
| // The maximum length allowed for strings in the database.
|
| const size_t kMaxDataLength = 2048;
|
|
|
| -void BindRowToStatement(const NetworkActionPredictorDatabase::Row& row,
|
| +void BindRowToStatement(const AutocompleteActionPredictorDatabase::Row& row,
|
| sql::Statement* statement) {
|
| DCHECK(guid::IsValidGUID(row.id));
|
| statement->BindString(0, row.id);
|
| @@ -35,7 +35,7 @@ void BindRowToStatement(const NetworkActionPredictorDatabase::Row& row,
|
| }
|
|
|
| bool StepAndInitializeRow(sql::Statement* statement,
|
| - NetworkActionPredictorDatabase::Row* row) {
|
| + AutocompleteActionPredictorDatabase::Row* row) {
|
| if (!statement->Step())
|
| return false;
|
|
|
| @@ -56,7 +56,7 @@ void LogDatabaseStats(const FilePath& db_path, sql::Connection* db) {
|
|
|
| sql::Statement count_statement(db->GetUniqueStatement(
|
| base::StringPrintf("SELECT count(id) FROM %s",
|
| - kNetworkActionPredictorTableName).c_str()));
|
| + kAutocompleteActionPredictorTableName).c_str()));
|
| if (!count_statement.Step())
|
| return;
|
| UMA_HISTOGRAM_COUNTS("NetworkActionPredictor.DatabaseRowCount",
|
| @@ -65,12 +65,12 @@ void LogDatabaseStats(const FilePath& db_path, sql::Connection* db) {
|
|
|
| }
|
|
|
| -NetworkActionPredictorDatabase::Row::Row()
|
| +AutocompleteActionPredictorDatabase::Row::Row()
|
| : number_of_hits(0),
|
| number_of_misses(0) {
|
| }
|
|
|
| -NetworkActionPredictorDatabase::Row::Row(const Row::Id& id,
|
| +AutocompleteActionPredictorDatabase::Row::Row(const Row::Id& id,
|
| const string16& user_text,
|
| const GURL& url,
|
| int number_of_hits,
|
| @@ -82,14 +82,16 @@ NetworkActionPredictorDatabase::Row::Row(const Row::Id& id,
|
| number_of_misses(number_of_misses) {
|
| }
|
|
|
| -NetworkActionPredictorDatabase::NetworkActionPredictorDatabase(Profile* profile)
|
| - : db_path_(profile->GetPath().Append(kNetworkActionPredictorDatabaseName)) {
|
| +AutocompleteActionPredictorDatabase::AutocompleteActionPredictorDatabase(
|
| + Profile* profile)
|
| + : db_path_(profile->GetPath().Append(
|
| + kAutocompleteActionPredictorDatabaseName)) {
|
| }
|
|
|
| -NetworkActionPredictorDatabase::~NetworkActionPredictorDatabase() {
|
| +AutocompleteActionPredictorDatabase::~AutocompleteActionPredictorDatabase() {
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::Initialize() {
|
| +void AutocompleteActionPredictorDatabase::Initialize() {
|
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
|
|
|
| if (canceled_.IsSet())
|
| @@ -101,13 +103,13 @@ void NetworkActionPredictorDatabase::Initialize() {
|
| return;
|
| }
|
|
|
| - if (!db_.DoesTableExist(kNetworkActionPredictorTableName))
|
| + if (!db_.DoesTableExist(kAutocompleteActionPredictorTableName))
|
| CreateTable();
|
|
|
| LogDatabaseStats(db_path_, &db_);
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::GetRow(const Row::Id& id, Row* row) {
|
| +void AutocompleteActionPredictorDatabase::GetRow(const Row::Id& id, Row* row) {
|
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
|
|
|
| if (canceled_.IsSet())
|
| @@ -116,16 +118,16 @@ void NetworkActionPredictorDatabase::GetRow(const Row::Id& id, Row* row) {
|
| sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
|
| base::StringPrintf(
|
| "SELECT * FROM %s WHERE id=?",
|
| - kNetworkActionPredictorTableName).c_str()));
|
| + kAutocompleteActionPredictorTableName).c_str()));
|
| statement.BindString(0, id);
|
|
|
| bool success = StepAndInitializeRow(&statement, row);
|
| DCHECK(success) << "Failed to get row " << id << " from "
|
| - << kNetworkActionPredictorTableName;
|
| + << kAutocompleteActionPredictorTableName;
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::GetAllRows(
|
| - std::vector<NetworkActionPredictorDatabase::Row>* row_buffer) {
|
| +void AutocompleteActionPredictorDatabase::GetAllRows(
|
| + std::vector<AutocompleteActionPredictorDatabase::Row>* row_buffer) {
|
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
|
| CHECK(row_buffer);
|
| row_buffer->clear();
|
| @@ -135,15 +137,15 @@ void NetworkActionPredictorDatabase::GetAllRows(
|
|
|
| sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
|
| base::StringPrintf(
|
| - "SELECT * FROM %s", kNetworkActionPredictorTableName).c_str()));
|
| + "SELECT * FROM %s", kAutocompleteActionPredictorTableName).c_str()));
|
|
|
| Row row;
|
| while (StepAndInitializeRow(&statement, &row))
|
| row_buffer->push_back(row);
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::AddRow(
|
| - const NetworkActionPredictorDatabase::Row& row) {
|
| +void AutocompleteActionPredictorDatabase::AddRow(
|
| + const AutocompleteActionPredictorDatabase::Row& row) {
|
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
|
|
|
| if (canceled_.IsSet())
|
| @@ -153,16 +155,17 @@ void NetworkActionPredictorDatabase::AddRow(
|
| base::StringPrintf(
|
| "INSERT INTO %s "
|
| "(id, user_text, url, number_of_hits, number_of_misses) "
|
| - "VALUES (?,?,?,?,?)", kNetworkActionPredictorTableName).c_str()));
|
| + "VALUES (?,?,?,?,?)",
|
| + kAutocompleteActionPredictorTableName).c_str()));
|
| BindRowToStatement(row, &statement);
|
|
|
| bool success = statement.Run();
|
| DCHECK(success) << "Failed to insert row " << row.id << " into "
|
| - << kNetworkActionPredictorTableName;
|
| + << kAutocompleteActionPredictorTableName;
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::UpdateRow(
|
| - const NetworkActionPredictorDatabase::Row& row) {
|
| +void AutocompleteActionPredictorDatabase::UpdateRow(
|
| + const AutocompleteActionPredictorDatabase::Row& row) {
|
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
|
|
|
| if (canceled_.IsSet())
|
| @@ -172,14 +175,14 @@ void NetworkActionPredictorDatabase::UpdateRow(
|
| base::StringPrintf(
|
| "UPDATE %s "
|
| "SET id=?, user_text=?, url=?, number_of_hits=?, number_of_misses=? "
|
| - "WHERE id=?1", kNetworkActionPredictorTableName).c_str()));
|
| + "WHERE id=?1", kAutocompleteActionPredictorTableName).c_str()));
|
| BindRowToStatement(row, &statement);
|
|
|
| statement.Run();
|
| DCHECK_GT(db_.GetLastChangeCount(), 0);
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::DeleteRow(const Row::Id& id) {
|
| +void AutocompleteActionPredictorDatabase::DeleteRow(const Row::Id& id) {
|
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
|
|
|
| if (canceled_.IsSet())
|
| @@ -188,7 +191,7 @@ void NetworkActionPredictorDatabase::DeleteRow(const Row::Id& id) {
|
| DeleteRows(std::vector<Row::Id>(1, id));
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::DeleteRows(
|
| +void AutocompleteActionPredictorDatabase::DeleteRows(
|
| const std::vector<Row::Id>& id_list) {
|
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
|
|
|
| @@ -197,7 +200,7 @@ void NetworkActionPredictorDatabase::DeleteRows(
|
|
|
| sql::Statement statement(db_.GetUniqueStatement(base::StringPrintf(
|
| "DELETE FROM %s WHERE id=?",
|
| - kNetworkActionPredictorTableName).c_str()));
|
| + kAutocompleteActionPredictorTableName).c_str()));
|
|
|
| db_.BeginTransaction();
|
| for (std::vector<Row::Id>::const_iterator it = id_list.begin();
|
| @@ -209,7 +212,7 @@ void NetworkActionPredictorDatabase::DeleteRows(
|
| db_.CommitTransaction();
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::DeleteAllRows() {
|
| +void AutocompleteActionPredictorDatabase::DeleteAllRows() {
|
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
|
|
|
| if (canceled_.IsSet())
|
| @@ -217,12 +220,12 @@ void NetworkActionPredictorDatabase::DeleteAllRows() {
|
|
|
| sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
|
| base::StringPrintf("DELETE FROM %s",
|
| - kNetworkActionPredictorTableName).c_str()));
|
| + kAutocompleteActionPredictorTableName).c_str()));
|
|
|
| statement.Run();
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::BeginTransaction() {
|
| +void AutocompleteActionPredictorDatabase::BeginTransaction() {
|
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
|
|
|
| if (canceled_.IsSet())
|
| @@ -231,7 +234,7 @@ void NetworkActionPredictorDatabase::BeginTransaction() {
|
| db_.BeginTransaction();
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::CommitTransaction() {
|
| +void AutocompleteActionPredictorDatabase::CommitTransaction() {
|
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
|
|
|
| if (canceled_.IsSet())
|
| @@ -240,18 +243,19 @@ void NetworkActionPredictorDatabase::CommitTransaction() {
|
| db_.CommitTransaction();
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::OnPredictorDestroyed() {
|
| +void AutocompleteActionPredictorDatabase::OnPredictorDestroyed() {
|
| canceled_.Set();
|
| }
|
|
|
| -void NetworkActionPredictorDatabase::CreateTable() {
|
| +void AutocompleteActionPredictorDatabase::CreateTable() {
|
| bool success = db_.Execute(base::StringPrintf(
|
| "CREATE TABLE %s ( "
|
| "id TEXT PRIMARY KEY, "
|
| "user_text TEXT, "
|
| "url TEXT, "
|
| "number_of_hits INTEGER, "
|
| - "number_of_misses INTEGER)", kNetworkActionPredictorTableName).c_str());
|
| - DCHECK(success) << "Failed to create " << kNetworkActionPredictorTableName
|
| - << " table.";
|
| + "number_of_misses INTEGER)",
|
| + kAutocompleteActionPredictorTableName).c_str());
|
| + DCHECK(success) << "Failed to create "
|
| + << kAutocompleteActionPredictorTableName << " table.";
|
| }
|
|
|