Commit 13ea31c0 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Don't assume UI/DB threads unnecessarily.

Some code that currently assumes it's running on the UI or DB threads can simply
use "the current thread" or "the background thread" or similar.

Bug: 689520
Change-Id: Ide84528d7abea223939bef247c1f4d9c47bb8752
Reviewed-on: https://chromium-review.googlesource.com/578144
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarVaclav Brozek <vabr@chromium.org>
Reviewed-by: default avatarSelim Gurun <sgurun@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488419}
parent 4b18c52b
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/task_scheduler/post_task.h" #include "base/task_scheduler/post_task.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/autofill/core/browser/webdata/autofill_table.h" #include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/webdata/common/webdata_constants.h" #include "components/webdata/common/webdata_constants.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -34,16 +35,15 @@ AwFormDatabaseService::AwFormDatabaseService(const base::FilePath path) ...@@ -34,16 +35,15 @@ AwFormDatabaseService::AwFormDatabaseService(const base::FilePath path)
has_form_data_completion_( has_form_data_completion_(
base::WaitableEvent::ResetPolicy::AUTOMATIC, base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED) { base::WaitableEvent::InitialState::NOT_SIGNALED) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); auto ui_thread = base::ThreadTaskRunnerHandle::Get();
web_database_ = new WebDatabaseService( web_database_ = new WebDatabaseService(
path.Append(kWebDataFilename), path.Append(kWebDataFilename), ui_thread,
BrowserThread::GetTaskRunnerForThread(BrowserThread::UI),
BrowserThread::GetTaskRunnerForThread(BrowserThread::DB)); BrowserThread::GetTaskRunnerForThread(BrowserThread::DB));
web_database_->AddTable(base::WrapUnique(new autofill::AutofillTable)); web_database_->AddTable(base::WrapUnique(new autofill::AutofillTable));
web_database_->LoadDatabase(); web_database_->LoadDatabase();
autofill_data_ = new autofill::AutofillWebDataService( autofill_data_ = new autofill::AutofillWebDataService(
web_database_, BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), web_database_, ui_thread,
BrowserThread::GetTaskRunnerForThread(BrowserThread::DB), BrowserThread::GetTaskRunnerForThread(BrowserThread::DB),
base::Bind(&DatabaseErrorCallback)); base::Bind(&DatabaseErrorCallback));
autofill_data_->Init(); autofill_data_->Init();
...@@ -54,7 +54,6 @@ AwFormDatabaseService::~AwFormDatabaseService() { ...@@ -54,7 +54,6 @@ AwFormDatabaseService::~AwFormDatabaseService() {
} }
void AwFormDatabaseService::Shutdown() { void AwFormDatabaseService::Shutdown() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// TODO(sgurun) we don't run into this logic right now, // TODO(sgurun) we don't run into this logic right now,
// but if we do, then we need to implement cancellation // but if we do, then we need to implement cancellation
// of pending queries. // of pending queries.
......
...@@ -23,10 +23,8 @@ ...@@ -23,10 +23,8 @@
#include "components/password_manager/core/browser/password_manager.h" #include "components/password_manager/core/browser/password_manager.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h" #include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/webdata/password_web_data_service_win.h" #include "components/password_manager/core/browser/webdata/password_web_data_service_win.h"
#include "content/public/browser/browser_thread.h"
using autofill::PasswordForm; using autofill::PasswordForm;
using content::BrowserThread;
using password_manager::PasswordStore; using password_manager::PasswordStore;
using password_manager::PasswordStoreDefault; using password_manager::PasswordStoreDefault;
...@@ -86,7 +84,8 @@ class PasswordStoreWin::DBHandler : public WebDataServiceConsumer { ...@@ -86,7 +84,8 @@ class PasswordStoreWin::DBHandler : public WebDataServiceConsumer {
}; };
PasswordStoreWin::DBHandler::~DBHandler() { PasswordStoreWin::DBHandler::~DBHandler() {
DCHECK_CURRENTLY_ON(BrowserThread::DB); DCHECK(
password_store_->GetBackgroundTaskRunner()->RunsTasksInCurrentSequence());
for (PendingRequestMap::const_iterator i = pending_requests_.begin(); for (PendingRequestMap::const_iterator i = pending_requests_.begin();
i != pending_requests_.end(); i != pending_requests_.end();
++i) { ++i) {
...@@ -97,7 +96,8 @@ PasswordStoreWin::DBHandler::~DBHandler() { ...@@ -97,7 +96,8 @@ PasswordStoreWin::DBHandler::~DBHandler() {
void PasswordStoreWin::DBHandler::GetIE7Login( void PasswordStoreWin::DBHandler::GetIE7Login(
const PasswordStore::FormDigest& form, const PasswordStore::FormDigest& form,
const ResultCallback& result_callback) { const ResultCallback& result_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::DB); DCHECK(
password_store_->GetBackgroundTaskRunner()->RunsTasksInCurrentSequence());
IE7PasswordInfo info; IE7PasswordInfo info;
info.url_hash = info.url_hash =
ie7_password::GetUrlHash(base::UTF8ToWide(form.origin.spec())); ie7_password::GetUrlHash(base::UTF8ToWide(form.origin.spec()));
...@@ -111,7 +111,8 @@ std::vector<std::unique_ptr<PasswordForm>> ...@@ -111,7 +111,8 @@ std::vector<std::unique_ptr<PasswordForm>>
PasswordStoreWin::DBHandler::GetIE7Results( PasswordStoreWin::DBHandler::GetIE7Results(
const WDTypedResult* result, const WDTypedResult* result,
const PasswordStore::FormDigest& form) { const PasswordStore::FormDigest& form) {
DCHECK_CURRENTLY_ON(BrowserThread::DB); DCHECK(
password_store_->GetBackgroundTaskRunner()->RunsTasksInCurrentSequence());
std::vector<std::unique_ptr<PasswordForm>> matched_forms; std::vector<std::unique_ptr<PasswordForm>> matched_forms;
const WDResult<IE7PasswordInfo>* r = const WDResult<IE7PasswordInfo>* r =
static_cast<const WDResult<IE7PasswordInfo>*>(result); static_cast<const WDResult<IE7PasswordInfo>*>(result);
...@@ -155,7 +156,8 @@ void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( ...@@ -155,7 +156,8 @@ void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone(
FROM_HERE_WITH_EXPLICIT_FUNCTION( FROM_HERE_WITH_EXPLICIT_FUNCTION(
"422460 PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone")); "422460 PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone"));
DCHECK_CURRENTLY_ON(BrowserThread::DB); DCHECK(
password_store_->GetBackgroundTaskRunner()->RunsTasksInCurrentSequence());
PendingRequestMap::iterator i = pending_requests_.find(handle); PendingRequestMap::iterator i = pending_requests_.find(handle);
DCHECK(i != pending_requests_.end()); DCHECK(i != pending_requests_.end());
...@@ -197,14 +199,13 @@ PasswordStoreWin::~PasswordStoreWin() { ...@@ -197,14 +199,13 @@ PasswordStoreWin::~PasswordStoreWin() {
} }
void PasswordStoreWin::ShutdownOnDBThread() { void PasswordStoreWin::ShutdownOnDBThread() {
DCHECK_CURRENTLY_ON(BrowserThread::DB); DCHECK(GetBackgroundTaskRunner()->RunsTasksInCurrentSequence());
db_handler_.reset(); db_handler_.reset();
} }
void PasswordStoreWin::ShutdownOnUIThread() { void PasswordStoreWin::ShutdownOnUIThread() {
BrowserThread::PostTask( GetBackgroundTaskRunner()->PostTask(
BrowserThread::DB, FROM_HERE, FROM_HERE, base::Bind(&PasswordStoreWin::ShutdownOnDBThread, this));
base::Bind(&PasswordStoreWin::ShutdownOnDBThread, this));
PasswordStoreDefault::ShutdownOnUIThread(); PasswordStoreDefault::ShutdownOnUIThread();
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/test/histogram_tester.h" #include "base/test/histogram_tester.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/os_crypt/ie7_password_win.h" #include "components/os_crypt/ie7_password_win.h"
...@@ -31,8 +32,6 @@ ...@@ -31,8 +32,6 @@
#include "components/password_manager/core/browser/password_store_consumer.h" #include "components/password_manager/core/browser/password_store_consumer.h"
#include "components/password_manager/core/browser/webdata/logins_table.h" #include "components/password_manager/core/browser/webdata/logins_table.h"
#include "components/password_manager/core/browser/webdata/password_web_data_service_win.h" #include "components/password_manager/core/browser/webdata/password_web_data_service_win.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/webdata/common/web_database_service.h" #include "components/webdata/common/web_database_service.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
...@@ -138,14 +137,14 @@ class PasswordStoreWinTest : public testing::Test { ...@@ -138,14 +137,14 @@ class PasswordStoreWinTest : public testing::Test {
base::FilePath path = temp_dir_.GetPath().AppendASCII("web_data_test"); base::FilePath path = temp_dir_.GetPath().AppendASCII("web_data_test");
wdbs_ = new WebDatabaseService( wdbs_ = new WebDatabaseService(
path, BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), path, base::ThreadTaskRunnerHandle::Get(),
BrowserThread::GetTaskRunnerForThread(BrowserThread::DB)); BrowserThread::GetTaskRunnerForThread(BrowserThread::DB));
// Need to add at least one table so the database gets created. // Need to add at least one table so the database gets created.
wdbs_->AddTable(std::unique_ptr<WebDatabaseTable>(new LoginsTable())); wdbs_->AddTable(std::unique_ptr<WebDatabaseTable>(new LoginsTable()));
wdbs_->LoadDatabase(); wdbs_->LoadDatabase();
wds_ = new PasswordWebDataService( wds_ =
wdbs_, BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), new PasswordWebDataService(wdbs_, base::ThreadTaskRunnerHandle::Get(),
WebDataServiceBase::ProfileErrorCallback()); WebDataServiceBase::ProfileErrorCallback());
wds_->Init(); wds_->Init();
} }
...@@ -189,7 +188,6 @@ class PasswordStoreWinTest : public testing::Test { ...@@ -189,7 +188,6 @@ class PasswordStoreWinTest : public testing::Test {
}; };
ACTION(QuitUIMessageLoop) { ACTION(QuitUIMessageLoop) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::MessageLoop::current()->QuitWhenIdle(); base::MessageLoop::current()->QuitWhenIdle();
} }
......
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