Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Unified Diff: components/subresource_filter/content/browser/verified_ruleset_dealer.cc

Issue 2670543002: Introduce VerifiedRuleset and its async Handle. (Closed)
Patch Set: Address comments; fix memory leak in tests. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/subresource_filter/content/browser/verified_ruleset_dealer.cc
diff --git a/components/subresource_filter/content/browser/verified_ruleset_dealer.cc b/components/subresource_filter/content/browser/verified_ruleset_dealer.cc
index cb6b79d72d7bf828f5bbb0a94c87120b57822c3f..fab4ae86807b277106d083aee981b5909efcbdc7 100644
--- a/components/subresource_filter/content/browser/verified_ruleset_dealer.cc
+++ b/components/subresource_filter/content/browser/verified_ruleset_dealer.cc
@@ -14,6 +14,8 @@
namespace subresource_filter {
+// VerifiedRulesetDealer and its Handle. ---------------------------------------
+
VerifiedRulesetDealer::VerifiedRulesetDealer() = default;
VerifiedRulesetDealer::~VerifiedRulesetDealer() = default;
@@ -78,4 +80,37 @@ void VerifiedRulesetDealer::Handle::SetRulesetFile(base::File file) {
base::Unretained(dealer_.get()), base::Passed(&file)));
}
+// VerifiedRuleset and its Handle. ---------------------------------------------
+
+VerifiedRuleset::VerifiedRuleset() {
+ thread_checker_.DetachFromThread();
+}
+
+VerifiedRuleset::~VerifiedRuleset() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+}
+
+void VerifiedRuleset::Initialize(VerifiedRulesetDealer* dealer) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(dealer);
+ ruleset_ = dealer->GetRuleset();
+}
+
+VerifiedRuleset::Handle::Handle(VerifiedRulesetDealer::Handle* dealer_handle)
+ : task_runner_(dealer_handle->task_runner()),
+ ruleset_(new VerifiedRuleset, base::OnTaskRunnerDeleter(task_runner_)) {
+ dealer_handle->GetDealerAsync(base::Bind(&VerifiedRuleset::Initialize,
+ base::Unretained(ruleset_.get())));
+}
+
+VerifiedRuleset::Handle::~Handle() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+}
+
+void VerifiedRuleset::Handle::GetRulesetAsync(
+ base::Callback<void(VerifiedRuleset*)> callback) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ task_runner_->PostTask(FROM_HERE, base::Bind(callback, ruleset_.get()));
+}
+
} // namespace subresource_filter

Powered by Google App Engine
This is Rietveld 408576698