| Index: chrome/browser/history/android/sqlite_cursor.cc
|
| diff --git a/chrome/browser/history/android/sqlite_cursor.cc b/chrome/browser/history/android/sqlite_cursor.cc
|
| index 3a933c665afe21e89892dacd56b07fc7eccb0420..4bf584acd889f6630cb0261bae547dac0be91994 100644
|
| --- a/chrome/browser/history/android/sqlite_cursor.cc
|
| +++ b/chrome/browser/history/android/sqlite_cursor.cc
|
| @@ -132,7 +132,17 @@ jint SQLiteCursor::GetColumnType(JNIEnv* env, jobject obj, jint column) {
|
| }
|
|
|
| void SQLiteCursor::Destroy(JNIEnv* env, jobject obj) {
|
| - delete this;
|
| + // We do our best to cleanup when Destroy() is called from Java's finalize()
|
| + // where the UI message loop might stop running or in the process of shutting
|
| + // down, as the whole process will be destroyed soon, it's fine to leave some
|
| + // objects out there.
|
| + if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
|
| + DestroyOnUIThread();
|
| + } else if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&SQLiteCursor::DestroyOnUIThread,
|
| + base::Unretained(this)))) {
|
| + delete this;
|
| + }
|
| }
|
|
|
| SQLiteCursor::SQLiteCursor(const std::vector<std::string>& column_names,
|
| @@ -150,25 +160,16 @@ SQLiteCursor::SQLiteCursor(const std::vector<std::string>& column_names,
|
| }
|
|
|
| SQLiteCursor::~SQLiteCursor() {
|
| +}
|
| +
|
| +void SQLiteCursor::DestroyOnUIThread() {
|
| // Consumer requests were set in the UI thread. They must be cancelled
|
| // using the same thread.
|
| - if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
|
| - CancelAllRequests(NULL);
|
| - } else {
|
| - base::WaitableEvent event(false, false);
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI,
|
| - FROM_HERE,
|
| - base::Bind(&SQLiteCursor::CancelAllRequests, base::Unretained(this),
|
| - &event));
|
| - event.Wait();
|
| - }
|
| -
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI,
|
| - FROM_HERE,
|
| - base::Bind(&AndroidHistoryProviderService::CloseStatement,
|
| - base::Unretained(service_), statement_));
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + consumer_.reset();
|
| + tracker_.reset();
|
| + service_->CloseStatement(statement_);
|
| + delete this;
|
| }
|
|
|
| bool SQLiteCursor::GetFavicon(chrome::FaviconID id,
|
| @@ -226,17 +227,6 @@ void SQLiteCursor::OnMoved(AndroidHistoryProviderService::Handle handle,
|
| test_observer_->OnGetMoveToResult();
|
| }
|
|
|
| -void SQLiteCursor::CancelAllRequests(base::WaitableEvent* finished) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| -
|
| - // Destruction will cancel all pending tasks.
|
| - consumer_.reset();
|
| - tracker_.reset();
|
| -
|
| - if (finished)
|
| - finished->Signal();
|
| -}
|
| -
|
| SQLiteCursor::JavaColumnType SQLiteCursor::GetColumnTypeInternal(int column) {
|
| if (column == statement_->favicon_index())
|
| return SQLiteCursor::BLOB;
|
|
|