| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_impl.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 net::ChannelIDService* channel_id_service = | 144 net::ChannelIDService* channel_id_service = |
| 145 rq_context->GetURLRequestContext()->channel_id_service(); | 145 rq_context->GetURLRequestContext()->channel_id_service(); |
| 146 channel_id_service->GetChannelIDStore()->DeleteForDomainsCreatedBetween( | 146 channel_id_service->GetChannelIDStore()->DeleteForDomainsCreatedBetween( |
| 147 domain_predicate, delete_begin, delete_end, | 147 domain_predicate, delete_begin, delete_end, |
| 148 base::Bind(&OnClearedChannelIDsOnIOThread, | 148 base::Bind(&OnClearedChannelIDsOnIOThread, |
| 149 base::RetainedRef(std::move(rq_context)), callback)); | 149 base::RetainedRef(std::move(rq_context)), callback)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 } // namespace | 152 } // namespace |
| 153 | 153 |
| 154 BrowsingDataRemoverImpl::CompletionInhibitor* | |
| 155 BrowsingDataRemoverImpl::completion_inhibitor_ = nullptr; | |
| 156 | |
| 157 BrowsingDataRemoverImpl::SubTask::SubTask(const base::Closure& forward_callback) | 154 BrowsingDataRemoverImpl::SubTask::SubTask(const base::Closure& forward_callback) |
| 158 : is_pending_(false), | 155 : is_pending_(false), |
| 159 forward_callback_(forward_callback), | 156 forward_callback_(forward_callback), |
| 160 weak_ptr_factory_(this) { | 157 weak_ptr_factory_(this) { |
| 161 DCHECK(!forward_callback_.is_null()); | 158 DCHECK(!forward_callback_.is_null()); |
| 162 } | 159 } |
| 163 | 160 |
| 164 BrowsingDataRemoverImpl::SubTask::~SubTask() {} | 161 BrowsingDataRemoverImpl::SubTask::~SubTask() {} |
| 165 | 162 |
| 166 void BrowsingDataRemoverImpl::SubTask::Start() { | 163 void BrowsingDataRemoverImpl::SubTask::Start() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 189 is_removing_(false), | 186 is_removing_(false), |
| 190 sub_task_forward_callback_( | 187 sub_task_forward_callback_( |
| 191 base::Bind(&BrowsingDataRemoverImpl::NotifyIfDone, | 188 base::Bind(&BrowsingDataRemoverImpl::NotifyIfDone, |
| 192 base::Unretained(this))), | 189 base::Unretained(this))), |
| 193 synchronous_clear_operations_(sub_task_forward_callback_), | 190 synchronous_clear_operations_(sub_task_forward_callback_), |
| 194 clear_embedder_data_(sub_task_forward_callback_), | 191 clear_embedder_data_(sub_task_forward_callback_), |
| 195 clear_cache_(sub_task_forward_callback_), | 192 clear_cache_(sub_task_forward_callback_), |
| 196 clear_channel_ids_(sub_task_forward_callback_), | 193 clear_channel_ids_(sub_task_forward_callback_), |
| 197 clear_http_auth_cache_(sub_task_forward_callback_), | 194 clear_http_auth_cache_(sub_task_forward_callback_), |
| 198 clear_storage_partition_data_(sub_task_forward_callback_), | 195 clear_storage_partition_data_(sub_task_forward_callback_), |
| 196 storage_partition_for_testing_(nullptr), |
| 199 weak_ptr_factory_(this) { | 197 weak_ptr_factory_(this) { |
| 200 DCHECK(browser_context_); | 198 DCHECK(browser_context_); |
| 201 } | 199 } |
| 202 | 200 |
| 203 BrowsingDataRemoverImpl::~BrowsingDataRemoverImpl() { | 201 BrowsingDataRemoverImpl::~BrowsingDataRemoverImpl() { |
| 204 if (!task_queue_.empty()) { | 202 if (!task_queue_.empty()) { |
| 205 VLOG(1) << "BrowsingDataRemoverImpl shuts down with " << task_queue_.size() | 203 VLOG(1) << "BrowsingDataRemoverImpl shuts down with " << task_queue_.size() |
| 206 << " pending tasks"; | 204 << " pending tasks"; |
| 207 } | 205 } |
| 208 | 206 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 } | 568 } |
| 571 | 569 |
| 572 void BrowsingDataRemoverImpl::AddObserver(Observer* observer) { | 570 void BrowsingDataRemoverImpl::AddObserver(Observer* observer) { |
| 573 observer_list_.AddObserver(observer); | 571 observer_list_.AddObserver(observer); |
| 574 } | 572 } |
| 575 | 573 |
| 576 void BrowsingDataRemoverImpl::RemoveObserver(Observer* observer) { | 574 void BrowsingDataRemoverImpl::RemoveObserver(Observer* observer) { |
| 577 observer_list_.RemoveObserver(observer); | 575 observer_list_.RemoveObserver(observer); |
| 578 } | 576 } |
| 579 | 577 |
| 578 void BrowsingDataRemoverImpl::SetWouldCompleteCallbackForTesting( |
| 579 const base::Callback<void(const base::Closure& continue_to_completion)>& |
| 580 callback) { |
| 581 would_complete_callback_ = callback; |
| 582 } |
| 583 |
| 580 void BrowsingDataRemoverImpl::OverrideStoragePartitionForTesting( | 584 void BrowsingDataRemoverImpl::OverrideStoragePartitionForTesting( |
| 581 content::StoragePartition* storage_partition) { | 585 content::StoragePartition* storage_partition) { |
| 582 storage_partition_for_testing_ = storage_partition; | 586 storage_partition_for_testing_ = storage_partition; |
| 583 } | 587 } |
| 584 | 588 |
| 585 const base::Time& BrowsingDataRemoverImpl::GetLastUsedBeginTime() { | 589 const base::Time& BrowsingDataRemoverImpl::GetLastUsedBeginTime() { |
| 586 return delete_begin_; | 590 return delete_begin_; |
| 587 } | 591 } |
| 588 | 592 |
| 589 const base::Time& BrowsingDataRemoverImpl::GetLastUsedEndTime() { | 593 const base::Time& BrowsingDataRemoverImpl::GetLastUsedEndTime() { |
| 590 return delete_end_; | 594 return delete_end_; |
| 591 } | 595 } |
| 592 | 596 |
| 593 int BrowsingDataRemoverImpl::GetLastUsedRemovalMask() { | 597 int BrowsingDataRemoverImpl::GetLastUsedRemovalMask() { |
| 594 return remove_mask_; | 598 return remove_mask_; |
| 595 } | 599 } |
| 596 | 600 |
| 597 int BrowsingDataRemoverImpl::GetLastUsedOriginTypeMask() { | 601 int BrowsingDataRemoverImpl::GetLastUsedOriginTypeMask() { |
| 598 return origin_type_mask_; | 602 return origin_type_mask_; |
| 599 } | 603 } |
| 600 | 604 |
| 605 base::WeakPtr<BrowsingDataRemover> BrowsingDataRemoverImpl::GetWeakPtr() { |
| 606 return GetImplWeakPtr(); |
| 607 } |
| 608 |
| 601 BrowsingDataRemoverImpl::RemovalTask::RemovalTask( | 609 BrowsingDataRemoverImpl::RemovalTask::RemovalTask( |
| 602 const base::Time& delete_begin, | 610 const base::Time& delete_begin, |
| 603 const base::Time& delete_end, | 611 const base::Time& delete_end, |
| 604 int remove_mask, | 612 int remove_mask, |
| 605 int origin_type_mask, | 613 int origin_type_mask, |
| 606 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, | 614 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, |
| 607 Observer* observer) | 615 Observer* observer) |
| 608 : delete_begin(delete_begin), | 616 : delete_begin(delete_begin), |
| 609 delete_end(delete_end), | 617 delete_end(delete_end), |
| 610 remove_mask(remove_mask), | 618 remove_mask(remove_mask), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 // All removal tasks have finished. Inform the observers that we're idle. | 657 // All removal tasks have finished. Inform the observers that we're idle. |
| 650 SetRemoving(false); | 658 SetRemoving(false); |
| 651 return; | 659 return; |
| 652 } | 660 } |
| 653 | 661 |
| 654 // Yield to the UI thread before executing the next removal task. | 662 // Yield to the UI thread before executing the next removal task. |
| 655 // TODO(msramek): Consider also adding a backoff if too many tasks | 663 // TODO(msramek): Consider also adding a backoff if too many tasks |
| 656 // are scheduled. | 664 // are scheduled. |
| 657 BrowserThread::PostTask( | 665 BrowserThread::PostTask( |
| 658 BrowserThread::UI, FROM_HERE, | 666 BrowserThread::UI, FROM_HERE, |
| 659 base::Bind(&BrowsingDataRemoverImpl::RunNextTask, GetWeakPtr())); | 667 base::Bind(&BrowsingDataRemoverImpl::RunNextTask, GetImplWeakPtr())); |
| 660 } | 668 } |
| 661 | 669 |
| 662 void BrowsingDataRemoverImpl::NotifyIfDone() { | 670 void BrowsingDataRemoverImpl::NotifyIfDone() { |
| 663 // TODO(brettw) http://crbug.com/305259: This should also observe session | 671 // TODO(brettw) http://crbug.com/305259: This should also observe session |
| 664 // clearing (what about other things such as passwords, etc.?) and wait for | 672 // clearing (what about other things such as passwords, etc.?) and wait for |
| 665 // them to complete before continuing. | 673 // them to complete before continuing. |
| 666 | 674 |
| 667 if (!AllDone()) | 675 if (!AllDone()) |
| 668 return; | 676 return; |
| 669 | 677 |
| 670 if (completion_inhibitor_) { | 678 if (!would_complete_callback_.is_null()) { |
| 671 completion_inhibitor_->OnBrowsingDataRemoverWouldComplete( | 679 would_complete_callback_.Run( |
| 672 this, base::Bind(&BrowsingDataRemoverImpl::Notify, GetWeakPtr())); | 680 base::Bind(&BrowsingDataRemoverImpl::Notify, GetImplWeakPtr())); |
| 673 return; | 681 return; |
| 674 } | 682 } |
| 675 | 683 |
| 676 Notify(); | 684 Notify(); |
| 677 } | 685 } |
| 678 | 686 |
| 679 base::WeakPtr<BrowsingDataRemoverImpl> BrowsingDataRemoverImpl::GetWeakPtr() { | 687 base::WeakPtr<BrowsingDataRemoverImpl> |
| 688 BrowsingDataRemoverImpl::GetImplWeakPtr() { |
| 680 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 689 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 681 base::WeakPtr<BrowsingDataRemoverImpl> weak_ptr = | 690 base::WeakPtr<BrowsingDataRemoverImpl> weak_ptr = |
| 682 weak_ptr_factory_.GetWeakPtr(); | 691 weak_ptr_factory_.GetWeakPtr(); |
| 683 | 692 |
| 684 // Immediately bind the weak pointer to the UI thread. This makes it easier | 693 // Immediately bind the weak pointer to the UI thread. This makes it easier |
| 685 // to discover potential misuse on the IO thread. | 694 // to discover potential misuse on the IO thread. |
| 686 weak_ptr.get(); | 695 weak_ptr.get(); |
| 687 | 696 |
| 688 return weak_ptr; | 697 return weak_ptr; |
| 689 } | 698 } |
| OLD | NEW |