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/android/android_history_provider_service.h"
7 #include "chrome/browser/history/history_backend.h"
8 #include "chrome/browser/history/history_service.h"
9 #include "chrome/browser/history/history_service_factory.h"
10 #include "chrome/browser/profiles/profile.h"
12 using history::HistoryBackend;
14 AndroidHistoryProviderService::AndroidHistoryProviderService(Profile* profile)
18 AndroidHistoryProviderService::~AndroidHistoryProviderService() {
21 base::CancelableTaskTracker::TaskId
22 AndroidHistoryProviderService::QueryHistoryAndBookmarks(
23 const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections,
24 const std::string& selection,
25 const std::vector<base::string16>& selection_args,
26 const std::string& sort_order,
27 const QueryCallback& callback,
28 base::CancelableTaskTracker* tracker) {
30 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
32 DCHECK(hs->thread_) << "History service being called after cleanup";
33 DCHECK(hs->thread_checker_.CalledOnValidThread());
34 return tracker->PostTaskAndReplyWithResult(
35 hs->thread_->message_loop_proxy().get(),
37 base::Bind(&HistoryBackend::QueryHistoryAndBookmarks,
38 hs->history_backend_.get(),
46 return base::CancelableTaskTracker::kBadTaskId;
50 base::CancelableTaskTracker::TaskId
51 AndroidHistoryProviderService::UpdateHistoryAndBookmarks(
52 const history::HistoryAndBookmarkRow& row,
53 const std::string& selection,
54 const std::vector<base::string16>& selection_args,
55 const UpdateCallback& callback,
56 base::CancelableTaskTracker* tracker) {
58 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
60 DCHECK(hs->thread_) << "History service being called after cleanup";
61 DCHECK(hs->thread_checker_.CalledOnValidThread());
62 return tracker->PostTaskAndReplyWithResult(
63 hs->thread_->message_loop_proxy().get(),
65 base::Bind(&HistoryBackend::UpdateHistoryAndBookmarks,
66 hs->history_backend_.get(),
73 return base::CancelableTaskTracker::kBadTaskId;
77 base::CancelableTaskTracker::TaskId
78 AndroidHistoryProviderService::DeleteHistoryAndBookmarks(
79 const std::string& selection,
80 const std::vector<base::string16>& selection_args,
81 const DeleteCallback& callback,
82 base::CancelableTaskTracker* tracker) {
84 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
86 DCHECK(hs->thread_) << "History service being called after cleanup";
87 DCHECK(hs->thread_checker_.CalledOnValidThread());
88 return tracker->PostTaskAndReplyWithResult(
89 hs->thread_->message_loop_proxy().get(),
91 base::Bind(&HistoryBackend::DeleteHistoryAndBookmarks,
92 hs->history_backend_.get(),
98 return base::CancelableTaskTracker::kBadTaskId;
102 base::CancelableTaskTracker::TaskId
103 AndroidHistoryProviderService::InsertHistoryAndBookmark(
104 const history::HistoryAndBookmarkRow& values,
105 const InsertCallback& callback,
106 base::CancelableTaskTracker* tracker) {
108 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
110 DCHECK(hs->thread_) << "History service being called after cleanup";
111 DCHECK(hs->thread_checker_.CalledOnValidThread());
112 return tracker->PostTaskAndReplyWithResult(
113 hs->thread_->message_loop_proxy().get(),
115 base::Bind(&HistoryBackend::InsertHistoryAndBookmark,
116 hs->history_backend_.get(),
121 return base::CancelableTaskTracker::kBadTaskId;
125 base::CancelableTaskTracker::TaskId
126 AndroidHistoryProviderService::DeleteHistory(
127 const std::string& selection,
128 const std::vector<base::string16>& selection_args,
129 const DeleteCallback& callback,
130 base::CancelableTaskTracker* tracker) {
132 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
134 DCHECK(hs->thread_) << "History service being called after cleanup";
135 DCHECK(hs->thread_checker_.CalledOnValidThread());
136 return tracker->PostTaskAndReplyWithResult(
137 hs->thread_->message_loop_proxy().get(),
139 base::Bind(&HistoryBackend::DeleteHistory,
140 hs->history_backend_.get(),
146 return base::CancelableTaskTracker::kBadTaskId;
150 base::CancelableTaskTracker::TaskId
151 AndroidHistoryProviderService::MoveStatement(
152 history::AndroidStatement* statement,
155 const MoveStatementCallback& callback,
156 base::CancelableTaskTracker* tracker) {
158 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
160 DCHECK(hs->thread_) << "History service being called after cleanup";
161 DCHECK(hs->thread_checker_.CalledOnValidThread());
162 return tracker->PostTaskAndReplyWithResult(
163 hs->thread_->message_loop_proxy().get(),
165 base::Bind(&HistoryBackend::MoveStatement,
166 hs->history_backend_.get(),
172 callback.Run(current_pos);
173 return base::CancelableTaskTracker::kBadTaskId;
177 void AndroidHistoryProviderService::CloseStatement(
178 history::AndroidStatement* statement) {
180 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
182 hs->ScheduleAndForget(HistoryService::PRIORITY_NORMAL,
183 &HistoryBackend::CloseStatement, statement);
189 base::CancelableTaskTracker::TaskId
190 AndroidHistoryProviderService::InsertSearchTerm(
191 const history::SearchRow& row,
192 const InsertCallback& callback,
193 base::CancelableTaskTracker* tracker) {
195 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
197 DCHECK(hs->thread_) << "History service being called after cleanup";
198 DCHECK(hs->thread_checker_.CalledOnValidThread());
199 return tracker->PostTaskAndReplyWithResult(
200 hs->thread_->message_loop_proxy().get(),
203 &HistoryBackend::InsertSearchTerm, hs->history_backend_.get(), row),
207 return base::CancelableTaskTracker::kBadTaskId;
211 base::CancelableTaskTracker::TaskId
212 AndroidHistoryProviderService::UpdateSearchTerms(
213 const history::SearchRow& row,
214 const std::string& selection,
215 const std::vector<base::string16>& selection_args,
216 const UpdateCallback& callback,
217 base::CancelableTaskTracker* tracker) {
219 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
221 DCHECK(hs->thread_) << "History service being called after cleanup";
222 DCHECK(hs->thread_checker_.CalledOnValidThread());
223 return tracker->PostTaskAndReplyWithResult(
224 hs->thread_->message_loop_proxy().get(),
226 base::Bind(&HistoryBackend::UpdateSearchTerms,
227 hs->history_backend_.get(),
234 return base::CancelableTaskTracker::kBadTaskId;
238 base::CancelableTaskTracker::TaskId
239 AndroidHistoryProviderService::DeleteSearchTerms(
240 const std::string& selection,
241 const std::vector<base::string16>& selection_args,
242 const DeleteCallback& callback,
243 base::CancelableTaskTracker* tracker) {
245 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
247 DCHECK(hs->thread_) << "History service being called after cleanup";
248 DCHECK(hs->thread_checker_.CalledOnValidThread());
249 return tracker->PostTaskAndReplyWithResult(
250 hs->thread_->message_loop_proxy().get(),
252 base::Bind(&HistoryBackend::DeleteSearchTerms,
253 hs->history_backend_.get(),
259 return base::CancelableTaskTracker::kBadTaskId;
263 base::CancelableTaskTracker::TaskId
264 AndroidHistoryProviderService::QuerySearchTerms(
265 const std::vector<history::SearchRow::ColumnID>& projections,
266 const std::string& selection,
267 const std::vector<base::string16>& selection_args,
268 const std::string& sort_order,
269 const QueryCallback& callback,
270 base::CancelableTaskTracker* tracker) {
272 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
274 DCHECK(hs->thread_) << "History service being called after cleanup";
275 DCHECK(hs->thread_checker_.CalledOnValidThread());
276 return tracker->PostTaskAndReplyWithResult(
277 hs->thread_->message_loop_proxy().get(),
279 base::Bind(&HistoryBackend::QuerySearchTerms,
280 hs->history_backend_.get(),
288 return base::CancelableTaskTracker::kBadTaskId;