Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: components/history/core/android/android_urls_database.cc

Issue 849323002: Componentize HistoryDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android compilation Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/history/core/android/android_urls_database.cc
diff --git a/components/history/core/android/android_urls_database.cc b/components/history/core/android/android_urls_database.cc
deleted file mode 100644
index bc692eb3a21257d24ab4f868fcb55ec5c201b79b..0000000000000000000000000000000000000000
--- a/components/history/core/android/android_urls_database.cc
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/history/core/android/android_urls_database.h"
-
-#include "base/logging.h"
-
-namespace history {
-
-AndroidURLsDatabase::AndroidURLsDatabase() {
-}
-
-AndroidURLsDatabase::~AndroidURLsDatabase() {
-}
-
-bool AndroidURLsDatabase::CreateAndroidURLsTable() {
- const char* name = "android_urls";
- if (!GetDB().DoesTableExist(name)) {
- std::string sql;
- sql.append("CREATE TABLE ");
- sql.append(name);
- sql.append("("
- "id INTEGER PRIMARY KEY,"
- "raw_url LONGVARCHAR," // Passed in raw url.
- "url_id INTEGER NOT NULL" // url id in urls table.
- ")");
- if (!GetDB().Execute(sql.c_str())) {
- LOG(ERROR) << GetDB().GetErrorMessage();
- return false;
- }
-
- if (!GetDB().Execute("CREATE INDEX android_urls_raw_url_idx"
- " ON android_urls(raw_url)")) {
- LOG(ERROR) << GetDB().GetErrorMessage();
- return false;
- }
-
- if (!GetDB().Execute("CREATE INDEX android_urls_url_id_idx"
- " ON android_urls(url_id)")) {
- LOG(ERROR) << GetDB().GetErrorMessage();
- return false;
- }
- }
- return true;
-}
-
-AndroidURLID AndroidURLsDatabase::AddAndroidURLRow(const std::string& raw_url,
- URLID url_id) {
- if (GetAndroidURLRow(url_id, NULL)) {
- LOG(ERROR) << "url_id already exist";
- return 0;
- }
-
- sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
- "INSERT INTO android_urls (raw_url, url_id) VALUES (?, ?)"));
-
- statement.BindString(0, raw_url);
- statement.BindInt64(1, static_cast<int64>(url_id));
-
- if (!statement.Run()) {
- LOG(ERROR) << GetDB().GetErrorMessage();
- return 0;
- }
- return GetDB().GetLastInsertRowId();
-}
-
-bool AndroidURLsDatabase::GetAndroidURLRow(URLID url_id, AndroidURLRow* row) {
- sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
- "SELECT id, raw_url, url_id FROM android_urls WHERE url_id = ?"));
-
- statement.BindInt64(0, url_id);
-
- if (!statement.Step())
- return false;
- if (row) {
- row->id = statement.ColumnInt64(0);
- row->raw_url = statement.ColumnString(1);
- row->url_id = statement.ColumnInt64(2);
- }
- return true;
-}
-
-bool AndroidURLsDatabase::DeleteAndroidURLRows(
- const std::vector<URLID>& url_ids) {
- if (url_ids.empty())
- return true;
-
- std::string sql;
- sql.append("DELETE FROM android_urls ");
- std::ostringstream oss;
- bool has_id = false;
- for (std::vector<URLID>::const_iterator i = url_ids.begin();
- i != url_ids.end(); ++i) {
- if (has_id)
- oss << ", ";
- else
- has_id = true;
- oss << *i;
- }
-
- if (has_id) {
- sql.append(" WHERE url_id in ( ");
- sql.append(oss.str());
- sql.append(" )");
- }
-
- if (!GetDB().Execute(sql.c_str())) {
- LOG(ERROR) << GetDB().GetErrorMessage();
- return false;
- }
- return true;
-}
-
-bool AndroidURLsDatabase::DeleteUnusedAndroidURLs() {
- return GetDB().Execute("DELETE FROM android_urls WHERE url_id NOT IN ("
- "SELECT id FROM urls)");
-}
-
-bool AndroidURLsDatabase::UpdateAndroidURLRow(AndroidURLID id,
- const std::string& raw_url,
- URLID url_id) {
- sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
- "UPDATE android_urls SET raw_url = ?, url_id = ? WHERE id = ?"));
-
- statement.BindString(0, raw_url);
- statement.BindInt64(1, url_id);
- statement.BindInt64(2, id);
-
- if (!statement.is_valid()) {
- LOG(ERROR) << GetDB().GetErrorMessage();
- return false;
- }
-
- if (!statement.Run()) {
- LOG(ERROR) << GetDB().GetErrorMessage();
- return false;
- }
-
- return true;
-}
-
-bool AndroidURLsDatabase::ClearAndroidURLRows() {
- // The android_urls table might not exist if the Android content provider is
- // never used, especially in the unit tests. See http://b/6385692.
- if (GetDB().DoesTableExist("android_urls"))
- return GetDB().Execute("DELETE FROM android_urls");
-
- return true;
-}
-
-bool AndroidURLsDatabase::MigrateToVersion22() {
- if (!GetDB().DoesTableExist("android_urls"))
- return true;
-
- if (!GetDB().Execute("ALTER TABLE android_urls RENAME TO android_urls_tmp"))
- return false;
-
- if (!GetDB().Execute("DROP INDEX android_urls_raw_url_idx"))
- return false;
-
- if (!GetDB().Execute("DROP INDEX android_urls_url_id_idx"))
- return false;
-
- if (!CreateAndroidURLsTable())
- return false;
-
- if (!GetDB().Execute(
- "INSERT INTO android_urls (id, raw_url, url_id) "
- "SELECT id, raw_url, url_id FROM android_urls_tmp"))
- return false;
-
- if (!GetDB().Execute("DROP TABLE android_urls_tmp"))
- return false;
-
- return true;
-}
-
-} // namespace history
« no previous file with comments | « components/history/core/android/android_urls_database.h ('k') | components/history/core/android/android_urls_sql_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698