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

Unified Diff: components/autofill/core/browser/webdata/autofill_webdata_service.cc

Issue 25870002: Abstract BrowserThread knowledge out of AutofillWebDataService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix up test constructor Created 7 years, 2 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: components/autofill/core/browser/webdata/autofill_webdata_service.cc
diff --git a/components/autofill/core/browser/webdata/autofill_webdata_service.cc b/components/autofill/core/browser/webdata/autofill_webdata_service.cc
index dbf9854407d8a1cefd7df036ffb696df1773b4b5..9ba3fed5c8b31aca1e9d2db8eaebcb0b15aeece9 100644
--- a/components/autofill/core/browser/webdata/autofill_webdata_service.cc
+++ b/components/autofill/core/browser/webdata/autofill_webdata_service.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/logging.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "base/stl_util.h"
#include "components/autofill/core/browser/autofill_country.h"
#include "components/autofill/core/browser/autofill_profile.h"
@@ -18,19 +19,20 @@
#include "components/autofill/core/common/form_field_data.h"
#include "components/webdata/common/web_data_service_backend.h"
#include "components/webdata/common/web_database_service.h"
-#include "content/public/browser/browser_thread.h"
using base::Bind;
using base::Time;
-using content::BrowserThread;
namespace autofill {
AutofillWebDataService::AutofillWebDataService(
scoped_refptr<WebDatabaseService> wdbs,
+ scoped_refptr<base::MessageLoopProxy> ui_thread,
+ scoped_refptr<base::MessageLoopProxy> db_thread,
const ProfileErrorCallback& callback)
- : WebDataServiceBase(wdbs, callback,
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)),
+ : WebDataServiceBase(wdbs, callback, ui_thread),
+ ui_thread_(ui_thread),
+ db_thread_(db_thread),
weak_ptr_factory_(this),
autofill_backend_(NULL) {
@@ -39,27 +41,27 @@ AutofillWebDataService::AutofillWebDataService(
weak_ptr_factory_.GetWeakPtr());
autofill_backend_ = new AutofillWebDataBackendImpl(
- wdbs_->GetBackend(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
- on_changed_callback);
+ wdbs_->GetBackend(), ui_thread_, db_thread_, on_changed_callback);
}
-AutofillWebDataService::AutofillWebDataService()
+AutofillWebDataService::AutofillWebDataService(
+ scoped_refptr<base::MessageLoopProxy> ui_thread,
+ scoped_refptr<base::MessageLoopProxy> db_thread)
: WebDataServiceBase(NULL, WebDataServiceBase::ProfileErrorCallback(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)),
+ ui_thread),
+ ui_thread_(ui_thread),
+ db_thread_(db_thread),
weak_ptr_factory_(this),
autofill_backend_(new AutofillWebDataBackendImpl(NULL,
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
+ ui_thread_,
+ db_thread_,
base::Closure())) {
}
void AutofillWebDataService::ShutdownOnUIThread() {
weak_ptr_factory_.InvalidateWeakPtrs();
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- Bind(&AutofillWebDataBackendImpl::ResetUserData,
- autofill_backend_));
+ db_thread_->PostTask(FROM_HERE,
+ Bind(&AutofillWebDataBackendImpl::ResetUserData, autofill_backend_));
WebDataServiceBase::ShutdownOnUIThread();
}
@@ -175,47 +177,45 @@ void AutofillWebDataService::RemoveOriginURLsModifiedBetween(
void AutofillWebDataService::AddObserver(
AutofillWebDataServiceObserverOnDBThread* observer) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
if (autofill_backend_.get())
autofill_backend_->AddObserver(observer);
}
void AutofillWebDataService::RemoveObserver(
AutofillWebDataServiceObserverOnDBThread* observer) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
if (autofill_backend_.get())
autofill_backend_->RemoveObserver(observer);
}
void AutofillWebDataService::AddObserver(
AutofillWebDataServiceObserverOnUIThread* observer) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(ui_thread_->BelongsToCurrentThread());
ui_observer_list_.AddObserver(observer);
}
void AutofillWebDataService::RemoveObserver(
AutofillWebDataServiceObserverOnUIThread* observer) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(ui_thread_->BelongsToCurrentThread());
ui_observer_list_.RemoveObserver(observer);
}
base::SupportsUserData* AutofillWebDataService::GetDBUserData() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
return autofill_backend_->GetDBUserData();
}
void AutofillWebDataService::GetAutofillBackend(
const base::Callback<void(AutofillWebDataBackend*)>& callback) {
- BrowserThread::PostTask(BrowserThread::DB,
- FROM_HERE,
- base::Bind(callback, autofill_backend_));
+ db_thread_->PostTask(FROM_HERE, base::Bind(callback, autofill_backend_));
}
AutofillWebDataService::~AutofillWebDataService() {
}
void AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(ui_thread_->BelongsToCurrentThread());
FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnUIThread,
ui_observer_list_,
AutofillMultipleChanged());

Powered by Google App Engine
This is Rietveld 408576698