Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
| 6 | 6 |
| 7 BrowsingDataRemoverCompletionObserver::BrowsingDataRemoverCompletionObserver( | 7 BrowsingDataRemoverCompletionObserver::BrowsingDataRemoverCompletionObserver( |
| 8 BrowsingDataRemover* remover) | 8 BrowsingDataRemover* remover) |
| 9 : message_loop_runner_(new content::MessageLoopRunner), observer_(this) { | 9 : message_loop_runner_(new content::MessageLoopRunner), observer_(this) { |
| 10 observer_.Add(remover); | 10 observer_.Add(remover); |
| 11 } | 11 } |
| 12 | 12 |
| 13 BrowsingDataRemoverCompletionObserver:: | 13 BrowsingDataRemoverCompletionObserver:: |
| 14 ~BrowsingDataRemoverCompletionObserver() {} | 14 ~BrowsingDataRemoverCompletionObserver() {} |
| 15 | 15 |
| 16 void BrowsingDataRemoverCompletionObserver::BlockUntilCompletion() { | 16 void BrowsingDataRemoverCompletionObserver::BlockUntilCompletion() { |
| 17 message_loop_runner_->Run(); | 17 message_loop_runner_->Run(); |
| 18 } | 18 } |
| 19 | 19 |
| 20 void BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone() { | 20 void BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone() { |
| 21 observer_.RemoveAll(); | 21 observer_.RemoveAll(); |
| 22 message_loop_runner_->Quit(); | 22 message_loop_runner_->Quit(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 BrowsingDataRemoverCompletionInhibitor::BrowsingDataRemoverCompletionInhibitor() | 25 BrowsingDataRemoverCompletionInhibitor::BrowsingDataRemoverCompletionInhibitor( |
| 26 BrowsingDataRemover* remover) | |
| 26 : message_loop_runner_(new content::MessageLoopRunner) { | 27 : message_loop_runner_(new content::MessageLoopRunner) { |
| 27 BrowsingDataRemoverImpl::set_completion_inhibitor_for_testing(this); | 28 DCHECK(remover); |
| 29 remover_ = remover->GetWeakPtr(); | |
| 30 remover_->SetWouldCompleteCallbackForTesting( | |
| 31 base::Bind(&BrowsingDataRemoverCompletionInhibitor:: | |
| 32 OnBrowsingDataRemoverWouldComplete, | |
| 33 base::Unretained(this))); | |
| 28 } | 34 } |
| 29 | 35 |
| 30 BrowsingDataRemoverCompletionInhibitor:: | 36 BrowsingDataRemoverCompletionInhibitor:: |
| 31 ~BrowsingDataRemoverCompletionInhibitor() { | 37 ~BrowsingDataRemoverCompletionInhibitor() { |
| 32 BrowsingDataRemoverImpl::set_completion_inhibitor_for_testing(nullptr); | 38 // BrowsingDataRemoverCompletionInhibitor might outlive BrowsingDataRemover |
| 39 // in some tests. | |
|
Bernhard Bauer
2017/04/10 23:29:37
So sometimes this class outlives the BrowsingDataR
msramek
2017/04/11 13:13:03
The unittest contains a testcase specifically abou
Bernhard Bauer
2017/04/11 15:58:41
(Which BTW was just a workaround for the fact that
msramek
2017/04/11 19:46:19
Huh. I remember seeing it now, but I guess I wasn'
Bernhard Bauer
2017/04/12 00:12:55
No, only in the instances where the BrowsingDataRe
msramek
2017/04/12 12:18:35
I see. I though you meant the other way around, be
| |
| 40 if (!remover_) | |
| 41 return; | |
| 42 remover_->SetWouldCompleteCallbackForTesting( | |
| 43 base::Callback<void(const base::Closure&)>()); | |
| 33 } | 44 } |
| 34 | 45 |
| 35 void BrowsingDataRemoverCompletionInhibitor::BlockUntilNearCompletion() { | 46 void BrowsingDataRemoverCompletionInhibitor::BlockUntilNearCompletion() { |
| 36 message_loop_runner_->Run(); | 47 message_loop_runner_->Run(); |
| 37 message_loop_runner_ = new content::MessageLoopRunner; | 48 message_loop_runner_ = new content::MessageLoopRunner; |
| 38 } | 49 } |
| 39 | 50 |
| 40 void BrowsingDataRemoverCompletionInhibitor::ContinueToCompletion() { | 51 void BrowsingDataRemoverCompletionInhibitor::ContinueToCompletion() { |
| 41 DCHECK(!continue_to_completion_callback_.is_null()); | 52 DCHECK(!continue_to_completion_callback_.is_null()); |
| 42 continue_to_completion_callback_.Run(); | 53 continue_to_completion_callback_.Run(); |
| 43 continue_to_completion_callback_.Reset(); | 54 continue_to_completion_callback_.Reset(); |
| 44 } | 55 } |
| 45 | 56 |
| 46 void BrowsingDataRemoverCompletionInhibitor::OnBrowsingDataRemoverWouldComplete( | 57 void BrowsingDataRemoverCompletionInhibitor::OnBrowsingDataRemoverWouldComplete( |
| 47 BrowsingDataRemoverImpl* remover, | |
| 48 const base::Closure& continue_to_completion) { | 58 const base::Closure& continue_to_completion) { |
| 49 DCHECK(continue_to_completion_callback_.is_null()); | 59 DCHECK(continue_to_completion_callback_.is_null()); |
| 50 continue_to_completion_callback_ = continue_to_completion; | 60 continue_to_completion_callback_ = continue_to_completion; |
| 51 message_loop_runner_->Quit(); | 61 message_loop_runner_->Quit(); |
| 52 } | 62 } |
| OLD | NEW |