summaryrefslogtreecommitdiffstats
path: root/components/autofill
diff options
context:
space:
mode:
authorblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-03 10:23:45 +0000
committerblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-03 10:23:45 +0000
commitb8abc93c9ea0dd93e2231ce9aeac1456b39fdff5 (patch)
treea65926fb027debc31d80423951f3e23d5444ab16 /components/autofill
parent6bf35a5f4054509cd29604ae715c120682c67e06 (diff)
downloadchromium_src-b8abc93c9ea0dd93e2231ce9aeac1456b39fdff5.zip
chromium_src-b8abc93c9ea0dd93e2231ce9aeac1456b39fdff5.tar.gz
chromium_src-b8abc93c9ea0dd93e2231ce9aeac1456b39fdff5.tar.bz2
Abstract content::BrowserThread usage out of AutofillWebDataBackendImpl.
Instead, this class now takes in MessageLoopProxy's for the UI thread and DB thread. All operations that were previously on BrowserThread are changed to the corresponding operations on MessageLoopProxy. A follow-up change will perform a similar abstraction for AutofillWebDataService. BUG=303017 Review URL: https://codereview.chromium.org/25783002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226724 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/autofill')
-rw-r--r--components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc57
-rw-r--r--components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h33
-rw-r--r--components/autofill/core/browser/webdata/autofill_webdata_service.cc9
3 files changed, 60 insertions, 39 deletions
diff --git a/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc b/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc
index b3da704..ad6c132 100644
--- a/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc
+++ b/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc
@@ -4,8 +4,10 @@
#include "components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/scoped_vector.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"
@@ -19,26 +21,31 @@
using base::Bind;
using base::Time;
-using content::BrowserThread;
namespace autofill {
AutofillWebDataBackendImpl::AutofillWebDataBackendImpl(
scoped_refptr<WebDataServiceBackend> web_database_backend,
+ scoped_refptr<base::MessageLoopProxy> ui_thread,
+ scoped_refptr<base::MessageLoopProxy> db_thread,
const base::Closure& on_changed_callback)
- : web_database_backend_(web_database_backend),
+ : base::RefCountedDeleteOnMessageLoop<AutofillWebDataBackendImpl>(
+ db_thread),
+ ui_thread_(ui_thread),
+ db_thread_(db_thread),
+ web_database_backend_(web_database_backend),
on_changed_callback_(on_changed_callback) {
}
void AutofillWebDataBackendImpl::AddObserver(
AutofillWebDataServiceObserverOnDBThread* observer) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
db_observer_list_.AddObserver(observer);
}
void AutofillWebDataBackendImpl::RemoveObserver(
AutofillWebDataServiceObserverOnDBThread* observer) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
db_observer_list_.RemoveObserver(observer);
}
@@ -47,7 +54,7 @@ AutofillWebDataBackendImpl::~AutofillWebDataBackendImpl() {
}
WebDatabase* AutofillWebDataBackendImpl::GetDatabase() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
return web_database_backend_->database();
}
@@ -58,14 +65,12 @@ void AutofillWebDataBackendImpl::RemoveExpiredFormElements() {
}
void AutofillWebDataBackendImpl::NotifyOfMultipleAutofillChanges() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
- BrowserThread::PostTask(BrowserThread::UI,
- FROM_HERE,
- on_changed_callback_);
+ DCHECK(db_thread_->BelongsToCurrentThread());
+ ui_thread_->PostTask(FROM_HERE, on_changed_callback_);
}
base::SupportsUserData* AutofillWebDataBackendImpl::GetDBUserData() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
if (!user_data_)
user_data_.reset(new SupportsUserDataAggregatable());
return user_data_.get();
@@ -77,7 +82,7 @@ void AutofillWebDataBackendImpl::ResetUserData() {
WebDatabase::State AutofillWebDataBackendImpl::AddFormElements(
const std::vector<FormFieldData>& fields, WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
AutofillChangeList changes;
if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues(
fields, &changes)) {
@@ -99,7 +104,7 @@ scoped_ptr<WDTypedResult>
AutofillWebDataBackendImpl::GetFormValuesForElementName(
const base::string16& name, const base::string16& prefix, int limit,
WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
std::vector<base::string16> values;
AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName(
name, prefix, &values, limit);
@@ -110,7 +115,7 @@ AutofillWebDataBackendImpl::GetFormValuesForElementName(
scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::HasFormElements(
WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
bool value = AutofillTable::FromWebDatabase(db)->HasFormElements();
return scoped_ptr<WDTypedResult>(
new WDResult<bool>(AUTOFILL_VALUE_RESULT, value));
@@ -120,7 +125,7 @@ WebDatabase::State AutofillWebDataBackendImpl::RemoveFormElementsAddedBetween(
const base::Time& delete_begin,
const base::Time& delete_end,
WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
AutofillChangeList changes;
if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween(
@@ -140,7 +145,7 @@ WebDatabase::State AutofillWebDataBackendImpl::RemoveFormElementsAddedBetween(
WebDatabase::State AutofillWebDataBackendImpl::RemoveFormValueForElementName(
const base::string16& name, const base::string16& value, WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) {
AutofillChangeList changes;
@@ -159,7 +164,7 @@ WebDatabase::State AutofillWebDataBackendImpl::RemoveFormValueForElementName(
WebDatabase::State AutofillWebDataBackendImpl::AddAutofillProfile(
const AutofillProfile& profile, WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) {
NOTREACHED();
return WebDatabase::COMMIT_NOT_NEEDED;
@@ -177,7 +182,7 @@ WebDatabase::State AutofillWebDataBackendImpl::AddAutofillProfile(
WebDatabase::State AutofillWebDataBackendImpl::UpdateAutofillProfile(
const AutofillProfile& profile, WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
// Only perform the update if the profile exists. It is currently
// valid to try to update a missing profile. We simply drop the write and
// the caller will detect this on the next refresh.
@@ -205,7 +210,7 @@ WebDatabase::State AutofillWebDataBackendImpl::UpdateAutofillProfile(
WebDatabase::State AutofillWebDataBackendImpl::RemoveAutofillProfile(
const std::string& guid, WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
AutofillProfile* profile = NULL;
if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) {
NOTREACHED();
@@ -229,7 +234,7 @@ WebDatabase::State AutofillWebDataBackendImpl::RemoveAutofillProfile(
scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::GetAutofillProfiles(
WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
std::vector<AutofillProfile*> profiles;
AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles);
return scoped_ptr<WDTypedResult>(
@@ -242,7 +247,7 @@ scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::GetAutofillProfiles(
WebDatabase::State AutofillWebDataBackendImpl::AddCreditCard(
const CreditCard& credit_card, WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) {
NOTREACHED();
return WebDatabase::COMMIT_NOT_NEEDED;
@@ -253,7 +258,7 @@ WebDatabase::State AutofillWebDataBackendImpl::AddCreditCard(
WebDatabase::State AutofillWebDataBackendImpl::UpdateCreditCard(
const CreditCard& credit_card, WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
// It is currently valid to try to update a missing profile. We simply drop
// the write and the caller will detect this on the next refresh.
CreditCard* original_credit_card = NULL;
@@ -272,7 +277,7 @@ WebDatabase::State AutofillWebDataBackendImpl::UpdateCreditCard(
WebDatabase::State AutofillWebDataBackendImpl::RemoveCreditCard(
const std::string& guid, WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) {
NOTREACHED();
return WebDatabase::COMMIT_NOT_NEEDED;
@@ -282,7 +287,7 @@ WebDatabase::State AutofillWebDataBackendImpl::RemoveCreditCard(
scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::GetCreditCards(
WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
std::vector<CreditCard*> credit_cards;
AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards);
return scoped_ptr<WDTypedResult>(
@@ -298,7 +303,7 @@ WebDatabase::State
const base::Time& delete_begin,
const base::Time& delete_end,
WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
std::vector<std::string> profile_guids;
std::vector<std::string> credit_card_guids;
if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween(
@@ -324,7 +329,7 @@ WebDatabase::State AutofillWebDataBackendImpl::RemoveOriginURLsModifiedBetween(
const base::Time& delete_begin,
const base::Time& delete_end,
WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
ScopedVector<AutofillProfile> profiles;
if (AutofillTable::FromWebDatabase(db)->RemoveOriginURLsModifiedBetween(
delete_begin, delete_end, &profiles)) {
@@ -345,7 +350,7 @@ WebDatabase::State AutofillWebDataBackendImpl::RemoveOriginURLsModifiedBetween(
WebDatabase::State AutofillWebDataBackendImpl::RemoveExpiredFormElementsImpl(
WebDatabase* db) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(db_thread_->BelongsToCurrentThread());
AutofillChangeList changes;
if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) {
diff --git a/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h b/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h
index 8015dd4..6db3f99 100644
--- a/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h
+++ b/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h
@@ -6,6 +6,7 @@
#define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMPL_H_
#include "base/memory/ref_counted.h"
+#include "base/memory/ref_counted_delete_on_message_loop.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/supports_user_data.h"
@@ -16,7 +17,10 @@
#include "components/webdata/common/web_data_service_base.h"
#include "components/webdata/common/web_data_service_consumer.h"
#include "components/webdata/common/web_database.h"
-#include "content/public/browser/browser_thread.h"
+
+namespace base {
+class MessageLoopProxy;
+}
class WebDataServiceBackend;
@@ -32,17 +36,21 @@ class CreditCard;
// in it should only be called from that thread. Most functions here are just
// the implementations of the corresponding functions in the Autofill
// WebDataService.
+// This class is destroyed on the DB thread.
class AutofillWebDataBackendImpl
- : public base::RefCountedThreadSafe<AutofillWebDataBackendImpl,
- content::BrowserThread::DeleteOnDBThread>,
+ : public base::RefCountedDeleteOnMessageLoop<AutofillWebDataBackendImpl>,
public AutofillWebDataBackend {
public:
// |web_database_backend| is used to access the WebDatabase directly for
- // Sync-related operations. |on_changed_callback| is a closure which can be
- // used to notify the UI thread of changes initiated by Sync (this callback
- // may be called multiple times).
+ // Sync-related operations. |ui_thread| and |db_thread| are the threads that
+ // this class uses as its UI and DB threads respectively.
+ // |on_changed_callback| is a closure which can be used to notify the UI
+ // thread of changes initiated by Sync (this callback may be called multiple
+ // times).
AutofillWebDataBackendImpl(
scoped_refptr<WebDataServiceBackend> web_database_backend,
+ scoped_refptr<base::MessageLoopProxy> ui_thread,
+ scoped_refptr<base::MessageLoopProxy> db_thread,
const base::Closure& on_changed_callback);
// AutofillWebDataBackend implementation.
@@ -137,13 +145,8 @@ class AutofillWebDataBackendImpl
virtual ~AutofillWebDataBackendImpl();
private:
- friend struct content::BrowserThread::DeleteOnThread<
- content::BrowserThread::DB>;
+ friend class base::RefCountedDeleteOnMessageLoop<AutofillWebDataBackendImpl>;
friend class base::DeleteHelper<AutofillWebDataBackendImpl>;
- // We have to friend RCTS<> so WIN shared-lib build is happy
- // (http://crbug/112250).
- friend class base::RefCountedThreadSafe<AutofillWebDataBackendImpl,
- content::BrowserThread::DeleteOnDBThread>;
// This makes the destructor public, and thus allows us to aggregate
// SupportsUserData. It is private by default to prevent incorrect
@@ -157,6 +160,12 @@ class AutofillWebDataBackendImpl
DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable);
};
+ // The MessageLoopProxy that this class uses as its UI thread.
+ scoped_refptr<base::MessageLoopProxy> ui_thread_;
+
+ // The MessageLoopProxy that this class uses as its DB thread.
+ scoped_refptr<base::MessageLoopProxy> db_thread_;
+
// Storage for user data to be accessed only on the DB thread. May
// be used e.g. for SyncableService subclasses that need to be owned
// by this object. Is created on first call to |GetDBUserData()|.
diff --git a/components/autofill/core/browser/webdata/autofill_webdata_service.cc b/components/autofill/core/browser/webdata/autofill_webdata_service.cc
index bc4f65a..dbf9854 100644
--- a/components/autofill/core/browser/webdata/autofill_webdata_service.cc
+++ b/components/autofill/core/browser/webdata/autofill_webdata_service.cc
@@ -4,6 +4,7 @@
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "components/autofill/core/browser/autofill_country.h"
@@ -17,6 +18,7 @@
#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;
@@ -38,6 +40,8 @@ AutofillWebDataService::AutofillWebDataService(
autofill_backend_ = new AutofillWebDataBackendImpl(
wdbs_->GetBackend(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
on_changed_callback);
}
@@ -45,7 +49,10 @@ AutofillWebDataService::AutofillWebDataService()
: WebDataServiceBase(NULL, WebDataServiceBase::ProfileErrorCallback(),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)),
weak_ptr_factory_(this),
- autofill_backend_(new AutofillWebDataBackendImpl(NULL, base::Closure())) {
+ autofill_backend_(new AutofillWebDataBackendImpl(NULL,
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
+ base::Closure())) {
}
void AutofillWebDataService::ShutdownOnUIThread() {