| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/history/android/android_history_provider_service.h" |
| 6 |
| 7 #include "chrome/browser/history/history.h" |
| 8 #include "chrome/browser/history/history_backend.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 |
| 11 using history::HistoryBackend; |
| 12 |
| 13 AndroidHistoryProviderService::AndroidHistoryProviderService(Profile* profile) |
| 14 : profile_(profile) { |
| 15 } |
| 16 |
| 17 AndroidHistoryProviderService::~AndroidHistoryProviderService() { |
| 18 } |
| 19 |
| 20 AndroidHistoryProviderService::Handle |
| 21 AndroidHistoryProviderService::QueryHistoryAndBookmarks( |
| 22 const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections, |
| 23 const std::string& selection, |
| 24 const std::vector<string16>& selection_args, |
| 25 const std::string& sort_order, |
| 26 CancelableRequestConsumerBase* consumer, |
| 27 const QueryCallback& callback) { |
| 28 QueryRequest* request = new QueryRequest(callback); |
| 29 AddRequest(request, consumer); |
| 30 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 31 if (hs) { |
| 32 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
| 33 &HistoryBackend::QueryHistoryAndBookmarks, NULL, request, |
| 34 projections, selection, selection_args, sort_order); |
| 35 } else { |
| 36 request->ForwardResultAsync(request->handle(), false, 0); |
| 37 } |
| 38 return request->handle(); |
| 39 } |
| 40 |
| 41 AndroidHistoryProviderService::Handle |
| 42 AndroidHistoryProviderService::UpdateHistoryAndBookmarks( |
| 43 const history::HistoryAndBookmarkRow& row, |
| 44 const std::string& selection, |
| 45 const std::vector<string16>& selection_args, |
| 46 CancelableRequestConsumerBase* consumer, |
| 47 const UpdateCallback& callback) { |
| 48 UpdateRequest* request = new UpdateRequest(callback); |
| 49 AddRequest(request, consumer); |
| 50 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 51 if (hs) { |
| 52 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
| 53 &HistoryBackend::UpdateHistoryAndBookmarks, NULL, request, row, |
| 54 selection, selection_args); |
| 55 } else { |
| 56 request->ForwardResultAsync(request->handle(), false, 0); |
| 57 } |
| 58 return request->handle(); |
| 59 } |
| 60 |
| 61 AndroidHistoryProviderService::Handle |
| 62 AndroidHistoryProviderService::DeleteHistoryAndBookmarks( |
| 63 const std::string& selection, |
| 64 const std::vector<string16>& selection_args, |
| 65 CancelableRequestConsumerBase* consumer, |
| 66 const DeleteCallback& callback) { |
| 67 DeleteRequest* request = new DeleteRequest(callback); |
| 68 AddRequest(request, consumer); |
| 69 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 70 if (hs) { |
| 71 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
| 72 &HistoryBackend::DeleteHistoryAndBookmarks, NULL, request, |
| 73 selection, selection_args); |
| 74 } else { |
| 75 request->ForwardResultAsync(request->handle(), false, 0); |
| 76 } |
| 77 return request->handle(); |
| 78 } |
| 79 |
| 80 AndroidHistoryProviderService::Handle |
| 81 AndroidHistoryProviderService::InsertHistoryAndBookmark( |
| 82 const history::HistoryAndBookmarkRow& values, |
| 83 CancelableRequestConsumerBase* consumer, |
| 84 const InsertCallback& callback) { |
| 85 InsertRequest* request = new InsertRequest(callback); |
| 86 AddRequest(request, consumer); |
| 87 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 88 if (hs) { |
| 89 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
| 90 &HistoryBackend::InsertHistoryAndBookmark, NULL, request, values); |
| 91 } else { |
| 92 request->ForwardResultAsync(request->handle(), false, 0); |
| 93 } |
| 94 return request->handle(); |
| 95 } |
| 96 |
| 97 AndroidHistoryProviderService::Handle |
| 98 AndroidHistoryProviderService::DeleteHistory( |
| 99 const std::string& selection, |
| 100 const std::vector<string16>& selection_args, |
| 101 CancelableRequestConsumerBase* consumer, |
| 102 const DeleteCallback& callback) { |
| 103 DeleteRequest* request = new DeleteRequest(callback); |
| 104 AddRequest(request, consumer); |
| 105 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 106 if (hs) { |
| 107 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
| 108 &HistoryBackend::DeleteHistory, NULL, request, selection, |
| 109 selection_args); |
| 110 } else { |
| 111 request->ForwardResultAsync(request->handle(), false, 0); |
| 112 } |
| 113 return request->handle(); |
| 114 } |
| 115 |
| 116 AndroidHistoryProviderService::Handle |
| 117 AndroidHistoryProviderService::MoveStatement( |
| 118 history::AndroidStatement* statement, |
| 119 int current_pos, |
| 120 int destination, |
| 121 CancelableRequestConsumerBase* consumer, |
| 122 const MoveStatementCallback& callback) { |
| 123 MoveStatementRequest* request = new MoveStatementRequest(callback); |
| 124 AddRequest(request, consumer); |
| 125 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 126 if (hs) { |
| 127 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
| 128 &HistoryBackend::MoveStatement, NULL, request, statement, |
| 129 current_pos, destination); |
| 130 } else { |
| 131 request->ForwardResultAsync(request->handle(), current_pos); |
| 132 } |
| 133 return request->handle(); |
| 134 } |
| 135 |
| 136 void AndroidHistoryProviderService::CloseStatement( |
| 137 history::AndroidStatement* statement) { |
| 138 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 139 if (hs) { |
| 140 hs->ScheduleAndForget(HistoryService::PRIORITY_NORMAL, |
| 141 &HistoryBackend::CloseStatement, statement); |
| 142 } else { |
| 143 delete statement; |
| 144 } |
| 145 } |
| 146 |
| 147 AndroidHistoryProviderService::Handle |
| 148 AndroidHistoryProviderService::InsertSearchTerm( |
| 149 const history::SearchRow& row, |
| 150 CancelableRequestConsumerBase* consumer, |
| 151 const InsertCallback& callback) { |
| 152 InsertRequest* request = new InsertRequest(callback); |
| 153 AddRequest(request, consumer); |
| 154 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 155 if (hs) { |
| 156 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
| 157 &HistoryBackend::InsertSearchTerm, NULL, request, row); |
| 158 } else { |
| 159 request->ForwardResultAsync(request->handle(), false, 0); |
| 160 } |
| 161 return request->handle(); |
| 162 } |
| 163 |
| 164 AndroidHistoryProviderService::Handle |
| 165 AndroidHistoryProviderService::UpdateSearchTerms( |
| 166 const history::SearchRow& row, |
| 167 const std::string& selection, |
| 168 const std::vector<string16>& selection_args, |
| 169 CancelableRequestConsumerBase* consumer, |
| 170 const UpdateCallback& callback) { |
| 171 UpdateRequest* request = new UpdateRequest(callback); |
| 172 AddRequest(request, consumer); |
| 173 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 174 if (hs) { |
| 175 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
| 176 &HistoryBackend::UpdateSearchTerms, NULL, request, row, selection, |
| 177 selection_args); |
| 178 } else { |
| 179 request->ForwardResultAsync(request->handle(), false, 0); |
| 180 } |
| 181 return request->handle(); |
| 182 } |
| 183 |
| 184 AndroidHistoryProviderService::Handle |
| 185 AndroidHistoryProviderService::DeleteSearchTerms( |
| 186 const std::string& selection, |
| 187 const std::vector<string16>& selection_args, |
| 188 CancelableRequestConsumerBase* consumer, |
| 189 const DeleteCallback& callback) { |
| 190 DeleteRequest* request = new DeleteRequest(callback); |
| 191 AddRequest(request, consumer); |
| 192 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 193 if (hs) { |
| 194 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
| 195 &HistoryBackend::DeleteSearchTerms, NULL, request, selection, |
| 196 selection_args); |
| 197 } else { |
| 198 request->ForwardResultAsync(request->handle(), false, 0); |
| 199 } |
| 200 return request->handle(); |
| 201 } |
| 202 |
| 203 AndroidHistoryProviderService::Handle |
| 204 AndroidHistoryProviderService::QuerySearchTerms( |
| 205 const std::vector<history::SearchRow::ColumnID>& projections, |
| 206 const std::string& selection, |
| 207 const std::vector<string16>& selection_args, |
| 208 const std::string& sort_order, |
| 209 CancelableRequestConsumerBase* consumer, |
| 210 const QueryCallback& callback) { |
| 211 QueryRequest* request = new QueryRequest(callback); |
| 212 AddRequest(request, consumer); |
| 213 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 214 if (hs) { |
| 215 hs->Schedule(HistoryService::PRIORITY_NORMAL, |
| 216 &HistoryBackend::QuerySearchTerms, NULL, request, projections, |
| 217 selection, selection_args, sort_order); |
| 218 } else { |
| 219 request->ForwardResultAsync(request->handle(), false, 0); |
| 220 } |
| 221 return request->handle(); |
| 222 } |
| OLD | NEW |