This source file includes following definitions.
- history_db_
- Insert
- Update
- Delete
#include "chrome/browser/history/android/urls_sql_handler.h"
#include "base/logging.h"
#include "chrome/browser/history/history_database.h"
using base::Time;
namespace history {
namespace {
const HistoryAndBookmarkRow::ColumnID kInterestingColumns[] = {
HistoryAndBookmarkRow::URL, HistoryAndBookmarkRow::VISIT_COUNT,
HistoryAndBookmarkRow::TITLE, HistoryAndBookmarkRow::LAST_VISIT_TIME };
}
UrlsSQLHandler::UrlsSQLHandler(HistoryDatabase* history_db)
: SQLHandler(kInterestingColumns, arraysize(kInterestingColumns)),
history_db_(history_db) {
}
UrlsSQLHandler:: ~UrlsSQLHandler() {
}
bool UrlsSQLHandler::Insert(HistoryAndBookmarkRow* row) {
URLRow url_row(row->url());
URLID id = history_db_->GetRowForURL(row->url(), &url_row);
if (id) {
LOG(ERROR) << "AndroidProviderBackend::Insert Urls; url exists.";
return false;
}
if (row->is_value_set_explicitly(HistoryAndBookmarkRow::TITLE))
url_row.set_title(row->title());
if (row->is_value_set_explicitly(HistoryAndBookmarkRow::LAST_VISIT_TIME))
url_row.set_last_visit(row->last_visit_time());
if (row->is_value_set_explicitly(HistoryAndBookmarkRow::VISIT_COUNT))
url_row.set_visit_count(row->visit_count());
if (!row->is_value_set_explicitly(HistoryAndBookmarkRow::LAST_VISIT_TIME)) {
if (row->is_value_set_explicitly(HistoryAndBookmarkRow::CREATED))
url_row.set_last_visit(row->created());
else if (row->is_value_set_explicitly(HistoryAndBookmarkRow::VISIT_COUNT))
url_row.set_last_visit(Time::Now());
}
if (!row->is_value_set_explicitly(HistoryAndBookmarkRow::VISIT_COUNT)) {
int visit_count = 0;
if (row->is_value_set_explicitly(HistoryAndBookmarkRow::CREATED) &&
row->is_value_set_explicitly(HistoryAndBookmarkRow::LAST_VISIT_TIME) &&
row->last_visit_time() == row->created()) {
visit_count = 1;
} else {
if (row->is_value_set_explicitly(HistoryAndBookmarkRow::CREATED))
visit_count++;
if (row->is_value_set_explicitly(HistoryAndBookmarkRow::LAST_VISIT_TIME))
visit_count++;
}
url_row.set_visit_count(visit_count);
}
URLID new_id = history_db_->AddURL(url_row);
row->set_url_id(new_id);
return new_id;
}
bool UrlsSQLHandler::Update(const HistoryAndBookmarkRow& row,
const TableIDRows& ids_set) {
DCHECK(!row.is_value_set_explicitly(HistoryAndBookmarkRow::URL));
for (TableIDRows::const_iterator ids = ids_set.begin();
ids != ids_set.end(); ++ids) {
URLRow url_row;
if (!history_db_->GetURLRow(ids->url_id, &url_row))
return false;
URLRow update_row = url_row;
if (row.is_value_set_explicitly(HistoryAndBookmarkRow::TITLE))
update_row.set_title(row.title());
if (row.is_value_set_explicitly(HistoryAndBookmarkRow::VISIT_COUNT))
update_row.set_visit_count(row.visit_count());
if (row.is_value_set_explicitly(HistoryAndBookmarkRow::LAST_VISIT_TIME)) {
if (row.last_visit_time() < url_row.last_visit())
return false;
update_row.set_last_visit(row.last_visit_time());
}
if (!row.is_value_set_explicitly(HistoryAndBookmarkRow::VISIT_COUNT) &&
row.is_value_set_explicitly(HistoryAndBookmarkRow::LAST_VISIT_TIME) &&
(row.last_visit_time() != url_row.last_visit()))
update_row.set_visit_count(url_row.visit_count() + 1);
if (!row.is_value_set_explicitly(HistoryAndBookmarkRow::LAST_VISIT_TIME)) {
if (row.is_value_set_explicitly(HistoryAndBookmarkRow::VISIT_COUNT) &&
row.visit_count() == 0) {
update_row.set_last_visit(Time());
} else if (row.visit_count() > url_row.visit_count()) {
update_row.set_last_visit(Time::Now());
}
}
if (!history_db_->UpdateURLRow(ids->url_id, update_row))
return false;
}
return true;
}
bool UrlsSQLHandler::Delete(const TableIDRows& ids_set) {
for (TableIDRows::const_iterator ids = ids_set.begin();
ids != ids_set.end(); ++ids) {
if (!history_db_->DeleteURLRow(ids->url_id))
return false;
}
return true;
}
}