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/favicon/favicon_service.h"
8 #include "chrome/browser/favicon/favicon_service_factory.h"
9 #include "chrome/browser/history/history_backend.h"
10 #include "chrome/browser/history/history_service.h"
11 #include "chrome/browser/history/history_service_factory.h"
12 #include "chrome/browser/profiles/profile.h"
14 using history::HistoryBackend;
16 AndroidHistoryProviderService::AndroidHistoryProviderService(Profile* profile)
20 AndroidHistoryProviderService::~AndroidHistoryProviderService() {
23 base::CancelableTaskTracker::TaskId
24 AndroidHistoryProviderService::QueryHistoryAndBookmarks(
25 const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections,
26 const std::string& selection,
27 const std::vector<base::string16>& selection_args,
28 const std::string& sort_order,
29 const QueryCallback& callback,
30 base::CancelableTaskTracker* tracker) {
32 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
34 DCHECK(hs->thread_) << "History service being called after cleanup";
35 DCHECK(hs->thread_checker_.CalledOnValidThread());
36 return tracker->PostTaskAndReplyWithResult(
37 hs->thread_->message_loop_proxy().get(),
39 base::Bind(&HistoryBackend::QueryHistoryAndBookmarks,
40 hs->history_backend_.get(),
48 return base::CancelableTaskTracker::kBadTaskId;
52 base::CancelableTaskTracker::TaskId
53 AndroidHistoryProviderService::UpdateHistoryAndBookmarks(
54 const history::HistoryAndBookmarkRow& row,
55 const std::string& selection,
56 const std::vector<base::string16>& selection_args,
57 const UpdateCallback& callback,
58 base::CancelableTaskTracker* tracker) {
60 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
62 DCHECK(hs->thread_) << "History service being called after cleanup";
63 DCHECK(hs->thread_checker_.CalledOnValidThread());
64 return tracker->PostTaskAndReplyWithResult(
65 hs->thread_->message_loop_proxy().get(),
67 base::Bind(&HistoryBackend::UpdateHistoryAndBookmarks,
68 hs->history_backend_.get(),
75 return base::CancelableTaskTracker::kBadTaskId;
79 base::CancelableTaskTracker::TaskId
80 AndroidHistoryProviderService::DeleteHistoryAndBookmarks(
81 const std::string& selection,
82 const std::vector<base::string16>& selection_args,
83 const DeleteCallback& callback,
84 base::CancelableTaskTracker* tracker) {
86 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
88 DCHECK(hs->thread_) << "History service being called after cleanup";
89 DCHECK(hs->thread_checker_.CalledOnValidThread());
90 return tracker->PostTaskAndReplyWithResult(
91 hs->thread_->message_loop_proxy().get(),
93 base::Bind(&HistoryBackend::DeleteHistoryAndBookmarks,
94 hs->history_backend_.get(),
100 return base::CancelableTaskTracker::kBadTaskId;
104 base::CancelableTaskTracker::TaskId
105 AndroidHistoryProviderService::InsertHistoryAndBookmark(
106 const history::HistoryAndBookmarkRow& values,
107 const InsertCallback& callback,
108 base::CancelableTaskTracker* tracker) {
110 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
112 DCHECK(hs->thread_) << "History service being called after cleanup";
113 DCHECK(hs->thread_checker_.CalledOnValidThread());
114 return tracker->PostTaskAndReplyWithResult(
115 hs->thread_->message_loop_proxy().get(),
117 base::Bind(&HistoryBackend::InsertHistoryAndBookmark,
118 hs->history_backend_.get(),
123 return base::CancelableTaskTracker::kBadTaskId;
127 base::CancelableTaskTracker::TaskId
128 AndroidHistoryProviderService::DeleteHistory(
129 const std::string& selection,
130 const std::vector<base::string16>& selection_args,
131 const DeleteCallback& callback,
132 base::CancelableTaskTracker* tracker) {
134 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
136 DCHECK(hs->thread_) << "History service being called after cleanup";
137 DCHECK(hs->thread_checker_.CalledOnValidThread());
138 return tracker->PostTaskAndReplyWithResult(
139 hs->thread_->message_loop_proxy().get(),
141 base::Bind(&HistoryBackend::DeleteHistory,
142 hs->history_backend_.get(),
148 return base::CancelableTaskTracker::kBadTaskId;
152 base::CancelableTaskTracker::TaskId
153 AndroidHistoryProviderService::MoveStatement(
154 history::AndroidStatement* statement,
157 const MoveStatementCallback& callback,
158 base::CancelableTaskTracker* tracker) {
160 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
162 DCHECK(hs->thread_) << "History service being called after cleanup";
163 DCHECK(hs->thread_checker_.CalledOnValidThread());
164 return tracker->PostTaskAndReplyWithResult(
165 hs->thread_->message_loop_proxy().get(),
167 base::Bind(&HistoryBackend::MoveStatement,
168 hs->history_backend_.get(),
174 callback.Run(current_pos);
175 return base::CancelableTaskTracker::kBadTaskId;
179 void AndroidHistoryProviderService::CloseStatement(
180 history::AndroidStatement* statement) {
182 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
184 hs->ScheduleAndForget(HistoryService::PRIORITY_NORMAL,
185 &HistoryBackend::CloseStatement, statement);
191 base::CancelableTaskTracker::TaskId
192 AndroidHistoryProviderService::InsertSearchTerm(
193 const history::SearchRow& row,
194 const InsertCallback& callback,
195 base::CancelableTaskTracker* tracker) {
197 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
199 DCHECK(hs->thread_) << "History service being called after cleanup";
200 DCHECK(hs->thread_checker_.CalledOnValidThread());
201 return tracker->PostTaskAndReplyWithResult(
202 hs->thread_->message_loop_proxy().get(),
205 &HistoryBackend::InsertSearchTerm, hs->history_backend_.get(), row),
209 return base::CancelableTaskTracker::kBadTaskId;
213 base::CancelableTaskTracker::TaskId
214 AndroidHistoryProviderService::UpdateSearchTerms(
215 const history::SearchRow& row,
216 const std::string& selection,
217 const std::vector<base::string16>& selection_args,
218 const UpdateCallback& callback,
219 base::CancelableTaskTracker* tracker) {
221 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
223 DCHECK(hs->thread_) << "History service being called after cleanup";
224 DCHECK(hs->thread_checker_.CalledOnValidThread());
225 return tracker->PostTaskAndReplyWithResult(
226 hs->thread_->message_loop_proxy().get(),
228 base::Bind(&HistoryBackend::UpdateSearchTerms,
229 hs->history_backend_.get(),
236 return base::CancelableTaskTracker::kBadTaskId;
240 base::CancelableTaskTracker::TaskId
241 AndroidHistoryProviderService::DeleteSearchTerms(
242 const std::string& selection,
243 const std::vector<base::string16>& selection_args,
244 const DeleteCallback& callback,
245 base::CancelableTaskTracker* tracker) {
247 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
249 DCHECK(hs->thread_) << "History service being called after cleanup";
250 DCHECK(hs->thread_checker_.CalledOnValidThread());
251 return tracker->PostTaskAndReplyWithResult(
252 hs->thread_->message_loop_proxy().get(),
254 base::Bind(&HistoryBackend::DeleteSearchTerms,
255 hs->history_backend_.get(),
261 return base::CancelableTaskTracker::kBadTaskId;
265 base::CancelableTaskTracker::TaskId
266 AndroidHistoryProviderService::QuerySearchTerms(
267 const std::vector<history::SearchRow::ColumnID>& projections,
268 const std::string& selection,
269 const std::vector<base::string16>& selection_args,
270 const std::string& sort_order,
271 const QueryCallback& callback,
272 base::CancelableTaskTracker* tracker) {
274 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
276 DCHECK(hs->thread_) << "History service being called after cleanup";
277 DCHECK(hs->thread_checker_.CalledOnValidThread());
278 return tracker->PostTaskAndReplyWithResult(
279 hs->thread_->message_loop_proxy().get(),
281 base::Bind(&HistoryBackend::QuerySearchTerms,
282 hs->history_backend_.get(),
290 return base::CancelableTaskTracker::kBadTaskId;
294 base::CancelableTaskTracker::TaskId
295 AndroidHistoryProviderService::GetLargestRawFaviconForID(
296 favicon_base::FaviconID favicon_id,
297 const favicon_base::FaviconRawBitmapCallback& callback,
298 base::CancelableTaskTracker* tracker) {
300 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
302 return fs->GetLargestRawFaviconForID(favicon_id, callback, tracker);