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

Unified Diff: chrome/browser/history/history_backend.cc

Issue 10217010: Completed the code path from AndroidProviderService to HistoryBackend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Init Created 8 years, 8 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: chrome/browser/history/history_backend.cc
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 42c33e08990071723981e15a060c18e3632959b3..ea469285cb75cf370aa0794334423b6afd267b57 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -36,6 +36,10 @@
#include "grit/generated_resources.h"
#include "net/base/registry_controlled_domain.h"
+#if defined(OS_ANDROID)
+#include "chrome/browser/history/android/android_provider_backend.h"
+#endif
+
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
@@ -217,6 +221,11 @@ HistoryBackend::~HistoryBackend() {
DCHECK(!scheduled_commit_) << "Deleting without cleanup";
ReleaseDBTasks();
+#if defined(OS_ANDROID)
+ // Release AndroidProviderBackend before other objects.
+ android_provider_backend_.reset();
+#endif
+
// First close the databases before optionally running the "destroy" task.
if (db_.get()) {
// Commit the long-running transaction.
@@ -241,6 +250,10 @@ HistoryBackend::~HistoryBackend() {
DCHECK(backend_destroy_message_loop_);
backend_destroy_message_loop_->PostTask(FROM_HERE, backend_destroy_task_);
}
+
+#if defined(OS_ANDROID)
+ file_util::Delete(GetAndroidCacheFileName(), false);
+#endif
}
void HistoryBackend::Init(const std::string& languages, bool force_fail) {
@@ -283,6 +296,12 @@ FilePath HistoryBackend::GetArchivedFileName() const {
return history_dir_.Append(chrome::kArchivedHistoryFilename);
}
+#if defined(OS_ANDROID)
+FilePath HistoryBackend::GetAndroidCacheFileName() const {
+ return history_dir_.Append(chrome::kAndroidCacheFilename);
+}
+#endif
+
SegmentID HistoryBackend::GetLastSegmentID(VisitID from_visit) {
// Set is used to detect referrer loops. Should not happen, but can
// if the database is corrupt.
@@ -702,6 +721,14 @@ void HistoryBackend::InitImpl(const std::string& languages) {
// Start expiring old stuff.
expirer_.StartArchivingOldStuff(TimeDelta::FromDays(kArchiveDaysThreshold));
+#if defined(OS_ANDROID)
+ if (thumbnail_db_.get()) {
+ android_provider_backend_.reset(new AndroidProviderBackend(
+ GetAndroidCacheFileName(), db_.get(), thumbnail_db_.get(),
+ bookmark_service_, delegate_.get()));
+ }
+#endif
+
HISTOGRAM_TIMES("History.InitTime",
TimeTicks::Now() - beginning_time);
}
@@ -1143,6 +1170,184 @@ void HistoryBackend::GetMostRecentKeywordSearchTerms(
request->ForwardResult(request->handle(), &request->value);
}
+#if defined(OS_ANDROID)
sky 2012/04/25 15:57:25 Move all of this into the file history_backend_and
michaelbai 2012/04/26 05:32:48 Done.
+
+// History and Bookmarks -------------------------------------------------------
+
+void HistoryBackend::InsertHistoryAndBookmark(
+ scoped_refptr<InsertRequest> request,
+ const HistoryAndBookmarkRow& row) {
+ if (request->canceled())
+ return;
+
+ AndroidURLID id = 0;
+ if (android_provider_backend_.get())
+ id = android_provider_backend_->InsertHistoryAndBookmark(row);
+
+ request->ForwardResult(request->handle(), id != 0, id);
+}
+
+void HistoryBackend::QueryHistoryAndBookmarks(
+ scoped_refptr<QueryRequest> request,
+ const std::vector<HistoryAndBookmarkRow::ColumnID>& projections,
+ const std::string& selection,
+ const std::vector<string16>& selection_args,
+ const std::string& sort_order) {
+ if (request->canceled())
+ return;
+
+ AndroidStatement* statement = NULL;
+ if (android_provider_backend_.get()) {
+ statement = android_provider_backend_->QueryHistoryAndBookmarks(
+ projections, selection, selection_args, sort_order);
+ }
+ request->ForwardResult(request->handle(), statement, statement);
+}
+
+void HistoryBackend::UpdateHistoryAndBookmarks(
+ scoped_refptr<UpdateRequest> request,
+ const HistoryAndBookmarkRow& row,
+ const std::string& selection,
+ const std::vector<string16>& selection_args) {
+ if (request->canceled())
+ return;
+
+ int count = 0;
+ bool result = false;
+ if (android_provider_backend_.get()) {
+ result = android_provider_backend_->UpdateHistoryAndBookmarks(row,
+ selection, selection_args, &count);
+ }
+
+ request->ForwardResult(request->handle(), result, count);
+}
+
+void HistoryBackend::DeleteHistoryAndBookmarks(
+ scoped_refptr<DeleteRequest> request,
+ const std::string& selection,
+ const std::vector<string16>& selection_args) {
+ if (request->canceled())
+ return;
+
+ int count = 0;
+ bool result = false;
+ if (android_provider_backend_.get())
+ result = android_provider_backend_->DeleteHistoryAndBookmarks(selection,
+ selection_args, &count);
+
+ request->ForwardResult(request->handle(), result, count);
+}
+
+void HistoryBackend::DeleteHistory(
+ scoped_refptr<DeleteRequest> request,
+ const std::string& selection,
+ const std::vector<string16>& selection_args) {
+ if (request->canceled())
+ return;
+
+ int count = 0;
+ bool result = false;
+ if (android_provider_backend_.get()) {
+ result = android_provider_backend_->DeleteHistory(selection, selection_args,
+ &count);
+ }
+ request->ForwardResult(request->handle(), result, count);
+}
+
+// Statement -------------------------------------------------------------------
+
+void HistoryBackend::MoveStatement(
+ scoped_refptr<MoveStatementRequest> request,
+ history::AndroidStatement* statement,
+ int current_pos,
+ int destination) {
+ DCHECK_LE(-1, current_pos);
+ DCHECK_LE(-1, destination);
+
+ int cur = current_pos;
+ if (current_pos > destination) {
+ statement->statement()->ResetWithoutClearingBoundVariables();
+ cur = -1;
+ }
+ for (; cur < destination; ++cur) {
+ if (!statement->statement()->Step())
+ break;
+ }
+
+ request->ForwardResult(request->handle(), cur);
+}
+
+void HistoryBackend::CloseStatement(AndroidStatement* statement) {
+ delete statement;
+}
+
+// Search Term -----------------------------------------------------------------
+
+void HistoryBackend::InsertSearchTerm(scoped_refptr<InsertRequest> request,
+ const SearchRow& row) {
+ if (request->canceled())
+ return;
+
+ SearchTermID id = 0;
+ if (android_provider_backend_.get())
+ id = android_provider_backend_->InsertSearchTerm(row);
+
+ request->ForwardResult(request->handle(), id != 0, id);
+}
+
+void HistoryBackend::UpdateSearchTerms(
+ scoped_refptr<UpdateRequest> request,
+ const SearchRow& row,
+ const std::string& selection,
+ const std::vector<string16> selection_args) {
+ if (request->canceled())
+ return;
+
+ int count = 0;
+ bool result = false;
+ if (android_provider_backend_.get()) {
+ result = android_provider_backend_->UpdateSearchTerms(row, selection,
+ selection_args, &count);
+ }
+ request->ForwardResult(request->handle(), result, count);
+}
+
+void HistoryBackend::DeleteSearchTerms(
+ scoped_refptr<DeleteRequest> request,
+ const std::string& selection,
+ const std::vector<string16> selection_args) {
+ if (request->canceled())
+ return;
+
+ int count = 0;
+ bool result = false;
+ if (android_provider_backend_.get()) {
+ result = android_provider_backend_->DeleteSearchTerms(selection,
+ selection_args, &count);
+ }
+
+ request->ForwardResult(request->handle(), result, count);
+}
+
+void HistoryBackend::QuerySearchTerms(
+ scoped_refptr<QueryRequest> request,
+ const std::vector<SearchRow::ColumnID>& projections,
+ const std::string& selection,
+ const std::vector<string16>& selection_args,
+ const std::string& sort_order) {
+ if (request->canceled())
+ return;
+
+ AndroidStatement* statement = NULL;
+ if (android_provider_backend_.get())
+ statement = android_provider_backend_->QuerySearchTerms(projections,
+ selection, selection_args, sort_order);
+
+ request->ForwardResult(request->handle(), statement, statement);
+}
+
+#endif // defined(OS_ANDROID)
+
// Downloads -------------------------------------------------------------------
void HistoryBackend::GetNextDownloadId(

Powered by Google App Engine
This is Rietveld 408576698