Change AndroidHistoryProviderService to use CancelableTaskTracker (3/6)

Change AndroidHistoryProviderService::MoveStatement to use
base::CancelableTaskTracker instead of CancelableRequestConsumer.

BUG=371818

Review URL: https://codereview.chromium.org/366133003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283770 0039d316-1c4b-4281-b951-d872f2087c98
parent d7554b1a
......@@ -126,25 +126,31 @@ AndroidHistoryProviderService::DeleteHistory(
return request->handle();
}
AndroidHistoryProviderService::Handle
base::CancelableTaskTracker::TaskId
AndroidHistoryProviderService::MoveStatement(
history::AndroidStatement* statement,
int current_pos,
int destination,
CancelableRequestConsumerBase* consumer,
const MoveStatementCallback& callback) {
MoveStatementRequest* request = new MoveStatementRequest(callback);
AddRequest(request, consumer);
const MoveStatementCallback& callback,
base::CancelableTaskTracker* tracker) {
HistoryService* hs =
HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
if (hs) {
hs->Schedule(HistoryService::PRIORITY_NORMAL,
&HistoryBackend::MoveStatement, NULL, request, statement,
current_pos, destination);
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::MoveStatement,
hs->history_backend_.get(),
statement,
current_pos,
destination),
callback);
} else {
request->ForwardResultAsync(request->handle(), current_pos);
callback.Run(current_pos);
return base::CancelableTaskTracker::kBadTaskId;
}
return request->handle();
}
void AndroidHistoryProviderService::CloseStatement(
......
......@@ -50,11 +50,10 @@ class AndroidHistoryProviderService : public CancelableRequestProvider {
DeleteCallback;
typedef CancelableRequest<DeleteCallback> DeleteRequest;
typedef base::Callback<void(
Handle, // handle
int)> // the new position.
MoveStatementCallback;
typedef CancelableRequest<MoveStatementCallback> MoveStatementRequest;
// Callback invoked when a method moving an |AndroidStatement| is complete.
// The value passed to the callback is the new position, or in case of
// failure, the old position.
typedef base::Callback<void(int)> MoveStatementCallback;
// History and Bookmarks ----------------------------------------------------
//
......@@ -116,11 +115,12 @@ class AndroidHistoryProviderService : public CancelableRequestProvider {
// Moves the statement's current row from |current_pos| to |destination| in DB
// thread. The new position is returned to the callback. The result supplied
// the callback is constrained by the number of rows might.
Handle MoveStatement(history::AndroidStatement* statement,
int current_pos,
int destination,
CancelableRequestConsumerBase* consumer,
const MoveStatementCallback& callback);
base::CancelableTaskTracker::TaskId MoveStatement(
history::AndroidStatement* statement,
int current_pos,
int destination,
const MoveStatementCallback& callback,
base::CancelableTaskTracker* tracker);
// Closes the statement in db thread. The AndroidHistoryProviderService takes
// the ownership of |statement|.
......
......@@ -134,8 +134,7 @@ class CallbackHelper : public base::RefCountedThreadSafe<CallbackHelper> {
base::MessageLoop::current()->Quit();
}
void OnStatementMoved(AndroidHistoryProviderService::Handle handle,
int cursor_position) {
void OnStatementMoved(int cursor_position) {
cursor_position_ = cursor_position;
base::MessageLoop::current()->Quit();
}
......@@ -184,8 +183,12 @@ TEST_F(AndroidHistoryProviderServiceTest, TestHistoryAndBookmark) {
// Move the cursor to the begining and verify whether we could get
// the same result.
AndroidStatement* statement = callback->statement();
service_->MoveStatement(statement, 0, -1, &cancelable_consumer_,
Bind(&CallbackHelper::OnStatementMoved, callback.get()));
service_->MoveStatement(
statement,
0,
-1,
Bind(&CallbackHelper::OnStatementMoved, callback.get()),
&cancelable_tracker_);
base::MessageLoop::current()->Run();
EXPECT_EQ(-1, callback->cursor_position());
EXPECT_TRUE(callback->statement()->statement()->Step());
......@@ -244,8 +247,12 @@ TEST_F(AndroidHistoryProviderServiceTest, TestSearchTerm) {
// Move the cursor to the begining and verify whether we could get
// the same result.
AndroidStatement* statement = callback->statement();
service_->MoveStatement(statement, 0, -1, &cancelable_consumer_,
Bind(&CallbackHelper::OnStatementMoved, callback.get()));
service_->MoveStatement(
statement,
0,
-1,
Bind(&CallbackHelper::OnStatementMoved, callback.get()),
&cancelable_tracker_);
base::MessageLoop::current()->Run();
EXPECT_EQ(-1, callback->cursor_position());
EXPECT_TRUE(callback->statement()->statement()->Step());
......
......@@ -167,7 +167,6 @@ void SQLiteCursor::DestroyOnUIThread() {
// Consumer requests were set in the UI thread. They must be cancelled
// using the same thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
consumer_.reset();
tracker_.reset();
service_->CloseStatement(statement_);
delete this;
......@@ -218,8 +217,7 @@ void SQLiteCursor::OnFaviconData(
test_observer_->OnGetFaviconResult();
}
void SQLiteCursor::OnMoved(AndroidHistoryProviderService::Handle handle,
int pos) {
void SQLiteCursor::OnMoved(int pos) {
position_ = pos;
event_.Signal();
if (test_observer_)
......@@ -236,9 +234,12 @@ SQLiteCursor::JavaColumnType SQLiteCursor::GetColumnTypeInternal(int column) {
void SQLiteCursor::RunMoveStatementOnUIThread(int pos) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!consumer_.get())
consumer_.reset(new CancelableRequestConsumer());
if (!tracker_.get())
tracker_.reset(new base::CancelableTaskTracker());
service_->MoveStatement(
statement_, position_, pos, consumer_.get(),
base::Bind(&SQLiteCursor::OnMoved, base::Unretained(this)));
statement_,
position_,
pos,
base::Bind(&SQLiteCursor::OnMoved, base::Unretained(this)),
tracker_.get());
}
......@@ -15,7 +15,6 @@
#include "base/strings/string16.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/common/cancelable_request.h"
#include "chrome/browser/history/android/android_history_provider_service.h"
#include "chrome/browser/history/history_types.h"
#include "components/favicon_base/favicon_callback.h"
......@@ -159,7 +158,7 @@ class SQLiteCursor {
void OnFaviconData(const favicon_base::FaviconRawBitmapResult& bitmap_result);
// The callback function of MoveTo().
void OnMoved(AndroidHistoryProviderService::Handle handle, int pos);
void OnMoved(int pos);
JavaColumnType GetColumnTypeInternal(int column);
......@@ -182,7 +181,6 @@ class SQLiteCursor {
FaviconService* favicon_service_;
// Live on UI thread.
scoped_ptr<CancelableRequestConsumer> consumer_;
scoped_ptr<base::CancelableTaskTracker> tracker_;
// The count of result rows.
......
......@@ -314,10 +314,9 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// Statement ----------------------------------------------------------------
// Move the statement's current position.
void MoveStatement(scoped_refptr<MoveStatementRequest> request,
history::AndroidStatement* statement,
int current_pos,
int destination);
int MoveStatement(history::AndroidStatement* statement,
int current_pos,
int destination);
// Close the given statement. The ownership is transfered.
void CloseStatement(AndroidStatement* statement);
......
......@@ -86,11 +86,9 @@ void HistoryBackend::DeleteHistory(
// Statement -------------------------------------------------------------------
void HistoryBackend::MoveStatement(
scoped_refptr<MoveStatementRequest> request,
history::AndroidStatement* statement,
int current_pos,
int destination) {
int HistoryBackend::MoveStatement(history::AndroidStatement* statement,
int current_pos,
int destination) {
DCHECK_LE(-1, current_pos);
DCHECK_LE(-1, destination);
......@@ -104,7 +102,7 @@ void HistoryBackend::MoveStatement(
break;
}
request->ForwardResult(request->handle(), cur);
return cur;
}
void HistoryBackend::CloseStatement(AndroidStatement* statement) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment