Commit 9a5a70fc authored by cfredric's avatar cfredric Committed by Commit Bot

Parse preloaded First-Party Sets in the NetworkService.

Bug: 1129506
Change-Id: I108aa17dc23fa407c4f3b9d6b0ed6a7ef18ce7ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2416881
Commit-Queue: Chris Fredrickson <cfredric@google.com>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarJonathan Metzman <metzman@chromium.org>
Reviewed-by: default avatarDan McArdle <dmcardle@chromium.org>
Reviewed-by: default avatarSteven Bingler <bingler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810842}
parent 8c3a59a5
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "base/version.h" #include "base/version.h"
#include "components/component_updater/component_updater_paths.h" #include "components/component_updater/component_updater_paths.h"
#include "content/public/browser/network_service_instance.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_service.mojom.h"
using component_updater::ComponentUpdateService; using component_updater::ComponentUpdateService;
...@@ -153,8 +155,9 @@ void RegisterFirstPartySetsComponent(ComponentUpdateService* cus) { ...@@ -153,8 +155,9 @@ void RegisterFirstPartySetsComponent(ComponentUpdateService* cus) {
std::make_unique<FirstPartySetsComponentInstallerPolicy>( std::make_unique<FirstPartySetsComponentInstallerPolicy>(
/*on_sets_ready=*/base::BindRepeating( /*on_sets_ready=*/base::BindRepeating(
[](const std ::string& raw_sets) { [](const std ::string& raw_sets) {
// TODO(cfredric): forward to NetworkService here.
VLOG(1) << "Received Sets: \"" << raw_sets << "\""; VLOG(1) << "Received Sets: \"" << raw_sets << "\"";
content::GetNetworkService()->SetPreloadedFirstPartySets(
raw_sets);
}))); })));
installer->Register(cus, base::OnceClosure()); installer->Register(cus, base::OnceClosure());
} }
......
...@@ -235,6 +235,7 @@ component("network_service") { ...@@ -235,6 +235,7 @@ component("network_service") {
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//net", "//net",
"//net:extras", "//net:extras",
"//services/network/first_party_sets",
"//services/network/public/cpp", "//services/network/public/cpp",
"//services/network/public/cpp:crash_keys", "//services/network/public/cpp:crash_keys",
"//services/network/public/cpp/cert_verifier:cert_verifier_creation", "//services/network/public/cpp/cert_verifier:cert_verifier_creation",
...@@ -388,6 +389,8 @@ source_set("tests") { ...@@ -388,6 +389,8 @@ source_set("tests") {
"//net:simple_quic_tools", "//net:simple_quic_tools",
"//net:test_support", "//net:test_support",
"//net/http:transport_security_state_unittest_data_default", "//net/http:transport_security_state_unittest_data_default",
"//services/network/first_party_sets",
"//services/network/first_party_sets:tests",
"//services/network/public/cpp", "//services/network/public/cpp",
"//services/network/public/cpp:buildflags", "//services/network/public/cpp:buildflags",
"//services/network/public/cpp/cert_verifier:cert_verifier_creation", "//services/network/public/cpp/cert_verifier:cert_verifier_creation",
......
# Copyright 2020 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.
import("//services/network/public/cpp/features.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//third_party/protobuf/proto_library.gni")
source_set("first_party_sets") {
visibility = [
":*",
"//services/network:network_service",
"//services/network:tests",
]
defines = [ "IS_NETWORK_SERVICE_IMPL" ]
sources = [
"first_party_set_parser.cc",
"first_party_set_parser.h",
"preloaded_first_party_sets.cc",
"preloaded_first_party_sets.h",
]
deps = [
"//base",
"//base/util/values:values_util",
"//components/cbor",
"//components/sqlite_proto",
"//services/network/public/cpp",
"//services/network/public/mojom",
"//sql",
"//url",
]
}
source_set("test_support") {
testonly = true
defines = [ "IS_NETWORK_SERVICE_IMPL" ]
sources = []
deps = [
":first_party_sets",
"//base",
"//base/test:test_support",
"//components/cbor",
"//net",
"//net:test_support",
"//net/traffic_annotation:test_support",
"//services/network/public/mojom",
"//testing/gtest",
"//url",
]
}
source_set("tests") {
testonly = true
defines = [ "IS_NETWORK_SERVICE_IMPL" ]
sources = [ "first_party_set_parser_unittest.cc" ]
deps = [
":first_party_sets",
":test_support",
"//base",
"//base/test:test_support",
"//components/cbor",
"//components/sqlite_proto",
"//net",
"//net:test_support",
"//net/traffic_annotation:test_support",
"//services/network:test_support",
"//testing/gmock",
"//testing/gtest",
"//url",
]
}
fuzzer_test("first_party_set_parser_fuzzer") {
sources = [ "test/first_party_set_parser_fuzzer.cc" ]
deps = [
":first_party_sets",
"//base",
"//net:net_fuzzer_test_support",
]
dict = "test/first_party_set_parser_fuzzer.dict"
seed_corpus = "//third_party/grpc/src/test/core/json/corpus/"
}
fuzzer_test("first_party_set_parser_json_fuzzer") {
sources = [ "test/first_party_set_parser_json_fuzzer.cc" ]
deps = [
":first_party_sets",
"//base",
"//testing/libfuzzer/proto:json_proto",
"//testing/libfuzzer/proto:json_proto_converter",
"//third_party/libprotobuf-mutator",
]
}
// Copyright 2020 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.
#include "services/network/first_party_sets/first_party_set_parser.h"
#include <iterator>
#include <memory>
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/json/json_reader.h"
namespace network {
namespace {
const char kFirstPartySetOwnerField[] = "owner";
const char kFirstPartySetMembersField[] = "members";
// Parses a single First-Party Set into a map from member to owner (not
// including the owner). Note that this is intended for use *only* on sets that
// were preloaded via the component updater, so this does not check assertions
// or versions. It does not handle non-disjoint sets (i.e. sets which have
// non-empty intersections of owners and/or members)..
void ParsePreloadedSet(
const base::Value& value,
std::vector<std::pair<std::string, std::string>>& map_storage,
base::flat_set<std::string>& owners,
base::flat_set<std::string>& members) {
if (!value.is_dict())
return;
// Confirm that the set has an owner, and the owner is a string.
const std::string* maybe_owner =
value.FindStringKey(kFirstPartySetOwnerField);
if (!maybe_owner)
return;
// An owner may only be listed once, and may not be a member of another set.
if (members.contains(*maybe_owner) || owners.contains(*maybe_owner))
return;
owners.insert(*maybe_owner);
// Confirm that the members field is present, and is an array of strings.
const base::Value* maybe_members_list =
value.FindListKey(kFirstPartySetMembersField);
if (!maybe_members_list)
return;
// Add each member to our mapping (assuming the member is a string).
for (const auto& item : maybe_members_list->GetList()) {
// Members may not be a member of another set, and may not be an owner of
// another set.
if (item.is_string()) {
std::string member = item.GetString();
if (!members.contains(member) && !owners.contains(member)) {
map_storage.emplace_back(member, *maybe_owner);
members.insert(member);
}
}
}
}
} // namespace
std::unique_ptr<base::flat_map<std::string, std::string>>
FirstPartySetParser::ParsePreloadedSets(base::StringPiece raw_sets) {
base::Optional<base::Value> maybe_value = base::JSONReader::Read(
raw_sets, base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS);
if (!maybe_value.has_value())
return nullptr;
if (!maybe_value->is_list())
return nullptr;
std::vector<std::pair<std::string, std::string>> map_storage;
base::flat_set<std::string> owners;
base::flat_set<std::string> members;
for (const auto& value : maybe_value->GetList()) {
ParsePreloadedSet(value, map_storage, owners, members);
}
return std::make_unique<base::flat_map<std::string, std::string>>(
std::move(map_storage));
}
} // namespace network
// Copyright 2020 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 SERVICES_NETWORK_FIRST_PARTY_SETS_FIRST_PARTY_SET_PARSER_H_
#define SERVICES_NETWORK_FIRST_PARTY_SETS_FIRST_PARTY_SET_PARSER_H_
#include <map>
#include <memory>
#include "base/callback.h"
#include "base/containers/flat_map.h"
#include "base/values.h"
namespace network {
class FirstPartySetParser {
public:
FirstPartySetParser() = delete;
~FirstPartySetParser() = delete;
FirstPartySetParser(const FirstPartySetParser&) = delete;
FirstPartySetParser& operator=(const FirstPartySetParser&) = delete;
// Parses the value in |raw_sets|, which should be the JSON-encoded string
// representation of a list of set declarations according to the format
// specified in this document: https://github.com/privacycg/first-party-sets.
// This function does not check versions or assertions, since it is intended
// only for *preloaded* sets.
static std::unique_ptr<base::flat_map<std::string, std::string>>
ParsePreloadedSets(base::StringPiece raw_sets);
};
} // namespace network
#endif // SERVICES_NETWORK_FIRST_PARTY_SETS_FIRST_PARTY_SET_PARSER_H_
// Copyright 2020 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.
#include "services/network/first_party_sets/first_party_set_parser.h"
#include "base/json/json_reader.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::Eq;
using ::testing::Pointee;
using ::testing::UnorderedPointwise;
namespace network {
TEST(FirstPartySetParser_Preloaded, RejectsEmpty) {
// If the input isn't valid JSON, we should
// reject it. In particular, we should reject
// empty input.
EXPECT_FALSE(FirstPartySetParser::ParsePreloadedSets(""));
}
TEST(FirstPartySetParser_Preloaded, RejectsNonemptyMalformed) {
// If the input isn't valid JSON, we should
// reject it.
const char input[] = "certainly not valid JSON";
// Sanity check that the input is not valid JSON.
ASSERT_FALSE(base::JSONReader::Read(input));
EXPECT_FALSE(FirstPartySetParser::ParsePreloadedSets(input));
}
TEST(FirstPartySetParser, RejectsNonListInput) {
// The outermost value should be a list.
const std::string input = "{}";
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_FALSE(FirstPartySetParser::ParsePreloadedSets(input));
}
TEST(FirstPartySetParser, AcceptsTrivial) {
const std::string input = "[]";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(
Eq(), base::flat_map<std::string, std::string>({}))));
}
TEST(FirstPartySetParser, AcceptsMinimal) {
const std::string input =
R"( [ { "owner": "example.com", "members": ["aaaa"] } ] )";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(
FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(Eq(), base::flat_map<std::string, std::string>(
{{"aaaa", "example.com"}}))));
}
TEST(FirstPartySetParser, RejectsMissingOwner) {
const std::string input = R"( [ { "members": ["aaaa"] } ] )";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(
Eq(), base::flat_map<std::string, std::string>({}))));
}
TEST(FirstPartySetParser, RejectsTypeUnsafeOwner) {
const std::string input = R"( [ { "owner": 3, "members": ["aaaa"] } ] )";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(
Eq(), base::flat_map<std::string, std::string>({}))));
}
TEST(FirstPartySetParser, RejectsMissingMembers) {
const std::string input = R"( [ { "owner": "example.com" } ] )";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(
Eq(), base::flat_map<std::string, std::string>({}))));
}
TEST(FirstPartySetParser, RejectsTypeUnsafeMembers) {
const std::string input =
R"( [ { "owner": "example.com", "members": ["aaaa", 4] } ] )";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(
FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(Eq(), base::flat_map<std::string, std::string>(
{{"aaaa", "example.com"}}))));
}
TEST(FirstPartySetParser, AcceptsMultipleSets) {
const std::string input = R"(
[
{
"owner": "example.com",
"members": ["member1"]
},
{
"owner": "foo.com",
"members": ["member2"]
}
]
)";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(
Eq(), base::flat_map<std::string, std::string>({
{"member1", "example.com"},
{"member2", "foo.com"},
}))));
}
TEST(FirstPartySetParser, AllowsTrailingCommas) {
const std::string input = R"(
[
{
"owner": "example.com",
"members": ["member1"],
},
]
)";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(
input, base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS));
EXPECT_THAT(FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(
Eq(), base::flat_map<std::string, std::string>({
{"member1", "example.com"},
}))));
}
TEST(FirstPartySetParser, IgnoresSubsequent_SameOwner) {
const std::string input = R"(
[
{
"owner": "example.com",
"members": ["member1"]
},
{
"owner": "example.com",
"members": ["member2"]
}
]
)";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(
Eq(), base::flat_map<std::string, std::string>({
{"member1", "example.com"},
}))));
}
TEST(FirstPartySetParser, IgnoresSubsequent_MemberAsOwner) {
const std::string input = R"(
[
{
"owner": "example.com",
"members": ["member1"]
},
{
"owner": "member1",
"members": ["member2"]
}
]
)";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(
Eq(), base::flat_map<std::string, std::string>({
{"member1", "example.com"},
}))));
}
TEST(FirstPartySetParser, IgnoresSubsequent_SameMember) {
const std::string input = R"(
[
{
"owner": "example.com",
"members": ["member1"]
},
{
"owner": "foo.com",
"members": ["member1", "member2"]
}
]
)";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(
Eq(), base::flat_map<std::string, std::string>({
{"member1", "example.com"},
{"member2", "foo.com"},
}))));
}
TEST(FirstPartySetParser, IgnoresSubsequent_OwnerAsMember) {
const std::string input = R"(
[
{
"owner": "example.com",
"members": ["member1"]
},
{
"owner": "example2.com",
"members": ["example.com", "member2"]
}
]
)";
// Sanity check that the input is actually valid JSON.
ASSERT_TRUE(base::JSONReader::Read(input));
EXPECT_THAT(FirstPartySetParser::ParsePreloadedSets(input),
Pointee(UnorderedPointwise(
Eq(), base::flat_map<std::string, std::string>({
{"member1", "example.com"},
{"member2", "example2.com"},
}))));
}
} // namespace network
// Copyright 2020 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.
#include "services/network/first_party_sets/preloaded_first_party_sets.h"
#include <memory>
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/values.h"
#include "services/network/first_party_sets/first_party_set_parser.h"
#include "services/network/public/cpp/network_switches.h"
namespace network {
PreloadedFirstPartySets::PreloadedFirstPartySets() = default;
PreloadedFirstPartySets::~PreloadedFirstPartySets() = default;
void PreloadedFirstPartySets::ParseAndSet(base::StringPiece raw_sets) {
std::unique_ptr<base::flat_map<std::string, std::string>> parsed =
FirstPartySetParser::ParsePreloadedSets(raw_sets);
if (parsed)
sets_.swap(*parsed);
}
} // namespace network
// Copyright 2020 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 SERVICES_NETWORK_FIRST_PARTY_SETS_PRELOADED_FIRST_PARTY_SETS_H_
#define SERVICES_NETWORK_FIRST_PARTY_SETS_PRELOADED_FIRST_PARTY_SETS_H_
#include <map>
#include <memory>
#include "base/callback.h"
#include "base/containers/flat_map.h"
namespace network {
// Class PreloadedFirstPartySets is a pseudo-singleton owned by NetworkService;
// it stores all known information about preloaded First-Party Sets state. This
// information is updated by the component updater via |ParseAndSet|.
class PreloadedFirstPartySets {
public:
PreloadedFirstPartySets();
~PreloadedFirstPartySets();
PreloadedFirstPartySets(const PreloadedFirstPartySets&) = delete;
PreloadedFirstPartySets& operator=(const PreloadedFirstPartySets&) = delete;
// Overwrites the current owners-to-sets map with the values in |raw_sets|,
// which should be the JSON-encoded string representation of a collection of
// set declarations according to the format specified in this document:
// https://github.com/privacycg/first-party-sets
void ParseAndSet(base::StringPiece raw_sets);
private:
base::flat_map<std::string, std::string> sets_;
};
} // namespace network
#endif // SERVICES_NETWORK_FIRST_PARTY_SETS_PRELOADED_FIRST_PARTY_SETS_H_
// Copyright 2020 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.
#include "services/network/first_party_sets/first_party_set_parser.h"
#include <cstdint>
#include <memory>
namespace network {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
base::StringPiece string_input(reinterpret_cast<const char*>(data), size);
FirstPartySetParser::ParsePreloadedSets(string_input);
return 0;
}
} // namespace network
# Copyright 2020 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.
"{"
"}"
"["
"]"
"\""
"'"
"\\"
"//"
":"
","
" "
"\\n"
"\\r"
"/*"
"*/"
"true"
"false"
"null"
"\\u"
"\\b"
"\\f"
"\\t"
"."
"e"
"e+"
"e-"
"E"
"E+"
"E-"
"owner"
"members"
// Copyright 2020 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.
#include "services/network/first_party_sets/first_party_set_parser.h"
#include <stdlib.h>
#include <iostream>
#include "testing/libfuzzer/proto/json.pb.h"
#include "testing/libfuzzer/proto/json_proto_converter.h"
#include "testing/libfuzzer/proto/lpm_interface.h"
DEFINE_PROTO_FUZZER(const json_proto::JsonValue& json_value) {
json_proto::JsonProtoConverter converter;
std::string native_input = converter.Convert(json_value);
if (getenv("LPM_DUMP_NATIVE_INPUT"))
std::cout << native_input << std::endl;
network::FirstPartySetParser::ParsePreloadedSets(native_input);
}
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "services/network/crl_set_distributor.h" #include "services/network/crl_set_distributor.h"
#include "services/network/cross_origin_read_blocking_exception_for_plugin.h" #include "services/network/cross_origin_read_blocking_exception_for_plugin.h"
#include "services/network/dns_config_change_manager.h" #include "services/network/dns_config_change_manager.h"
#include "services/network/first_party_sets/preloaded_first_party_sets.h"
#include "services/network/http_auth_cache_copier.h" #include "services/network/http_auth_cache_copier.h"
#include "services/network/legacy_tls_config_distributor.h" #include "services/network/legacy_tls_config_distributor.h"
#include "services/network/net_log_exporter.h" #include "services/network/net_log_exporter.h"
...@@ -372,6 +373,8 @@ void NetworkService::Initialize(mojom::NetworkServiceParamsPtr params, ...@@ -372,6 +373,8 @@ void NetworkService::Initialize(mojom::NetworkServiceParamsPtr params,
trust_token_key_commitments_ = std::make_unique<TrustTokenKeyCommitments>(); trust_token_key_commitments_ = std::make_unique<TrustTokenKeyCommitments>();
preloaded_first_party_sets_ = std::make_unique<PreloadedFirstPartySets>();
#if BUILDFLAG(IS_CT_SUPPORTED) #if BUILDFLAG(IS_CT_SUPPORTED)
constexpr size_t kMaxSCTAuditingCacheEntries = 1024; constexpr size_t kMaxSCTAuditingCacheEntries = 1024;
sct_auditing_cache_ = sct_auditing_cache_ =
...@@ -795,6 +798,10 @@ void NetworkService::BindTestInterface( ...@@ -795,6 +798,10 @@ void NetworkService::BindTestInterface(
} }
} }
void NetworkService::SetPreloadedFirstPartySets(const std::string& raw_sets) {
preloaded_first_party_sets_->ParseAndSet(raw_sets);
}
std::unique_ptr<net::HttpAuthHandlerFactory> std::unique_ptr<net::HttpAuthHandlerFactory>
NetworkService::CreateHttpAuthHandlerFactory(NetworkContext* network_context) { NetworkService::CreateHttpAuthHandlerFactory(NetworkContext* network_context) {
if (!http_auth_static_network_service_params_) { if (!http_auth_static_network_service_params_) {
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "net/log/net_log.h" #include "net/log/net_log.h"
#include "net/log/trace_net_log_observer.h" #include "net/log/trace_net_log_observer.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/first_party_sets/preloaded_first_party_sets.h"
#include "services/network/keepalive_statistics_recorder.h" #include "services/network/keepalive_statistics_recorder.h"
#include "services/network/network_change_manager.h" #include "services/network/network_change_manager.h"
#include "services/network/network_quality_estimator_manager.h" #include "services/network/network_quality_estimator_manager.h"
...@@ -231,6 +232,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkService ...@@ -231,6 +232,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkService
#endif #endif
void BindTestInterface( void BindTestInterface(
mojo::PendingReceiver<mojom::NetworkServiceTest> receiver) override; mojo::PendingReceiver<mojom::NetworkServiceTest> receiver) override;
void SetPreloadedFirstPartySets(const std::string& raw_sets) override;
// Returns an HttpAuthHandlerFactory for the given NetworkContext. // Returns an HttpAuthHandlerFactory for the given NetworkContext.
std::unique_ptr<net::HttpAuthHandlerFactory> CreateHttpAuthHandlerFactory( std::unique_ptr<net::HttpAuthHandlerFactory> CreateHttpAuthHandlerFactory(
...@@ -370,6 +372,10 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkService ...@@ -370,6 +372,10 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkService
mojom::HttpAuthDynamicParamsPtr http_auth_dynamic_network_service_params_; mojom::HttpAuthDynamicParamsPtr http_auth_dynamic_network_service_params_;
mojom::HttpAuthStaticParamsPtr http_auth_static_network_service_params_; mojom::HttpAuthStaticParamsPtr http_auth_static_network_service_params_;
// Globally-scoped state for First-Party Sets that were preloaded (and
// updated) via the component updater.
std::unique_ptr<PreloadedFirstPartySets> preloaded_first_party_sets_;
// NetworkContexts created by CreateNetworkContext(). They call into the // NetworkContexts created by CreateNetworkContext(). They call into the
// NetworkService when their connection is closed so that it can delete // NetworkService when their connection is closed so that it can delete
// them. It will also delete them when the NetworkService itself is torn // them. It will also delete them when the NetworkService itself is torn
......
...@@ -414,4 +414,15 @@ interface NetworkService { ...@@ -414,4 +414,15 @@ interface NetworkService {
// Binds the test service's testing interface. Available only in some test // Binds the test service's testing interface. Available only in some test
// environments. // environments.
BindTestInterface(pending_receiver<NetworkServiceTest> receiver); BindTestInterface(pending_receiver<NetworkServiceTest> receiver);
// Sets the preloaded First-Party Sets data. |raw_sets| is the JSON-encoded
// string representation of a collection of set declarations according to the
// format specified in this document:
// https://github.com/privacycg/first-party-sets
// Note that by setting the preloaded First-Party Sets, any previous notion of
// preloaded First-Party Sets is cleared. This method can be partially
// successful in the event of malformed input (which also clears previously-
// known First-Party Sets), but does nothing if given non-JSON input or JSON
// which is not a dictionary.
SetPreloadedFirstPartySets(string raw_sets);
}; };
...@@ -69,6 +69,11 @@ void JsonProtoConverter::AppendValue(const JsonValue& json_value) { ...@@ -69,6 +69,11 @@ void JsonProtoConverter::AppendValue(const JsonValue& json_value) {
} }
} }
std::string JsonProtoConverter::Convert(const JsonValue& json_value) {
AppendValue(json_value);
return data_.str();
}
std::string JsonProtoConverter::Convert(const JsonObject& json_object) { std::string JsonProtoConverter::Convert(const JsonObject& json_object) {
AppendObject(json_object); AppendObject(json_object);
return data_.str(); return data_.str();
......
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