Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6088)

Unified Diff: chrome/browser/history/android/sqlite_cursor.cc

Issue 15701011: Only wait for CancelAllRequests done if the post task succeeds (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync again Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
« no previous file with comments | « chrome/browser/history/android/sqlite_cursor.h ('k') | chrome/browser/history/android/sqlite_cursor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698