Commit ac63a036 authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Fix crash in AccountReconcilor::Lock::~Lock()

The lock can now outlive the AccountReconcilor.

Bug: 923094
Change-Id: I92443549d50354eb1418fe8495dddea5bf310d5d
Reviewed-on: https://chromium-review.googlesource.com/c/1425499Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625150}
parent 9963c133
...@@ -158,14 +158,15 @@ std::string PickFirstGaiaAccount( ...@@ -158,14 +158,15 @@ std::string PickFirstGaiaAccount(
} // namespace } // namespace
AccountReconcilor::Lock::Lock(AccountReconcilor* reconcilor) AccountReconcilor::Lock::Lock(AccountReconcilor* reconcilor)
: reconcilor_(reconcilor) { : reconcilor_(reconcilor->weak_factory_.GetWeakPtr()) {
DCHECK(reconcilor_); DCHECK(reconcilor_);
reconcilor_->IncrementLockCount(); reconcilor_->IncrementLockCount();
} }
AccountReconcilor::Lock::~Lock() { AccountReconcilor::Lock::~Lock() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
reconcilor_->DecrementLockCount(); if (reconcilor_)
reconcilor_->DecrementLockCount();
} }
AccountReconcilor::ScopedSyncedDataDeletion::ScopedSyncedDataDeletion( AccountReconcilor::ScopedSyncedDataDeletion::ScopedSyncedDataDeletion(
......
...@@ -53,7 +53,7 @@ class AccountReconcilor : public KeyedService, ...@@ -53,7 +53,7 @@ class AccountReconcilor : public KeyedService,
~Lock(); ~Lock();
private: private:
AccountReconcilor* reconcilor_; base::WeakPtr<AccountReconcilor> reconcilor_;
THREAD_CHECKER(thread_checker_); THREAD_CHECKER(thread_checker_);
DISALLOW_COPY_AND_ASSIGN(Lock); DISALLOW_COPY_AND_ASSIGN(Lock);
}; };
......
...@@ -2782,3 +2782,10 @@ TEST_F(AccountReconcilorTest, ScopedSyncedDataDeletionDestructionOrder) { ...@@ -2782,3 +2782,10 @@ TEST_F(AccountReconcilorTest, ScopedSyncedDataDeletionDestructionOrder) {
DeleteReconcilor(); DeleteReconcilor();
// data_deletion is destroyed after the reconcilor, this should not crash. // data_deletion is destroyed after the reconcilor, this should not crash.
} }
TEST_F(AccountReconcilorTest, LockDestructionOrder) {
AccountReconcilor* reconcilor = GetMockReconcilor();
AccountReconcilor::Lock lock(reconcilor);
DeleteReconcilor();
// |lock| is destroyed after the reconcilor, this should not crash.
}
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