OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/history/android/android_history_provider_service.h" | 5 #include "chrome/browser/history/android/android_history_provider_service.h" |
6 | 6 |
7 #include "chrome/browser/history/history_backend.h" | 7 #include "chrome/browser/history/history_backend.h" |
8 #include "chrome/browser/history/history_service.h" | 8 #include "chrome/browser/history/history_service.h" |
9 #include "chrome/browser/history/history_service_factory.h" | 9 #include "chrome/browser/history/history_service_factory.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 | 11 |
12 using history::HistoryBackend; | 12 using history::HistoryBackend; |
13 | 13 |
14 AndroidHistoryProviderService::AndroidHistoryProviderService(Profile* profile) | 14 AndroidHistoryProviderService::AndroidHistoryProviderService(Profile* profile) |
15 : profile_(profile) { | 15 : profile_(profile) { |
16 } | 16 } |
17 | 17 |
18 AndroidHistoryProviderService::~AndroidHistoryProviderService() { | 18 AndroidHistoryProviderService::~AndroidHistoryProviderService() { |
19 } | 19 } |
20 | 20 |
21 AndroidHistoryProviderService::Handle | 21 base::CancelableTaskTracker::TaskId |
22 AndroidHistoryProviderService::QueryHistoryAndBookmarks( | 22 AndroidHistoryProviderService::QueryHistoryAndBookmarks( |
23 const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections, | 23 const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections, |
24 const std::string& selection, | 24 const std::string& selection, |
25 const std::vector<base::string16>& selection_args, | 25 const std::vector<base::string16>& selection_args, |
26 const std::string& sort_order, | 26 const std::string& sort_order, |
27 CancelableRequestConsumerBase* consumer, | 27 const QueryCallback& callback, |
28 const QueryCallback& callback) { | 28 base::CancelableTaskTracker* tracker) { |
29 QueryRequest* request = new QueryRequest(callback); | |
30 AddRequest(request, consumer); | |
31 HistoryService* hs = | 29 HistoryService* hs = |
32 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 30 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
33 if (hs) { | 31 if (hs) { |
34 hs->Schedule(HistoryService::PRIORITY_NORMAL, | 32 DCHECK(hs->thread_) << "History service being called after cleanup"; |
35 &HistoryBackend::QueryHistoryAndBookmarks, NULL, request, | 33 DCHECK(hs->thread_checker_.CalledOnValidThread()); |
36 projections, selection, selection_args, sort_order); | 34 return tracker->PostTaskAndReplyWithResult( |
| 35 hs->thread_->message_loop_proxy().get(), |
| 36 FROM_HERE, |
| 37 base::Bind(&HistoryBackend::QueryHistoryAndBookmarks, |
| 38 hs->history_backend_.get(), |
| 39 projections, |
| 40 selection, |
| 41 selection_args, |
| 42 sort_order), |
| 43 callback); |
37 } else { | 44 } else { |
38 request->ForwardResultAsync(request->handle(), false, 0); | 45 callback.Run(NULL); |
| 46 return base::CancelableTaskTracker::kBadTaskId; |
39 } | 47 } |
40 return request->handle(); | |
41 } | 48 } |
42 | 49 |
43 AndroidHistoryProviderService::Handle | 50 AndroidHistoryProviderService::Handle |
44 AndroidHistoryProviderService::UpdateHistoryAndBookmarks( | 51 AndroidHistoryProviderService::UpdateHistoryAndBookmarks( |
45 const history::HistoryAndBookmarkRow& row, | 52 const history::HistoryAndBookmarkRow& row, |
46 const std::string& selection, | 53 const std::string& selection, |
47 const std::vector<base::string16>& selection_args, | 54 const std::vector<base::string16>& selection_args, |
48 CancelableRequestConsumerBase* consumer, | 55 CancelableRequestConsumerBase* consumer, |
49 const UpdateCallback& callback) { | 56 const UpdateCallback& callback) { |
50 UpdateRequest* request = new UpdateRequest(callback); | 57 UpdateRequest* request = new UpdateRequest(callback); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 if (hs) { | 211 if (hs) { |
205 hs->Schedule(HistoryService::PRIORITY_NORMAL, | 212 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
206 &HistoryBackend::DeleteSearchTerms, NULL, request, selection, | 213 &HistoryBackend::DeleteSearchTerms, NULL, request, selection, |
207 selection_args); | 214 selection_args); |
208 } else { | 215 } else { |
209 request->ForwardResultAsync(request->handle(), false, 0); | 216 request->ForwardResultAsync(request->handle(), false, 0); |
210 } | 217 } |
211 return request->handle(); | 218 return request->handle(); |
212 } | 219 } |
213 | 220 |
214 AndroidHistoryProviderService::Handle | 221 base::CancelableTaskTracker::TaskId |
215 AndroidHistoryProviderService::QuerySearchTerms( | 222 AndroidHistoryProviderService::QuerySearchTerms( |
216 const std::vector<history::SearchRow::ColumnID>& projections, | 223 const std::vector<history::SearchRow::ColumnID>& projections, |
217 const std::string& selection, | 224 const std::string& selection, |
218 const std::vector<base::string16>& selection_args, | 225 const std::vector<base::string16>& selection_args, |
219 const std::string& sort_order, | 226 const std::string& sort_order, |
220 CancelableRequestConsumerBase* consumer, | 227 const QueryCallback& callback, |
221 const QueryCallback& callback) { | 228 base::CancelableTaskTracker* tracker) { |
222 QueryRequest* request = new QueryRequest(callback); | |
223 AddRequest(request, consumer); | |
224 HistoryService* hs = | 229 HistoryService* hs = |
225 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 230 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
226 if (hs) { | 231 if (hs) { |
227 hs->Schedule(HistoryService::PRIORITY_NORMAL, | 232 DCHECK(hs->thread_) << "History service being called after cleanup"; |
228 &HistoryBackend::QuerySearchTerms, NULL, request, projections, | 233 DCHECK(hs->thread_checker_.CalledOnValidThread()); |
229 selection, selection_args, sort_order); | 234 return tracker->PostTaskAndReplyWithResult( |
| 235 hs->thread_->message_loop_proxy().get(), |
| 236 FROM_HERE, |
| 237 base::Bind(&HistoryBackend::QuerySearchTerms, |
| 238 hs->history_backend_.get(), |
| 239 projections, |
| 240 selection, |
| 241 selection_args, |
| 242 sort_order), |
| 243 callback); |
230 } else { | 244 } else { |
231 request->ForwardResultAsync(request->handle(), false, 0); | 245 callback.Run(NULL); |
| 246 return base::CancelableTaskTracker::kBadTaskId; |
232 } | 247 } |
233 return request->handle(); | |
234 } | 248 } |
OLD | NEW |