Commit 1f2e0a08 authored by Karan Bhatia's avatar Karan Bhatia Committed by Commit Bot

Declarative Net Request: Refactor RulesMonitorService (2/2).

This CL refactors RulesMonitorService. In particular, inner classes
FileSequenceState and FileSequenceBridge are introduced to handle the file
sequence operations. Also, while loading a ruleset on the file sequence, instead
of hopping directly to the IO thread, we return the result to the UI thread,
which then decides what to do. And unloading a ruleset now proceeds directly to
the IO thread instead of hopping to the file sequence first. This refactoring is
in preparation for a subsequent CL which will handle indexed ruleset corruption.

This CL does not introduce any behavior change.

BUG=852058

Change-Id: Idad96dcacc4563c1936890daf3c7bd548b9d4319
Reviewed-on: https://chromium-review.googlesource.com/1119635
Commit-Queue: Karan Bhatia <karandeepb@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573545}
parent f38e8cee
...@@ -10,15 +10,12 @@ ...@@ -10,15 +10,12 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "extensions/browser/browser_context_keyed_api_factory.h" #include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_registry_observer.h" #include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension_id.h" #include "extensions/common/extension_id.h"
namespace base {
class SequencedTaskRunner;
} // namespace base
namespace content { namespace content {
class BrowserContext; class BrowserContext;
} // namespace content } // namespace content
...@@ -26,8 +23,10 @@ class BrowserContext; ...@@ -26,8 +23,10 @@ class BrowserContext;
namespace extensions { namespace extensions {
class InfoMap; class InfoMap;
class ExtensionPrefs; class ExtensionPrefs;
class ExtensionRegistry;
namespace declarative_net_request { namespace declarative_net_request {
class RulesetMatcher;
// Observes loading and unloading of extensions to load and unload their // Observes loading and unloading of extensions to load and unload their
// rulesets for the Declarative Net Request API. Lives on the UI thread. Note: A // rulesets for the Declarative Net Request API. Lives on the UI thread. Note: A
...@@ -46,6 +45,10 @@ class RulesMonitorService : public BrowserContextKeyedAPI, ...@@ -46,6 +45,10 @@ class RulesMonitorService : public BrowserContextKeyedAPI,
bool HasRegisteredRuleset(const Extension* extension) const; bool HasRegisteredRuleset(const Extension* extension) const;
private: private:
struct LoadRulesetInfo;
class FileSequenceState;
class FileSequenceBridge;
friend class BrowserContextKeyedAPIFactory<RulesMonitorService>; friend class BrowserContextKeyedAPIFactory<RulesMonitorService>;
// The constructor is kept private since this should only be created by the // The constructor is kept private since this should only be created by the
...@@ -65,15 +68,27 @@ class RulesMonitorService : public BrowserContextKeyedAPI, ...@@ -65,15 +68,27 @@ class RulesMonitorService : public BrowserContextKeyedAPI,
const Extension* extension, const Extension* extension,
UnloadedExtensionReason reason) override; UnloadedExtensionReason reason) override;
// Callback invoked when we have loaded the ruleset for |info| on
// |file_task_runner_|. |matcher| is null iff the ruleset loading failed.
void OnRulesetLoaded(LoadRulesetInfo info,
std::unique_ptr<RulesetMatcher> matcher);
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
registry_observer_; registry_observer_;
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
std::set<ExtensionId> extensions_with_rulesets_; std::set<ExtensionId> extensions_with_rulesets_;
// Helper to bridge tasks to a sequence which allows file IO.
std::unique_ptr<const FileSequenceBridge> file_sequence_bridge_;
// Guaranteed to be valid through-out the lifetime of this instance. // Guaranteed to be valid through-out the lifetime of this instance.
InfoMap* const info_map_; InfoMap* const info_map_;
const ExtensionPrefs* const prefs_; const ExtensionPrefs* const prefs_;
ExtensionRegistry* const extension_registry_;
// Must be the last member variable. See WeakPtrFactory documentation for
// details.
base::WeakPtrFactory<RulesMonitorService> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(RulesMonitorService); DISALLOW_COPY_AND_ASSIGN(RulesMonitorService);
}; };
......
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