| 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/favicon/favicon_service.h" | 7 #include "chrome/browser/favicon/favicon_service.h" |
| 8 #include "chrome/browser/favicon/favicon_service_factory.h" | 8 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 9 #include "chrome/browser/history/android/android_provider_backend.h" |
| 9 #include "chrome/browser/history/history_backend.h" | 10 #include "chrome/browser/history/history_backend.h" |
| 10 #include "chrome/browser/history/history_service.h" | 11 #include "chrome/browser/history/history_service.h" |
| 11 #include "chrome/browser/history/history_service_factory.h" | 12 #include "chrome/browser/history/history_service_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 | 14 #include "components/history/core/browser/android/android_history_types.h" |
| 14 using history::HistoryBackend; | 15 #include "components/history/core/browser/history_db_task.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 // AndroidProviderTask wraps two callbacks into an HistoryDBTask so that they |
| 20 // can be passed to HistoryService::ScheduleDBTask. ResultType must be zero |
| 21 // constructible (i.e. ResultType(0) should build an initialized default value) |
| 22 // and copyable. |
| 23 template <typename ResultType> |
| 24 class AndroidProviderTask : public history::HistoryDBTask { |
| 25 public: |
| 26 typedef base::Callback<ResultType(history::AndroidProviderBackend*)> |
| 27 RequestCallback; |
| 28 typedef base::Callback<void(ResultType)> ResultCallback; |
| 29 |
| 30 AndroidProviderTask(const RequestCallback& request_cb, |
| 31 const ResultCallback& result_cb) |
| 32 : request_cb_(request_cb), result_cb_(result_cb), result_(0) { |
| 33 DCHECK(!request_cb_.is_null()); |
| 34 DCHECK(!result_cb_.is_null()); |
| 35 } |
| 36 |
| 37 ~AndroidProviderTask() override {} |
| 38 |
| 39 private: |
| 40 // history::HistoryDBTask implementation. |
| 41 bool RunOnDBThread(history::HistoryBackend* backend, |
| 42 history::HistoryDatabase* db) override { |
| 43 if (backend->android_provider_backend()) |
| 44 result_ = request_cb_.Run(backend->android_provider_backend()); |
| 45 return true; |
| 46 } |
| 47 |
| 48 void DoneRunOnMainThread() override { result_cb_.Run(result_); } |
| 49 |
| 50 RequestCallback request_cb_; |
| 51 ResultCallback result_cb_; |
| 52 ResultType result_; |
| 53 }; |
| 54 |
| 55 // Creates an instance of AndroidProviderTask using the two callback and using |
| 56 // type deduction. |
| 57 template <typename ResultType> |
| 58 scoped_ptr<history::HistoryDBTask> CreateAndroidProviderTask( |
| 59 const base::Callback<ResultType(history::AndroidProviderBackend*)>& |
| 60 request_cb, |
| 61 const base::Callback<void(ResultType)>& result_cb) { |
| 62 return scoped_ptr<history::HistoryDBTask>( |
| 63 new AndroidProviderTask<ResultType>(request_cb, result_cb)); |
| 64 } |
| 65 |
| 66 // History and bookmarks ---------------------------------------------------- |
| 67 |
| 68 // Inserts the given values into android provider backend. |
| 69 history::AndroidURLID InsertHistoryAndBookmarkAdapter( |
| 70 const history::HistoryAndBookmarkRow& row, |
| 71 history::AndroidProviderBackend* backend) { |
| 72 return backend->InsertHistoryAndBookmark(row); |
| 73 } |
| 74 |
| 75 // Runs the given query on android provider backend and returns the result. |
| 76 // |
| 77 // |projections| is the vector of the result columns. |
| 78 // |selection| is the SQL WHERE clause without 'WHERE'. |
| 79 // |selection_args| is the arguments for WHERE clause. |
| 80 // |sort_order| is the SQL ORDER clause. |
| 81 history::AndroidStatement* QueryHistoryAndBookmarksAdapter( |
| 82 const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections, |
| 83 const std::string& selection, |
| 84 const std::vector<base::string16>& selection_args, |
| 85 const std::string& sort_order, |
| 86 history::AndroidProviderBackend* backend) { |
| 87 return backend->QueryHistoryAndBookmarks(projections, selection, |
| 88 selection_args, sort_order); |
| 89 } |
| 90 |
| 91 // Returns the number of row updated by the update query. |
| 92 // |
| 93 // |row| is the value to update. |
| 94 // |selection| is the SQL WHERE clause without 'WHERE'. |
| 95 // |selection_args| is the arguments for the WHERE clause. |
| 96 int UpdateHistoryAndBookmarksAdapter( |
| 97 const history::HistoryAndBookmarkRow& row, |
| 98 const std::string& selection, |
| 99 const std::vector<base::string16>& selection_args, |
| 100 history::AndroidProviderBackend* backend) { |
| 101 int count = 0; |
| 102 backend->UpdateHistoryAndBookmarks(row, selection, selection_args, &count); |
| 103 return count; |
| 104 } |
| 105 |
| 106 // Deletes the specified rows and returns the number of rows deleted. |
| 107 // |
| 108 // |selection| is the SQL WHERE clause without 'WHERE'. |
| 109 // |selection_args| is the arguments for the WHERE clause. |
| 110 // |
| 111 // If |selection| is empty all history and bookmarks are deleted. |
| 112 int DeleteHistoryAndBookmarksAdapter( |
| 113 const std::string& selection, |
| 114 const std::vector<base::string16>& selection_args, |
| 115 history::AndroidProviderBackend* backend) { |
| 116 int count = 0; |
| 117 backend->DeleteHistoryAndBookmarks(selection, selection_args, &count); |
| 118 return count; |
| 119 } |
| 120 |
| 121 // Deletes the matched history and returns the number of rows deleted. |
| 122 int DeleteHistoryAdapter(const std::string& selection, |
| 123 const std::vector<base::string16>& selection_args, |
| 124 history::AndroidProviderBackend* backend) { |
| 125 int count = 0; |
| 126 backend->DeleteHistory(selection, selection_args, &count); |
| 127 return count; |
| 128 } |
| 129 |
| 130 // Statement ---------------------------------------------------------------- |
| 131 |
| 132 // Move the statement's current position. |
| 133 int MoveStatementAdapter(history::AndroidStatement* statement, |
| 134 int current_pos, |
| 135 int destination, |
| 136 history::AndroidProviderBackend* backend) { |
| 137 DCHECK_LE(-1, current_pos); |
| 138 DCHECK_LE(-1, destination); |
| 139 |
| 140 int cur = current_pos; |
| 141 if (current_pos > destination) { |
| 142 statement->statement()->Reset(false); |
| 143 cur = -1; |
| 144 } |
| 145 for (; cur < destination; ++cur) { |
| 146 if (!statement->statement()->Step()) |
| 147 break; |
| 148 } |
| 149 |
| 150 return cur; |
| 151 } |
| 152 |
| 153 // CloseStatementTask delete the passed |statement| in the DB thread (or in the |
| 154 // UI thread if the HistoryBackend is destroyed before the task is executed). |
| 155 class CloseStatementTask : public history::HistoryDBTask { |
| 156 public: |
| 157 // Close the given statement. The ownership is transfered. |
| 158 explicit CloseStatementTask(history::AndroidStatement* statement) |
| 159 : statement_(statement) { |
| 160 DCHECK(statement_); |
| 161 } |
| 162 |
| 163 ~CloseStatementTask() override { delete statement_; } |
| 164 |
| 165 // Returns the cancelable task tracker to use for this task. The task owns it, |
| 166 // so it can never be cancelled. This is required due to be compatible with |
| 167 // HistoryService::ScheduleDBTask() interface. |
| 168 base::CancelableTaskTracker* tracker() { return &tracker_; } |
| 169 |
| 170 private: |
| 171 // history::HistoryDBTask implementation. |
| 172 bool RunOnDBThread(history::HistoryBackend* backend, |
| 173 history::HistoryDatabase* db) override { |
| 174 delete statement_; |
| 175 statement_ = nullptr; |
| 176 return true; |
| 177 } |
| 178 |
| 179 void DoneRunOnMainThread() override {} |
| 180 |
| 181 history::AndroidStatement* statement_; |
| 182 base::CancelableTaskTracker tracker_; |
| 183 }; |
| 184 |
| 185 // Search terms ------------------------------------------------------------- |
| 186 |
| 187 // Inserts the given values and returns the SearchTermID of the inserted row. |
| 188 history::SearchTermID InsertSearchTermAdapter( |
| 189 const history::SearchRow& row, |
| 190 history::AndroidProviderBackend* backend) { |
| 191 return backend->InsertSearchTerm(row); |
| 192 } |
| 193 |
| 194 // Returns the number of row updated by the update query. |
| 195 // |
| 196 // |row| is the value to update. |
| 197 // |selection| is the SQL WHERE clause without 'WHERE'. |
| 198 // |selection_args| is the arguments for the WHERE clause. |
| 199 int UpdateSearchTermsAdapter(const history::SearchRow& row, |
| 200 const std::string& selection, |
| 201 const std::vector<base::string16> selection_args, |
| 202 history::AndroidProviderBackend* backend) { |
| 203 int count = 0; |
| 204 backend->UpdateSearchTerms(row, selection, selection_args, &count); |
| 205 return count; |
| 206 } |
| 207 |
| 208 // Deletes the matched rows and returns the number of deleted rows. |
| 209 // |
| 210 // |selection| is the SQL WHERE clause without 'WHERE'. |
| 211 // |selection_args| is the arguments for WHERE clause. |
| 212 // |
| 213 // If |selection| is empty all search terms will be deleted. |
| 214 int DeleteSearchTermsAdapter(const std::string& selection, |
| 215 const std::vector<base::string16> selection_args, |
| 216 history::AndroidProviderBackend* backend) { |
| 217 int count = 0; |
| 218 backend->DeleteSearchTerms(selection, selection_args, &count); |
| 219 return count; |
| 220 } |
| 221 |
| 222 // Returns the result of the given query. |
| 223 // |
| 224 // |projections| specifies the result columns. |
| 225 // |selection| is the SQL WHERE clause without 'WHERE'. |
| 226 // |selection_args| is the arguments for WHERE clause. |
| 227 // |sort_order| is the SQL ORDER clause. |
| 228 history::AndroidStatement* QuerySearchTermsAdapter( |
| 229 const std::vector<history::SearchRow::ColumnID>& projections, |
| 230 const std::string& selection, |
| 231 const std::vector<base::string16>& selection_args, |
| 232 const std::string& sort_order, |
| 233 history::AndroidProviderBackend* backend) { |
| 234 return backend->QuerySearchTerms(projections, selection, selection_args, |
| 235 sort_order); |
| 236 } |
| 237 |
| 238 } // namespace |
| 15 | 239 |
| 16 AndroidHistoryProviderService::AndroidHistoryProviderService(Profile* profile) | 240 AndroidHistoryProviderService::AndroidHistoryProviderService(Profile* profile) |
| 17 : profile_(profile) { | 241 : profile_(profile) { |
| 18 } | 242 } |
| 19 | 243 |
| 20 AndroidHistoryProviderService::~AndroidHistoryProviderService() { | 244 AndroidHistoryProviderService::~AndroidHistoryProviderService() { |
| 21 } | 245 } |
| 22 | 246 |
| 23 base::CancelableTaskTracker::TaskId | 247 base::CancelableTaskTracker::TaskId |
| 24 AndroidHistoryProviderService::QueryHistoryAndBookmarks( | 248 AndroidHistoryProviderService::QueryHistoryAndBookmarks( |
| 25 const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections, | 249 const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections, |
| 26 const std::string& selection, | 250 const std::string& selection, |
| 27 const std::vector<base::string16>& selection_args, | 251 const std::vector<base::string16>& selection_args, |
| 28 const std::string& sort_order, | 252 const std::string& sort_order, |
| 29 const QueryCallback& callback, | 253 const QueryCallback& callback, |
| 30 base::CancelableTaskTracker* tracker) { | 254 base::CancelableTaskTracker* tracker) { |
| 31 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 255 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 32 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 256 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 33 if (hs) { | 257 if (!hs) { |
| 34 DCHECK(hs->thread_) << "History service being called after cleanup"; | 258 callback.Run(nullptr); |
| 35 DCHECK(hs->thread_checker_.CalledOnValidThread()); | |
| 36 return tracker->PostTaskAndReplyWithResult( | |
| 37 hs->thread_->message_loop_proxy().get(), | |
| 38 FROM_HERE, | |
| 39 base::Bind(&HistoryBackend::QueryHistoryAndBookmarks, | |
| 40 hs->history_backend_.get(), | |
| 41 projections, | |
| 42 selection, | |
| 43 selection_args, | |
| 44 sort_order), | |
| 45 callback); | |
| 46 } else { | |
| 47 callback.Run(NULL); | |
| 48 return base::CancelableTaskTracker::kBadTaskId; | 259 return base::CancelableTaskTracker::kBadTaskId; |
| 49 } | 260 } |
| 261 return hs->ScheduleDBTask( |
| 262 CreateAndroidProviderTask( |
| 263 base::Bind(&QueryHistoryAndBookmarksAdapter, projections, selection, |
| 264 selection_args, sort_order), |
| 265 callback), |
| 266 tracker); |
| 50 } | 267 } |
| 51 | 268 |
| 52 base::CancelableTaskTracker::TaskId | 269 base::CancelableTaskTracker::TaskId |
| 53 AndroidHistoryProviderService::UpdateHistoryAndBookmarks( | 270 AndroidHistoryProviderService::UpdateHistoryAndBookmarks( |
| 54 const history::HistoryAndBookmarkRow& row, | 271 const history::HistoryAndBookmarkRow& row, |
| 55 const std::string& selection, | 272 const std::string& selection, |
| 56 const std::vector<base::string16>& selection_args, | 273 const std::vector<base::string16>& selection_args, |
| 57 const UpdateCallback& callback, | 274 const UpdateCallback& callback, |
| 58 base::CancelableTaskTracker* tracker) { | 275 base::CancelableTaskTracker* tracker) { |
| 59 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 276 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 60 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 277 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 61 if (hs) { | 278 if (!hs) { |
| 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(), | |
| 66 FROM_HERE, | |
| 67 base::Bind(&HistoryBackend::UpdateHistoryAndBookmarks, | |
| 68 hs->history_backend_.get(), | |
| 69 row, | |
| 70 selection, | |
| 71 selection_args), | |
| 72 callback); | |
| 73 } else { | |
| 74 callback.Run(0); | 279 callback.Run(0); |
| 75 return base::CancelableTaskTracker::kBadTaskId; | 280 return base::CancelableTaskTracker::kBadTaskId; |
| 76 } | 281 } |
| 282 return hs->ScheduleDBTask( |
| 283 CreateAndroidProviderTask(base::Bind(&UpdateHistoryAndBookmarksAdapter, |
| 284 row, selection, selection_args), |
| 285 callback), |
| 286 tracker); |
| 77 } | 287 } |
| 78 | 288 |
| 79 base::CancelableTaskTracker::TaskId | 289 base::CancelableTaskTracker::TaskId |
| 80 AndroidHistoryProviderService::DeleteHistoryAndBookmarks( | 290 AndroidHistoryProviderService::DeleteHistoryAndBookmarks( |
| 81 const std::string& selection, | 291 const std::string& selection, |
| 82 const std::vector<base::string16>& selection_args, | 292 const std::vector<base::string16>& selection_args, |
| 83 const DeleteCallback& callback, | 293 const DeleteCallback& callback, |
| 84 base::CancelableTaskTracker* tracker) { | 294 base::CancelableTaskTracker* tracker) { |
| 85 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 295 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 86 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 296 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 87 if (hs) { | 297 if (!hs) { |
| 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(), | |
| 92 FROM_HERE, | |
| 93 base::Bind(&HistoryBackend::DeleteHistoryAndBookmarks, | |
| 94 hs->history_backend_.get(), | |
| 95 selection, | |
| 96 selection_args), | |
| 97 callback); | |
| 98 } else { | |
| 99 callback.Run(0); | 298 callback.Run(0); |
| 100 return base::CancelableTaskTracker::kBadTaskId; | 299 return base::CancelableTaskTracker::kBadTaskId; |
| 101 } | 300 } |
| 301 return hs->ScheduleDBTask( |
| 302 CreateAndroidProviderTask(base::Bind(&DeleteHistoryAndBookmarksAdapter, |
| 303 selection, selection_args), |
| 304 callback), |
| 305 tracker); |
| 102 } | 306 } |
| 103 | 307 |
| 104 base::CancelableTaskTracker::TaskId | 308 base::CancelableTaskTracker::TaskId |
| 105 AndroidHistoryProviderService::InsertHistoryAndBookmark( | 309 AndroidHistoryProviderService::InsertHistoryAndBookmark( |
| 106 const history::HistoryAndBookmarkRow& values, | 310 const history::HistoryAndBookmarkRow& values, |
| 107 const InsertCallback& callback, | 311 const InsertCallback& callback, |
| 108 base::CancelableTaskTracker* tracker) { | 312 base::CancelableTaskTracker* tracker) { |
| 109 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 313 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 110 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 314 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 111 if (hs) { | 315 if (!hs) { |
| 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(), | |
| 116 FROM_HERE, | |
| 117 base::Bind(&HistoryBackend::InsertHistoryAndBookmark, | |
| 118 hs->history_backend_.get(), | |
| 119 values), | |
| 120 callback); | |
| 121 } else { | |
| 122 callback.Run(0); | 316 callback.Run(0); |
| 123 return base::CancelableTaskTracker::kBadTaskId; | 317 return base::CancelableTaskTracker::kBadTaskId; |
| 124 } | 318 } |
| 319 return hs->ScheduleDBTask( |
| 320 CreateAndroidProviderTask( |
| 321 base::Bind(&InsertHistoryAndBookmarkAdapter, values), callback), |
| 322 tracker); |
| 125 } | 323 } |
| 126 | 324 |
| 127 base::CancelableTaskTracker::TaskId | 325 base::CancelableTaskTracker::TaskId |
| 128 AndroidHistoryProviderService::DeleteHistory( | 326 AndroidHistoryProviderService::DeleteHistory( |
| 129 const std::string& selection, | 327 const std::string& selection, |
| 130 const std::vector<base::string16>& selection_args, | 328 const std::vector<base::string16>& selection_args, |
| 131 const DeleteCallback& callback, | 329 const DeleteCallback& callback, |
| 132 base::CancelableTaskTracker* tracker) { | 330 base::CancelableTaskTracker* tracker) { |
| 133 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 331 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 134 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 332 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 135 if (hs) { | 333 if (!hs) { |
| 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(), | |
| 140 FROM_HERE, | |
| 141 base::Bind(&HistoryBackend::DeleteHistory, | |
| 142 hs->history_backend_.get(), | |
| 143 selection, | |
| 144 selection_args), | |
| 145 callback); | |
| 146 } else { | |
| 147 callback.Run(0); | 334 callback.Run(0); |
| 148 return base::CancelableTaskTracker::kBadTaskId; | 335 return base::CancelableTaskTracker::kBadTaskId; |
| 149 } | 336 } |
| 337 return hs->ScheduleDBTask( |
| 338 CreateAndroidProviderTask( |
| 339 base::Bind(&DeleteHistoryAdapter, selection, selection_args), |
| 340 callback), |
| 341 tracker); |
| 150 } | 342 } |
| 151 | 343 |
| 152 base::CancelableTaskTracker::TaskId | 344 base::CancelableTaskTracker::TaskId |
| 153 AndroidHistoryProviderService::MoveStatement( | 345 AndroidHistoryProviderService::MoveStatement( |
| 154 history::AndroidStatement* statement, | 346 history::AndroidStatement* statement, |
| 155 int current_pos, | 347 int current_pos, |
| 156 int destination, | 348 int destination, |
| 157 const MoveStatementCallback& callback, | 349 const MoveStatementCallback& callback, |
| 158 base::CancelableTaskTracker* tracker) { | 350 base::CancelableTaskTracker* tracker) { |
| 159 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 351 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 160 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 352 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 161 if (hs) { | 353 if (!hs) { |
| 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(), | |
| 166 FROM_HERE, | |
| 167 base::Bind(&HistoryBackend::MoveStatement, | |
| 168 hs->history_backend_.get(), | |
| 169 statement, | |
| 170 current_pos, | |
| 171 destination), | |
| 172 callback); | |
| 173 } else { | |
| 174 callback.Run(current_pos); | 354 callback.Run(current_pos); |
| 175 return base::CancelableTaskTracker::kBadTaskId; | 355 return base::CancelableTaskTracker::kBadTaskId; |
| 176 } | 356 } |
| 357 return hs->ScheduleDBTask( |
| 358 CreateAndroidProviderTask(base::Bind(&MoveStatementAdapter, statement, |
| 359 current_pos, destination), |
| 360 callback), |
| 361 tracker); |
| 177 } | 362 } |
| 178 | 363 |
| 179 void AndroidHistoryProviderService::CloseStatement( | 364 void AndroidHistoryProviderService::CloseStatement( |
| 180 history::AndroidStatement* statement) { | 365 history::AndroidStatement* statement) { |
| 181 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 366 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 182 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 367 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 183 if (hs) { | 368 if (!hs) { |
| 184 hs->ScheduleTask(HistoryService::PRIORITY_NORMAL, | |
| 185 base::Bind(&HistoryBackend::CloseStatement, | |
| 186 hs->history_backend_.get(), statement)); | |
| 187 } else { | |
| 188 delete statement; | 369 delete statement; |
| 370 return; |
| 189 } | 371 } |
| 372 scoped_ptr<CloseStatementTask> task(new CloseStatementTask(statement)); |
| 373 base::CancelableTaskTracker* tracker = task->tracker(); |
| 374 hs->ScheduleDBTask(task.Pass(), tracker); |
| 190 } | 375 } |
| 191 | 376 |
| 192 base::CancelableTaskTracker::TaskId | 377 base::CancelableTaskTracker::TaskId |
| 193 AndroidHistoryProviderService::InsertSearchTerm( | 378 AndroidHistoryProviderService::InsertSearchTerm( |
| 194 const history::SearchRow& row, | 379 const history::SearchRow& row, |
| 195 const InsertCallback& callback, | 380 const InsertCallback& callback, |
| 196 base::CancelableTaskTracker* tracker) { | 381 base::CancelableTaskTracker* tracker) { |
| 197 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 382 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 198 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 383 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 199 if (hs) { | 384 if (!hs) { |
| 200 DCHECK(hs->thread_) << "History service being called after cleanup"; | |
| 201 DCHECK(hs->thread_checker_.CalledOnValidThread()); | |
| 202 return tracker->PostTaskAndReplyWithResult( | |
| 203 hs->thread_->message_loop_proxy().get(), | |
| 204 FROM_HERE, | |
| 205 base::Bind( | |
| 206 &HistoryBackend::InsertSearchTerm, hs->history_backend_.get(), row), | |
| 207 callback); | |
| 208 } else { | |
| 209 callback.Run(0); | 385 callback.Run(0); |
| 210 return base::CancelableTaskTracker::kBadTaskId; | 386 return base::CancelableTaskTracker::kBadTaskId; |
| 211 } | 387 } |
| 388 return hs->ScheduleDBTask( |
| 389 CreateAndroidProviderTask(base::Bind(&InsertSearchTermAdapter, row), |
| 390 callback), |
| 391 tracker); |
| 212 } | 392 } |
| 213 | 393 |
| 214 base::CancelableTaskTracker::TaskId | 394 base::CancelableTaskTracker::TaskId |
| 215 AndroidHistoryProviderService::UpdateSearchTerms( | 395 AndroidHistoryProviderService::UpdateSearchTerms( |
| 216 const history::SearchRow& row, | 396 const history::SearchRow& row, |
| 217 const std::string& selection, | 397 const std::string& selection, |
| 218 const std::vector<base::string16>& selection_args, | 398 const std::vector<base::string16>& selection_args, |
| 219 const UpdateCallback& callback, | 399 const UpdateCallback& callback, |
| 220 base::CancelableTaskTracker* tracker) { | 400 base::CancelableTaskTracker* tracker) { |
| 221 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 401 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 222 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 402 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 223 if (hs) { | 403 if (!hs) { |
| 224 DCHECK(hs->thread_) << "History service being called after cleanup"; | |
| 225 DCHECK(hs->thread_checker_.CalledOnValidThread()); | |
| 226 return tracker->PostTaskAndReplyWithResult( | |
| 227 hs->thread_->message_loop_proxy().get(), | |
| 228 FROM_HERE, | |
| 229 base::Bind(&HistoryBackend::UpdateSearchTerms, | |
| 230 hs->history_backend_.get(), | |
| 231 row, | |
| 232 selection, | |
| 233 selection_args), | |
| 234 callback); | |
| 235 } else { | |
| 236 callback.Run(0); | 404 callback.Run(0); |
| 237 return base::CancelableTaskTracker::kBadTaskId; | 405 return base::CancelableTaskTracker::kBadTaskId; |
| 238 } | 406 } |
| 407 return hs->ScheduleDBTask( |
| 408 CreateAndroidProviderTask( |
| 409 base::Bind(&UpdateSearchTermsAdapter, row, selection, selection_args), |
| 410 callback), |
| 411 tracker); |
| 239 } | 412 } |
| 240 | 413 |
| 241 base::CancelableTaskTracker::TaskId | 414 base::CancelableTaskTracker::TaskId |
| 242 AndroidHistoryProviderService::DeleteSearchTerms( | 415 AndroidHistoryProviderService::DeleteSearchTerms( |
| 243 const std::string& selection, | 416 const std::string& selection, |
| 244 const std::vector<base::string16>& selection_args, | 417 const std::vector<base::string16>& selection_args, |
| 245 const DeleteCallback& callback, | 418 const DeleteCallback& callback, |
| 246 base::CancelableTaskTracker* tracker) { | 419 base::CancelableTaskTracker* tracker) { |
| 247 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 420 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 248 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 421 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 249 if (hs) { | 422 if (!hs) { |
| 250 DCHECK(hs->thread_) << "History service being called after cleanup"; | |
| 251 DCHECK(hs->thread_checker_.CalledOnValidThread()); | |
| 252 return tracker->PostTaskAndReplyWithResult( | |
| 253 hs->thread_->message_loop_proxy().get(), | |
| 254 FROM_HERE, | |
| 255 base::Bind(&HistoryBackend::DeleteSearchTerms, | |
| 256 hs->history_backend_.get(), | |
| 257 selection, | |
| 258 selection_args), | |
| 259 callback); | |
| 260 } else { | |
| 261 callback.Run(0); | 423 callback.Run(0); |
| 262 return base::CancelableTaskTracker::kBadTaskId; | 424 return base::CancelableTaskTracker::kBadTaskId; |
| 263 } | 425 } |
| 426 return hs->ScheduleDBTask( |
| 427 CreateAndroidProviderTask( |
| 428 base::Bind(&DeleteSearchTermsAdapter, selection, selection_args), |
| 429 callback), |
| 430 tracker); |
| 264 } | 431 } |
| 265 | 432 |
| 266 base::CancelableTaskTracker::TaskId | 433 base::CancelableTaskTracker::TaskId |
| 267 AndroidHistoryProviderService::QuerySearchTerms( | 434 AndroidHistoryProviderService::QuerySearchTerms( |
| 268 const std::vector<history::SearchRow::ColumnID>& projections, | 435 const std::vector<history::SearchRow::ColumnID>& projections, |
| 269 const std::string& selection, | 436 const std::string& selection, |
| 270 const std::vector<base::string16>& selection_args, | 437 const std::vector<base::string16>& selection_args, |
| 271 const std::string& sort_order, | 438 const std::string& sort_order, |
| 272 const QueryCallback& callback, | 439 const QueryCallback& callback, |
| 273 base::CancelableTaskTracker* tracker) { | 440 base::CancelableTaskTracker* tracker) { |
| 274 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 441 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 275 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 442 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 276 if (hs) { | 443 if (!hs) { |
| 277 DCHECK(hs->thread_) << "History service being called after cleanup"; | 444 callback.Run(nullptr); |
| 278 DCHECK(hs->thread_checker_.CalledOnValidThread()); | |
| 279 return tracker->PostTaskAndReplyWithResult( | |
| 280 hs->thread_->message_loop_proxy().get(), | |
| 281 FROM_HERE, | |
| 282 base::Bind(&HistoryBackend::QuerySearchTerms, | |
| 283 hs->history_backend_.get(), | |
| 284 projections, | |
| 285 selection, | |
| 286 selection_args, | |
| 287 sort_order), | |
| 288 callback); | |
| 289 } else { | |
| 290 callback.Run(NULL); | |
| 291 return base::CancelableTaskTracker::kBadTaskId; | 445 return base::CancelableTaskTracker::kBadTaskId; |
| 292 } | 446 } |
| 447 return hs->ScheduleDBTask( |
| 448 CreateAndroidProviderTask( |
| 449 base::Bind(&QuerySearchTermsAdapter, projections, selection, |
| 450 selection_args, sort_order), |
| 451 callback), |
| 452 tracker); |
| 293 } | 453 } |
| 294 | 454 |
| 295 base::CancelableTaskTracker::TaskId | 455 base::CancelableTaskTracker::TaskId |
| 296 AndroidHistoryProviderService::GetLargestRawFaviconForID( | 456 AndroidHistoryProviderService::GetLargestRawFaviconForID( |
| 297 favicon_base::FaviconID favicon_id, | 457 favicon_base::FaviconID favicon_id, |
| 298 const favicon_base::FaviconRawBitmapCallback& callback, | 458 const favicon_base::FaviconRawBitmapCallback& callback, |
| 299 base::CancelableTaskTracker* tracker) { | 459 base::CancelableTaskTracker* tracker) { |
| 300 FaviconService* fs = FaviconServiceFactory::GetForProfile( | 460 FaviconService* fs = FaviconServiceFactory::GetForProfile( |
| 301 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 461 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 302 DCHECK(fs); | 462 DCHECK(fs); |
| 303 return fs->GetLargestRawFaviconForID(favicon_id, callback, tracker); | 463 return fs->GetLargestRawFaviconForID(favicon_id, callback, tracker); |
| 304 } | 464 } |
| OLD | NEW |