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
3 // found in the LICENSE file.
5 #include "chrome/browser/history/history_backend.h"
7 #include "chrome/browser/history/android/android_provider_backend.h"
11 void HistoryBackend::InsertHistoryAndBookmark(
12 scoped_refptr<InsertRequest> request,
13 const HistoryAndBookmarkRow& row) {
14 if (request->canceled())
18 if (android_provider_backend_)
19 id = android_provider_backend_->InsertHistoryAndBookmark(row);
21 request->ForwardResult(request->handle(), id != 0, id);
24 void HistoryBackend::QueryHistoryAndBookmarks(
25 scoped_refptr<QueryRequest> request,
26 const std::vector<HistoryAndBookmarkRow::ColumnID>& projections,
27 const std::string& selection,
28 const std::vector<string16>& selection_args,
29 const std::string& sort_order) {
30 if (request->canceled())
33 AndroidStatement* statement = NULL;
34 if (android_provider_backend_) {
35 statement = android_provider_backend_->QueryHistoryAndBookmarks(
36 projections, selection, selection_args, sort_order);
38 request->ForwardResult(request->handle(), statement, statement);
41 void HistoryBackend::UpdateHistoryAndBookmarks(
42 scoped_refptr<UpdateRequest> request,
43 const HistoryAndBookmarkRow& row,
44 const std::string& selection,
45 const std::vector<string16>& selection_args) {
46 if (request->canceled())
51 if (android_provider_backend_) {
52 result = android_provider_backend_->UpdateHistoryAndBookmarks(row,
53 selection, selection_args, &count);
56 request->ForwardResult(request->handle(), result, count);
59 void HistoryBackend::DeleteHistoryAndBookmarks(
60 scoped_refptr<DeleteRequest> request,
61 const std::string& selection,
62 const std::vector<string16>& selection_args) {
63 if (request->canceled())
68 if (android_provider_backend_)
69 result = android_provider_backend_->DeleteHistoryAndBookmarks(selection,
70 selection_args, &count);
72 request->ForwardResult(request->handle(), result, count);
75 void HistoryBackend::DeleteHistory(
76 scoped_refptr<DeleteRequest> request,
77 const std::string& selection,
78 const std::vector<string16>& selection_args) {
79 if (request->canceled())
84 if (android_provider_backend_) {
85 result = android_provider_backend_->DeleteHistory(selection, selection_args,
88 request->ForwardResult(request->handle(), result, count);
91 // Statement -------------------------------------------------------------------
93 void HistoryBackend::MoveStatement(
94 scoped_refptr<MoveStatementRequest> request,
95 history::AndroidStatement* statement,
98 DCHECK_LE(-1, current_pos);
99 DCHECK_LE(-1, destination);
101 int cur = current_pos;
102 if (current_pos > destination) {
103 statement->statement()->Reset(false);
106 for (; cur < destination; ++cur) {
107 if (!statement->statement()->Step())
111 request->ForwardResult(request->handle(), cur);
114 void HistoryBackend::CloseStatement(AndroidStatement* statement) {
118 // Search Term -----------------------------------------------------------------
120 void HistoryBackend::InsertSearchTerm(scoped_refptr<InsertRequest> request,
121 const SearchRow& row) {
122 if (request->canceled())
126 if (android_provider_backend_)
127 id = android_provider_backend_->InsertSearchTerm(row);
129 request->ForwardResult(request->handle(), id != 0, id);
132 void HistoryBackend::UpdateSearchTerms(
133 scoped_refptr<UpdateRequest> request,
134 const SearchRow& row,
135 const std::string& selection,
136 const std::vector<string16> selection_args) {
137 if (request->canceled())
142 if (android_provider_backend_) {
143 result = android_provider_backend_->UpdateSearchTerms(row, selection,
144 selection_args, &count);
146 request->ForwardResult(request->handle(), result, count);
149 void HistoryBackend::DeleteSearchTerms(
150 scoped_refptr<DeleteRequest> request,
151 const std::string& selection,
152 const std::vector<string16> selection_args) {
153 if (request->canceled())
158 if (android_provider_backend_) {
159 result = android_provider_backend_->DeleteSearchTerms(selection,
160 selection_args, &count);
163 request->ForwardResult(request->handle(), result, count);
166 void HistoryBackend::QuerySearchTerms(
167 scoped_refptr<QueryRequest> request,
168 const std::vector<SearchRow::ColumnID>& projections,
169 const std::string& selection,
170 const std::vector<string16>& selection_args,
171 const std::string& sort_order) {
172 if (request->canceled())
175 AndroidStatement* statement = NULL;
176 if (android_provider_backend_)
177 statement = android_provider_backend_->QuerySearchTerms(projections,
178 selection, selection_args, sort_order);
180 request->ForwardResult(request->handle(), statement, statement);
183 } // namespace history