diff options
7 files changed, 81 insertions, 77 deletions
diff --git a/chrome/browser/android/provider/chrome_browser_provider.cc b/chrome/browser/android/provider/chrome_browser_provider.cc index b4827da..b50528b 100644 --- a/chrome/browser/android/provider/chrome_browser_provider.cc +++ b/chrome/browser/android/provider/chrome_browser_provider.cc @@ -744,17 +744,17 @@ class AddBookmarkFromAPITask : public HistoryProviderTask { history::URLID Run(const history::HistoryAndBookmarkRow& row) { RunAsyncRequestOnUIThreadBlocking( base::Bind(&AndroidHistoryProviderService::InsertHistoryAndBookmark, - base::Unretained(service()), row, cancelable_consumer(), + base::Unretained(service()), + row, base::Bind(&AddBookmarkFromAPITask::OnBookmarkInserted, - base::Unretained(this)))); + base::Unretained(this)), + cancelable_tracker())); return result_; } private: - void OnBookmarkInserted(AndroidHistoryProviderService::Handle handle, - bool succeeded, - history::URLID id) { - // Note that here 0 means an invalid id too. + void OnBookmarkInserted(history::URLID id) { + // Note that here 0 means an invalid id. // This is because it represents a SQLite database row id. result_ = id; RequestCompleted(); @@ -967,15 +967,15 @@ class AddSearchTermFromAPITask : public SearchTermTask { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); history::SearchRow internal_row = row; BuildSearchRow(&internal_row); - service()->InsertSearchTerm(internal_row, cancelable_consumer(), + service()->InsertSearchTerm( + internal_row, base::Bind(&AddSearchTermFromAPITask::OnSearchTermInserted, - base::Unretained(this))); + base::Unretained(this)), + cancelable_tracker()); } - void OnSearchTermInserted(AndroidHistoryProviderService::Handle handle, - bool succeeded, - history::URLID id) { - // Note that here 0 means an invalid id too. + void OnSearchTermInserted(history::URLID id) { + // Note that here 0 means an invalid id. // This is because it represents a SQLite database row id. result_ = id; RequestCompleted(); diff --git a/chrome/browser/history/android/android_history_provider_service.cc b/chrome/browser/history/android/android_history_provider_service.cc index 67e2c47..e008b54 100644 --- a/chrome/browser/history/android/android_history_provider_service.cc +++ b/chrome/browser/history/android/android_history_provider_service.cc @@ -88,22 +88,27 @@ AndroidHistoryProviderService::DeleteHistoryAndBookmarks( return request->handle(); } -AndroidHistoryProviderService::Handle +base::CancelableTaskTracker::TaskId AndroidHistoryProviderService::InsertHistoryAndBookmark( const history::HistoryAndBookmarkRow& values, - CancelableRequestConsumerBase* consumer, - const InsertCallback& callback) { - InsertRequest* request = new InsertRequest(callback); - AddRequest(request, consumer); + const InsertCallback& callback, + base::CancelableTaskTracker* tracker) { HistoryService* hs = HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); if (hs) { - hs->Schedule(HistoryService::PRIORITY_NORMAL, - &HistoryBackend::InsertHistoryAndBookmark, NULL, request, values); + DCHECK(hs->thread_) << "History service being called after cleanup"; + DCHECK(hs->thread_checker_.CalledOnValidThread()); + return tracker->PostTaskAndReplyWithResult( + hs->thread_->message_loop_proxy().get(), + FROM_HERE, + base::Bind(&HistoryBackend::InsertHistoryAndBookmark, + hs->history_backend_.get(), + values), + callback); } else { - request->ForwardResultAsync(request->handle(), false, 0); + callback.Run(0); + return base::CancelableTaskTracker::kBadTaskId; } - return request->handle(); } AndroidHistoryProviderService::Handle @@ -165,22 +170,26 @@ void AndroidHistoryProviderService::CloseStatement( } } -AndroidHistoryProviderService::Handle +base::CancelableTaskTracker::TaskId AndroidHistoryProviderService::InsertSearchTerm( const history::SearchRow& row, - CancelableRequestConsumerBase* consumer, - const InsertCallback& callback) { - InsertRequest* request = new InsertRequest(callback); - AddRequest(request, consumer); + const InsertCallback& callback, + base::CancelableTaskTracker* tracker) { HistoryService* hs = HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); if (hs) { - hs->Schedule(HistoryService::PRIORITY_NORMAL, - &HistoryBackend::InsertSearchTerm, NULL, request, row); + DCHECK(hs->thread_) << "History service being called after cleanup"; + DCHECK(hs->thread_checker_.CalledOnValidThread()); + return tracker->PostTaskAndReplyWithResult( + hs->thread_->message_loop_proxy().get(), + FROM_HERE, + base::Bind( + &HistoryBackend::InsertSearchTerm, hs->history_backend_.get(), row), + callback); } else { - request->ForwardResultAsync(request->handle(), false, 0); + callback.Run(0); + return base::CancelableTaskTracker::kBadTaskId; } - return request->handle(); } AndroidHistoryProviderService::Handle diff --git a/chrome/browser/history/android/android_history_provider_service.h b/chrome/browser/history/android/android_history_provider_service.h index 7752ef8..0c54ca06 100644 --- a/chrome/browser/history/android/android_history_provider_service.h +++ b/chrome/browser/history/android/android_history_provider_service.h @@ -36,12 +36,9 @@ class AndroidHistoryProviderService : public CancelableRequestProvider { UpdateCallback; typedef CancelableRequest<UpdateCallback> UpdateRequest; - typedef base::Callback<void( - Handle, // handle - bool, // true if the insert succeeded. - int64)> // the id of inserted row. - InsertCallback; - typedef CancelableRequest<InsertCallback> InsertRequest; + // Callback invoked when a method inserting rows in the database complete. + // The value is the new row id or 0 if the insertion failed. + typedef base::Callback<void(int64)> InsertCallback; typedef base::Callback<void( Handle, // handle @@ -100,9 +97,10 @@ class AndroidHistoryProviderService : public CancelableRequestProvider { // Inserts the given values into history backend, and invokes the |callback| // to return the result. - Handle InsertHistoryAndBookmark(const history::HistoryAndBookmarkRow& values, - CancelableRequestConsumerBase* consumer, - const InsertCallback& callback); + base::CancelableTaskTracker::TaskId InsertHistoryAndBookmark( + const history::HistoryAndBookmarkRow& values, + const InsertCallback& callback, + base::CancelableTaskTracker* tracker); // Deletes the matched history and invokes |callback| to return the number of // the row deleted from the |callback|. @@ -128,12 +126,13 @@ class AndroidHistoryProviderService : public CancelableRequestProvider { // Search term -------------------------------------------------------------- // Inserts the given values and returns the SearchTermID of the inserted row - // from the |callback| on success. - Handle InsertSearchTerm(const history::SearchRow& row, - CancelableRequestConsumerBase* consumer, - const InsertCallback& callback); + // to the |callback| on success. + base::CancelableTaskTracker::TaskId InsertSearchTerm( + const history::SearchRow& row, + const InsertCallback& callback, + base::CancelableTaskTracker* tracker); - // Runs the given update and returns the number of the update rows from the + // Runs the given update and returns the number of the update rows to the // |callback| on success. // // |row| is the value need to update. @@ -145,8 +144,9 @@ class AndroidHistoryProviderService : public CancelableRequestProvider { CancelableRequestConsumerBase* consumer, const UpdateCallback& callback); - // Deletes the matched rows and the number of deleted rows is returned from + // Deletes the matched rows and the number of deleted rows is returned to // the |callback| on success. + // // |selection| is the SQL WHERE clause without 'WHERE'. // |selection_args| is the arguments for WHERE clause. // diff --git a/chrome/browser/history/android/android_history_provider_service_unittest.cc b/chrome/browser/history/android/android_history_provider_service_unittest.cc index 8595ff2..27f0ead 100644 --- a/chrome/browser/history/android/android_history_provider_service_unittest.cc +++ b/chrome/browser/history/android/android_history_provider_service_unittest.cc @@ -105,10 +105,8 @@ class CallbackHelper : public base::RefCountedThreadSafe<CallbackHelper> { return count_; } - void OnInserted(AndroidHistoryProviderService::Handle handle, - bool success, - int64 id) { - success_ = success; + void OnInserted(int64 id) { + success_ = id != 0; base::MessageLoop::current()->Quit(); } @@ -160,8 +158,10 @@ TEST_F(AndroidHistoryProviderServiceTest, TestHistoryAndBookmark) { scoped_refptr<CallbackHelper> callback(new CallbackHelper()); // Insert a row and verify it succeeded. - service_->InsertHistoryAndBookmark(row, &cancelable_consumer_, - Bind(&CallbackHelper::OnInserted, callback.get())); + service_->InsertHistoryAndBookmark( + row, + Bind(&CallbackHelper::OnInserted, callback.get()), + &cancelable_tracker_); base::MessageLoop::current()->Run(); EXPECT_TRUE(callback->success()); @@ -224,8 +224,9 @@ TEST_F(AndroidHistoryProviderServiceTest, TestSearchTerm) { scoped_refptr<CallbackHelper> callback(new CallbackHelper()); // Insert a row and verify it succeeded. - service_->InsertSearchTerm(search_row, &cancelable_consumer_, - Bind(&CallbackHelper::OnInserted, callback.get())); + service_->InsertSearchTerm(search_row, + Bind(&CallbackHelper::OnInserted, callback.get()), + &cancelable_tracker_); base::MessageLoop::current()->Run(); EXPECT_TRUE(callback->success()); diff --git a/chrome/browser/history/android/sqlite_cursor_unittest.cc b/chrome/browser/history/android/sqlite_cursor_unittest.cc index 2fe66a9..7b1b4aa 100644 --- a/chrome/browser/history/android/sqlite_cursor_unittest.cc +++ b/chrome/browser/history/android/sqlite_cursor_unittest.cc @@ -129,10 +129,8 @@ class CallbackHelper : public base::RefCountedThreadSafe<CallbackHelper> { return statement_; } - void OnInserted(AndroidHistoryProviderService::Handle handle, - bool success, - int64 id) { - success_ = success; + void OnInserted(int64 id) { + success_ = id != 0; base::MessageLoop::current()->Quit(); } @@ -170,8 +168,10 @@ TEST_F(SQLiteCursorTest, Run) { scoped_refptr<CallbackHelper> callback(new CallbackHelper()); // Insert a row and verify it succeeded. - service_->InsertHistoryAndBookmark(row, &cancelable_consumer_, - Bind(&CallbackHelper::OnInserted, callback.get())); + service_->InsertHistoryAndBookmark( + row, + Bind(&CallbackHelper::OnInserted, callback.get()), + &cancelable_tracker_); base::MessageLoop::current()->Run(); EXPECT_TRUE(callback->success()); diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index 87534cd..b4650f0 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -25,6 +25,10 @@ #include "components/history/core/browser/keyword_id.h" #include "sql/init_status.h" +#if defined(OS_ANDROID) +#include "chrome/browser/history/android/android_history_types.h" +#endif + class TestingProfile; class TypedUrlSyncableService; struct ThumbnailScore; @@ -282,8 +286,8 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, // Android Provider --------------------------------------------------------- // History and bookmarks ---------------------------------------------------- - void InsertHistoryAndBookmark(scoped_refptr<InsertRequest> request, - const HistoryAndBookmarkRow& row); + // Inserts the given values into history backend. + AndroidURLID InsertHistoryAndBookmark(const HistoryAndBookmarkRow& row); // Runs the given query on history backend and returns the result. // @@ -322,8 +326,8 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, void CloseStatement(AndroidStatement* statement); // Search terms ------------------------------------------------------------- - void InsertSearchTerm(scoped_refptr<InsertRequest> request, - const SearchRow& row); + // Inserts the given values and returns the SearchTermID of the inserted row. + SearchTermID InsertSearchTerm(const SearchRow& row); void UpdateSearchTerms(scoped_refptr<UpdateRequest> request, const SearchRow& row, diff --git a/chrome/browser/history/history_backend_android.cc b/chrome/browser/history/history_backend_android.cc index 840e8ee..83776ec 100644 --- a/chrome/browser/history/history_backend_android.cc +++ b/chrome/browser/history/history_backend_android.cc @@ -8,17 +8,12 @@ namespace history { -void HistoryBackend::InsertHistoryAndBookmark( - scoped_refptr<InsertRequest> request, +AndroidURLID HistoryBackend::InsertHistoryAndBookmark( const HistoryAndBookmarkRow& row) { - if (request->canceled()) - return; - AndroidURLID id = 0; if (android_provider_backend_) id = android_provider_backend_->InsertHistoryAndBookmark(row); - - request->ForwardResult(request->handle(), id != 0, id); + return id; } AndroidStatement* HistoryBackend::QueryHistoryAndBookmarks( @@ -111,16 +106,11 @@ void HistoryBackend::CloseStatement(AndroidStatement* statement) { // Search Term ----------------------------------------------------------------- -void HistoryBackend::InsertSearchTerm(scoped_refptr<InsertRequest> request, - const SearchRow& row) { - if (request->canceled()) - return; - +SearchTermID HistoryBackend::InsertSearchTerm(const SearchRow& row) { SearchTermID id = 0; if (android_provider_backend_) id = android_provider_backend_->InsertSearchTerm(row); - - request->ForwardResult(request->handle(), id != 0, id); + return id; } void HistoryBackend::UpdateSearchTerms( |