Commit 99312768 authored by Eric Robinson's avatar Eric Robinson Committed by Commit Bot

Remove RulesetServiceDelegate, Rename and move Headers.

See also go/chromerulesetservicemerge.

This CL removes the delegate file from core, and changes it as
well as the ContentRulesetService to the more appropriate name
of RulesetPublisher and RulesetPublisherImpl.  It also splits the
header files appropriately.  The final step will be to split the
source files, which will be done in a follow-up CL.

Change-Id: I2f5b077c9564c81586861b0ecae99f089b2237f3
Reviewed-on: https://chromium-review.googlesource.com/c/1340644Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Commit-Queue: Eric Robinson <ericrobinson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611275}
parent 623fa325
......@@ -16,6 +16,8 @@ static_library("browser") {
"navigation_console_logger.h",
"page_load_statistics.cc",
"page_load_statistics.h",
"ruleset_publisher.h",
"ruleset_publisher_impl.h",
"ruleset_service.cc",
"ruleset_service.h",
"subframe_navigation_filtering_throttle.cc",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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_CORE_BROWSER_RULESET_SERVICE_DELEGATE_H_
#define COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_RULESET_SERVICE_DELEGATE_H_
#ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_RULESET_PUBLISHER_H_
#define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_RULESET_PUBLISHER_H_
#include <memory>
#include <string>
#include "base/callback.h"
#include "base/callback_forward.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "base/single_thread_task_runner.h"
#include "components/subresource_filter/content/browser/verified_ruleset_dealer.h"
class PrefRegistrySimple;
class PrefService;
namespace base {
namespace trace_event {
class TracedValue;
} // namespace trace_event
} // namespace base
namespace subresource_filter {
class VerifiedRulesetDealer;
// Encapsulates information about a version of unindexed subresource
// filtering rules on disk.
struct UnindexedRulesetInfo {
UnindexedRulesetInfo();
~UnindexedRulesetInfo();
// The version of the ruleset contents. Because the wire format of unindexed
// rules is expected to be stable over time (at least backwards compatible),
// the unindexed ruleset is uniquely identified by its content version.
//
// The version string must not be empty, but can be any string otherwise.
// There is no ordering defined on versions.
std::string content_version;
// The path to the file containing the unindexed subresource filtering rules.
base::FilePath ruleset_path;
// The (optional) path to a file containing the applicable license, which will
// be copied next to the indexed ruleset. For convenience, the lack of license
// can be indicated not only by setting |license_path| to empty, but also by
// setting it to any non existent path.
base::FilePath license_path;
};
// Encapsulates the combination of the binary format version of the indexed
// ruleset, and the version of the ruleset contents.
//
// In contrast to the unindexed ruleset, the binary format of the index data
// structures is expected to evolve over time, so the indexed ruleset is
// identified by a pair of versions: the content version of the rules that have
// been indexed; and the binary format version of the indexed data structures.
// It also contains a checksum of the data, to ensure it hasn't been corrupted.
struct IndexedRulesetVersion {
IndexedRulesetVersion();
IndexedRulesetVersion(const std::string& content_version, int format_version);
~IndexedRulesetVersion();
IndexedRulesetVersion& operator=(const IndexedRulesetVersion&);
static void RegisterPrefs(PrefRegistrySimple* registry);
static int CurrentFormatVersion();
bool IsValid() const;
bool IsCurrentFormatVersion() const;
void SaveToPrefs(PrefService* local_state) const;
void ReadFromPrefs(PrefService* local_state);
std::unique_ptr<base::trace_event::TracedValue> ToTracedValue() const;
std::string content_version;
int format_version = 0;
int checksum = 0;
};
// Interface for a delegate that implements RulesetService operations that
// depend on content/, thus allowing the service to not directly depend on it.
class RulesetServiceDelegate {
// Interface for a RulesetService that defines operations that distribute the
// ruleset to the renderer processes via the RulesetDealer.
class RulesetPublisher {
public:
virtual ~RulesetServiceDelegate() = default;
virtual ~RulesetPublisher() = default;
// Schedules file open and use it as ruleset file. In the case of success,
// the new and valid |base::File| is passed to |callback|. In the case of
......@@ -40,14 +105,14 @@ class RulesetServiceDelegate {
virtual scoped_refptr<base::SingleThreadTaskRunner>
BestEffortTaskRunner() = 0;
// Gets the ruleset dealer associated with the RulesetServiceDelegate.
// Gets the ruleset dealer associated with the RulesetPublisher.
virtual VerifiedRulesetDealer::Handle* GetRulesetDealer() = 0;
// Set the callback on publish associated with the RulesetServiceDelegate.
// Set the callback on publish associated with the RulesetPublisher.
virtual void SetRulesetPublishedCallbackForTesting(
base::OnceClosure callback) = 0;
};
} // namespace subresource_filter
#endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_RULESET_SERVICE_DELEGATE_H_
#endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_RULESET_SERVICE_H_
// 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/verified_ruleset_dealer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.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(base::File)> callback) override;
void PublishNewRulesetVersion(base::File 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);
private:
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
content::NotificationRegistrar notification_registrar_;
base::File ruleset_data_;
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_
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "components/subresource_filter/content/browser/ruleset_service.h"
#include "components/subresource_filter/content/browser/ruleset_publisher_impl.h"
#include <utility>
......@@ -28,7 +29,6 @@
#include "components/prefs/pref_service.h"
#include "components/subresource_filter/content/common/subresource_filter_messages.h"
#include "components/subresource_filter/core/browser/copying_file_stream.h"
#include "components/subresource_filter/core/browser/ruleset_service_delegate.h"
#include "components/subresource_filter/core/browser/subresource_filter_constants.h"
#include "components/subresource_filter/core/common/common_features.h"
#include "components/subresource_filter/core/common/indexed_ruleset.h"
......@@ -263,16 +263,16 @@ RulesetService::RulesetService(
scoped_refptr<base::SequencedTaskRunner> background_task_runner,
const base::FilePath& indexed_ruleset_base_dir,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
std::unique_ptr<RulesetServiceDelegate> delegate)
std::unique_ptr<RulesetPublisher> publisher)
: local_state_(local_state),
background_task_runner_(std::move(background_task_runner)),
is_initialized_(false),
indexed_ruleset_base_dir_(indexed_ruleset_base_dir) {
DCHECK_NE(local_state_->GetInitializationStatus(),
PrefService::INITIALIZATION_STATUS_WAITING);
delegate_ = delegate ? std::move(delegate)
: std::make_unique<ContentRulesetService>(
this, blocking_task_runner);
publisher_ = publisher ? std::move(publisher)
: std::make_unique<RulesetPublisherImpl>(
this, blocking_task_runner);
IndexedRulesetVersion most_recently_indexed_version;
most_recently_indexed_version.ReadFromPrefs(local_state_);
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("loading"),
......@@ -285,8 +285,8 @@ RulesetService::RulesetService(
IndexedRulesetVersion().SaveToPrefs(local_state_);
}
DCHECK(delegate_->BestEffortTaskRunner()->BelongsToCurrentThread());
delegate_->BestEffortTaskRunner()->PostTask(
DCHECK(publisher_->BestEffortTaskRunner()->BelongsToCurrentThread());
publisher_->BestEffortTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&RulesetService::FinishInitialization, AsWeakPtr()));
}
......@@ -533,7 +533,7 @@ void RulesetService::OpenAndPublishRuleset(
IndexedRulesetLocator::GetSubdirectoryPathForVersion(
indexed_ruleset_base_dir_, version));
delegate_->TryOpenAndSetRulesetFile(
publisher_->TryOpenAndSetRulesetFile(
file_path, version.checksum,
base::BindOnce(&RulesetService::OnRulesetSet, AsWeakPtr()));
}
......@@ -548,12 +548,12 @@ void RulesetService::OnRulesetSet(base::File file) {
return;
}
delegate_->PublishNewRulesetVersion(std::move(file));
publisher_->PublishNewRulesetVersion(std::move(file));
}
// ContentRulesetService ------------------------------------------------------
// RulesetPublisherImpl ------------------------------------------------------
ContentRulesetService::ContentRulesetService(
RulesetPublisherImpl::RulesetPublisherImpl(
RulesetService* ruleset_service,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner)
: ruleset_service_(ruleset_service),
......@@ -570,16 +570,16 @@ ContentRulesetService::ContentRulesetService(
content::NotificationService::AllBrowserContextsAndSources());
}
ContentRulesetService::~ContentRulesetService() {
RulesetPublisherImpl::~RulesetPublisherImpl() {
CloseFileOnFileThread(&ruleset_data_);
}
void ContentRulesetService::SetRulesetPublishedCallbackForTesting(
void RulesetPublisherImpl::SetRulesetPublishedCallbackForTesting(
base::OnceClosure callback) {
ruleset_published_callback_ = std::move(callback);
}
void ContentRulesetService::TryOpenAndSetRulesetFile(
void RulesetPublisherImpl::TryOpenAndSetRulesetFile(
const base::FilePath& file_path,
int expected_checksum,
base::OnceCallback<void(base::File)> callback) {
......@@ -587,7 +587,7 @@ void ContentRulesetService::TryOpenAndSetRulesetFile(
std::move(callback));
}
void ContentRulesetService::PublishNewRulesetVersion(base::File ruleset_data) {
void RulesetPublisherImpl::PublishNewRulesetVersion(base::File ruleset_data) {
DCHECK(ruleset_data.IsValid());
CloseFileOnFileThread(&ruleset_data_);
......@@ -610,22 +610,22 @@ void ContentRulesetService::PublishNewRulesetVersion(base::File ruleset_data) {
}
scoped_refptr<base::SingleThreadTaskRunner>
ContentRulesetService::BestEffortTaskRunner() {
RulesetPublisherImpl::BestEffortTaskRunner() {
return best_effort_task_runner_;
}
VerifiedRulesetDealer::Handle* ContentRulesetService::GetRulesetDealer() {
VerifiedRulesetDealer::Handle* RulesetPublisherImpl::GetRulesetDealer() {
return ruleset_dealer_.get();
}
void ContentRulesetService::IndexAndStoreAndPublishRulesetIfNeeded(
void RulesetPublisherImpl::IndexAndStoreAndPublishRulesetIfNeeded(
const UnindexedRulesetInfo& unindexed_ruleset_info) {
DCHECK(ruleset_service_);
ruleset_service_->IndexAndStoreAndPublishRulesetIfNeeded(
unindexed_ruleset_info);
}
void ContentRulesetService::Observe(
void RulesetPublisherImpl::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
......
......@@ -6,7 +6,6 @@ static_library("browser") {
sources = [
"copying_file_stream.cc",
"copying_file_stream.h",
"ruleset_service_delegate.h",
"subresource_filter_constants.cc",
"subresource_filter_constants.h",
"subresource_filter_features.cc",
......
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