summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorzea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-04 21:30:17 +0000
committerzea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-04 21:30:17 +0000
commita74507d345c15f077dcd72b810185ade89fedce5 (patch)
tree8d5ec7f5409c75cf0417cc09b93a0b4c469867eb /chrome
parent0baf54ea99585819b1f2c5ad1f87c83ae8138751 (diff)
downloadchromium_src-a74507d345c15f077dcd72b810185ade89fedce5.zip
chromium_src-a74507d345c15f077dcd72b810185ade89fedce5.tar.gz
chromium_src-a74507d345c15f077dcd72b810185ade89fedce5.tar.bz2
Add barrier to autofill datatype controller shutdown.
We need to ensure that datatypes that live on foreign threads have fully stopped before returning from the data type controller's Stop method, else race conditions can occur. Added a barrier into the autofill data type controller to make this happen. BUG=61804 TEST=Start up chrome, sign in to sync, shut down, make sure nothing breaks. Review URL: http://codereview.chromium.org/4481002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65115 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/sync/glue/autofill_data_type_controller.cc16
-rw-r--r--chrome/browser/sync/glue/autofill_data_type_controller.h4
2 files changed, 17 insertions, 3 deletions
diff --git a/chrome/browser/sync/glue/autofill_data_type_controller.cc b/chrome/browser/sync/glue/autofill_data_type_controller.cc
index 4585101..2598977 100644
--- a/chrome/browser/sync/glue/autofill_data_type_controller.cc
+++ b/chrome/browser/sync/glue/autofill_data_type_controller.cc
@@ -29,7 +29,8 @@ AutofillDataTypeController::AutofillDataTypeController(
state_(NOT_RUNNING),
personal_data_(NULL),
abort_association_(false),
- abort_association_complete_(false, false) {
+ abort_association_complete_(false, false),
+ datatype_stopped_(false, false) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(profile_sync_factory);
DCHECK(profile);
@@ -136,10 +137,15 @@ void AutofillDataTypeController::Stop() {
model_associator_->DisassociateModels();
set_state(NOT_RUNNING);
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ if (BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
NewRunnableMethod(
this,
- &AutofillDataTypeController::StopImpl));
+ &AutofillDataTypeController::StopImpl))) {
+ // We need to ensure the data type has fully stoppped before continuing. In
+ // particular, during shutdown we may attempt to destroy the
+ // profile_sync_service before we've removed its observers (BUG 61804).
+ datatype_stopped_.Wait();
+ }
}
void AutofillDataTypeController::StartImpl() {
@@ -173,6 +179,8 @@ void AutofillDataTypeController::StartImpl() {
bool merge_success = model_associator_->AssociateModels();
UMA_HISTOGRAM_TIMES("Sync.AutofillAssociationTime",
base::TimeTicks::Now() - start_time);
+ VLOG(1) << "Autofill association time: " <<
+ (base::TimeTicks::Now() - start_time).InSeconds();
if (!merge_success) {
StartFailed(ASSOCIATION_FAILED);
return;
@@ -223,6 +231,8 @@ void AutofillDataTypeController::StopImpl() {
change_processor_.reset();
model_associator_.reset();
+
+ datatype_stopped_.Signal();
}
void AutofillDataTypeController::StartFailed(StartResult result) {
diff --git a/chrome/browser/sync/glue/autofill_data_type_controller.h b/chrome/browser/sync/glue/autofill_data_type_controller.h
index 1def2d2..d22fcfaf 100644
--- a/chrome/browser/sync/glue/autofill_data_type_controller.h
+++ b/chrome/browser/sync/glue/autofill_data_type_controller.h
@@ -109,6 +109,10 @@ class AutofillDataTypeController : public DataTypeController,
bool abort_association_;
base::WaitableEvent abort_association_complete_;
+ // Barrier to ensure that the datatype has been stopped on the DB thread
+ // from the UI thread.
+ base::WaitableEvent datatype_stopped_;
+
DISALLOW_COPY_AND_ASSIGN(AutofillDataTypeController);
};