-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
ruleset_publisher_impl.h
79 lines (64 loc) · 3.15 KB
/
ruleset_publisher_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_RULESET_PUBLISHER_IMPL_H_
#define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_RULESET_PUBLISHER_IMPL_H_
#include <memory>
#include "base/callback.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "components/subresource_filter/content/browser/ruleset_publisher.h"
#include "components/subresource_filter/content/browser/ruleset_version.h"
#include "components/subresource_filter/content/browser/verified_ruleset_dealer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/render_process_host.h"
namespace subresource_filter {
class RulesetService;
// The implementation of RulesetPublisher. Owned by the underlying
// RulesetService. Its main responsibility is receiving new versions of
// subresource filtering rules from the RulesetService, and distributing them to
// renderer processes, where they will be memory-mapped as-needed by the
// UnverifiedRulesetDealer.
class RulesetPublisherImpl : public RulesetPublisher,
public content::NotificationObserver {
public:
RulesetPublisherImpl(
RulesetService* ruleset_service,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
~RulesetPublisherImpl() override;
// RulesetPublisher:
void TryOpenAndSetRulesetFile(
const base::FilePath& file_path,
int expected_checksum,
base::OnceCallback<void(RulesetFilePtr)> callback) override;
void PublishNewRulesetVersion(RulesetFilePtr ruleset_data) override;
scoped_refptr<base::SingleThreadTaskRunner> BestEffortTaskRunner() override;
VerifiedRulesetDealer::Handle* GetRulesetDealer() override;
void SetRulesetPublishedCallbackForTesting(
base::OnceClosure callback) override;
// Forwards calls to the underlying ruleset_service_.
void IndexAndStoreAndPublishRulesetIfNeeded(
const UnindexedRulesetInfo& unindex_ruleset_info);
protected:
virtual void SendRulesetToRenderProcess(base::File* file,
content::RenderProcessHost* rph);
private:
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
content::NotificationRegistrar notification_registrar_;
RulesetFilePtr ruleset_data_{nullptr, base::OnTaskRunnerDeleter{nullptr}};
base::OnceClosure ruleset_published_callback_;
// The service owns the publisher, and therefore outlives it.
RulesetService* ruleset_service_;
std::unique_ptr<VerifiedRulesetDealer::Handle> ruleset_dealer_;
scoped_refptr<base::SingleThreadTaskRunner> best_effort_task_runner_;
DISALLOW_COPY_AND_ASSIGN(RulesetPublisherImpl);
};
} // namespace subresource_filter
#endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_RULESET_SERVICE_H_