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

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

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
« no previous file with comments | « no previous file | components/subresource_filter/content/browser/verified_ruleset_dealer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/subresource_filter/content/browser/verified_ruleset_dealer.h
diff --git a/components/subresource_filter/content/browser/verified_ruleset_dealer.h b/components/subresource_filter/content/browser/verified_ruleset_dealer.h
index 187b7ed97a815a16dd13cccb3ef2ce19df255973..e3e248a64bd321f49e20cf072cab1b076854db60 100644
--- a/components/subresource_filter/content/browser/verified_ruleset_dealer.h
+++ b/components/subresource_filter/content/browser/verified_ruleset_dealer.h
@@ -68,6 +68,10 @@ class VerifiedRulesetDealer::Handle {
explicit Handle(scoped_refptr<base::SequencedTaskRunner> task_runner);
~Handle();
+ // Returns the |task_runner| on which the VerifiedRulesetDealer, as well as
+ // the MemoryMappedRulesets it creates, should be accessed.
+ base::SequencedTaskRunner* task_runner() { return task_runner_; }
+
// Invokes |callback| on |task_runner|, providing a pointer to the underlying
// VerifiedRulesetDealer as an argument. The pointer is guaranteed to be valid
// at least until the callback returns.
@@ -81,7 +85,65 @@ class VerifiedRulesetDealer::Handle {
// Note: Raw pointer, |dealer_| already holds a reference to |task_runner_|.
base::SequencedTaskRunner* task_runner_;
std::unique_ptr<VerifiedRulesetDealer, base::OnTaskRunnerDeleter> dealer_;
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(Handle);
+};
+
+// Holds a strong reference to MemoryMappedRuleset, and provides acceess to it.
+//
+// Initially holds an empty reference, allowing this object to be created on the
+// UI-thread synchronously, hence letting the Handle to be created synchronously
+// and be immediately used by clients on the UI-thread, while the
+// MemoryMappedRuleset is retrieved on the |task_runner| in a deferred manner.
+class VerifiedRuleset {
+ public:
+ class Handle;
+
+ VerifiedRuleset();
+ ~VerifiedRuleset();
+
+ // Can return nullptr even after initialization in case no ruleset is
+ // available, or if the ruleset is corrupted.
+ const MemoryMappedRuleset* Get() const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return ruleset_.get();
+ }
+
+ private:
+ // Initializes |ruleset_| with the one provided by the ruleset |dealer|.
+ void Initialize(VerifiedRulesetDealer* dealer);
+ scoped_refptr<const MemoryMappedRuleset> ruleset_;
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(VerifiedRuleset);
+};
+
+// The UI-thread handle that owns a VerifiedRuleset living on a dedicated
+// sequenced |task_runner|, same as the VerifiedRulesetDealer lives on. Provides
+// asynchronous access to the instance, and destroys it asynchronously.
+class VerifiedRuleset::Handle {
+ public:
+ // Creates a VerifiedRuleset and initializes it asynchronously on a
+ // |task_runner| using |dealer_handle|. The instance remains owned by this
+ // handle, but living and accessed on the |task_runner|.
+ explicit Handle(VerifiedRulesetDealer::Handle* dealer_handle);
+ ~Handle();
+
+ // Returns the |task_runner| on which the VerifiedRuleset, as well as the
+ // MemoryMappedRuleset it holds a reference to, should be accessed.
+ base::SequencedTaskRunner* task_runner() { return task_runner_; }
+
+ // Invokes |callback| on |task_runner|, providing a pointer to the underlying
+ // VerifiedRuleset as an argument. The pointer is guaranteed to be valid at
+ // least until the callback returns.
+ void GetRulesetAsync(base::Callback<void(VerifiedRuleset*)> callback);
+
+ private:
+ // Note: Raw pointer, |ruleset_| already holds a reference to |task_runner_|.
+ base::SequencedTaskRunner* task_runner_;
+ std::unique_ptr<VerifiedRuleset, base::OnTaskRunnerDeleter> ruleset_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(Handle);
« no previous file with comments | « no previous file | components/subresource_filter/content/browser/verified_ruleset_dealer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698