Commit f0dd74b8 authored by Lily Chen's avatar Lily Chen Committed by Commit Bot

Pass NetworkIsolationKey to ReportingCache from ReportingHeaderParser

ReportingCache is now told what the NIK of each parsed header is.
This will eventually be passed to the ReportingHeaderParser by the
caller and will correspond to the NIK of the response sending the
header.

The NIK fields are still empty for now, except in tests.

Bug: 993805
Change-Id: I93c30932559338c6ff2173d7ecbedf3541a0d35e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2135829
Commit-Queue: Lily Chen <chlily@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756882}
parent b5faee48
...@@ -128,8 +128,8 @@ class NET_EXPORT ReportingCache { ...@@ -128,8 +128,8 @@ class NET_EXPORT ReportingCache {
// Adds a new client to the cache for |origin|, or updates the existing one // Adds a new client to the cache for |origin|, or updates the existing one
// to match the new header. All values are assumed to be valid as they have // to match the new header. All values are assumed to be valid as they have
// passed through the ReportingHeaderParser. // passed through the ReportingHeaderParser.
// TODO(chlily): Take NetworkIsolationKey.
virtual void OnParsedHeader( virtual void OnParsedHeader(
const NetworkIsolationKey& network_isolation_key,
const url::Origin& origin, const url::Origin& origin,
std::vector<ReportingEndpointGroup> parsed_header) = 0; std::vector<ReportingEndpointGroup> parsed_header) = 0;
......
...@@ -215,12 +215,11 @@ bool ReportingCacheImpl::IsReportDoomedForTesting( ...@@ -215,12 +215,11 @@ bool ReportingCacheImpl::IsReportDoomedForTesting(
} }
void ReportingCacheImpl::OnParsedHeader( void ReportingCacheImpl::OnParsedHeader(
const NetworkIsolationKey& network_isolation_key,
const url::Origin& origin, const url::Origin& origin,
std::vector<ReportingEndpointGroup> parsed_header) { std::vector<ReportingEndpointGroup> parsed_header) {
SanityCheckClients(); SanityCheckClients();
// TODO(chlily): Respect NetworkIsolationKey.
NetworkIsolationKey network_isolation_key = NetworkIsolationKey::Todo();
Client new_client(network_isolation_key, origin); Client new_client(network_isolation_key, origin);
base::Time now = clock().Now(); base::Time now = clock().Now();
new_client.last_used = now; new_client.last_used = now;
...@@ -234,11 +233,8 @@ void ReportingCacheImpl::OnParsedHeader( ...@@ -234,11 +233,8 @@ void ReportingCacheImpl::OnParsedHeader(
// Creates an endpoint group and sets its |last_used| to |now|. // Creates an endpoint group and sets its |last_used| to |now|.
CachedReportingEndpointGroup new_group(parsed_endpoint_group, now); CachedReportingEndpointGroup new_group(parsed_endpoint_group, now);
// TODO(chlily): This DCHECK passes right now because the groups have their // Consistency check: the new client should have the same NIK and origin as
// NIK set to an empty NIK by the header parser, and we also set the // all groups parsed from this header.
// client's NIK to an empty NIK above. Eventually it should pass because the
// header parser should provide the NIK it used for the groups so that the
// client can be created using the same NIK.
DCHECK_EQ(new_group.group_key.network_isolation_key, DCHECK_EQ(new_group.group_key.network_isolation_key,
new_client.network_isolation_key); new_client.network_isolation_key);
DCHECK_EQ(new_group.group_key.origin, new_client.origin); DCHECK_EQ(new_group.group_key.origin, new_client.origin);
......
...@@ -65,6 +65,7 @@ class ReportingCacheImpl : public ReportingCache { ...@@ -65,6 +65,7 @@ class ReportingCacheImpl : public ReportingCache {
bool IsReportPendingForTesting(const ReportingReport* report) const override; bool IsReportPendingForTesting(const ReportingReport* report) const override;
bool IsReportDoomedForTesting(const ReportingReport* report) const override; bool IsReportDoomedForTesting(const ReportingReport* report) const override;
void OnParsedHeader( void OnParsedHeader(
const NetworkIsolationKey& network_isolation_key,
const url::Origin& origin, const url::Origin& origin,
std::vector<ReportingEndpointGroup> parsed_header) override; std::vector<ReportingEndpointGroup> parsed_header) override;
std::set<url::Origin> GetAllOrigins() const override; std::set<url::Origin> GetAllOrigins() const override;
......
...@@ -103,6 +103,7 @@ class TestReportingCache : public ReportingCache { ...@@ -103,6 +103,7 @@ class TestReportingCache : public ReportingCache {
return false; return false;
} }
void OnParsedHeader( void OnParsedHeader(
const NetworkIsolationKey& network_isolation_key,
const url::Origin& origin, const url::Origin& origin,
std::vector<ReportingEndpointGroup> parsed_header) override { std::vector<ReportingEndpointGroup> parsed_header) override {
NOTREACHED(); NOTREACHED();
......
...@@ -241,7 +241,9 @@ void ReportingHeaderParser::RecordHeaderDiscardedForJsonTooBig() { ...@@ -241,7 +241,9 @@ void ReportingHeaderParser::RecordHeaderDiscardedForJsonTooBig() {
} }
// static // static
void ReportingHeaderParser::ParseHeader(ReportingContext* context, void ReportingHeaderParser::ParseHeader(
ReportingContext* context,
const NetworkIsolationKey& network_isolation_key,
const GURL& url, const GURL& url,
std::unique_ptr<base::Value> value) { std::unique_ptr<base::Value> value) {
DCHECK(url.SchemeIsCryptographic()); DCHECK(url.SchemeIsCryptographic());
...@@ -254,7 +256,6 @@ void ReportingHeaderParser::ParseHeader(ReportingContext* context, ...@@ -254,7 +256,6 @@ void ReportingHeaderParser::ParseHeader(ReportingContext* context,
ReportingCache* cache = context->cache(); ReportingCache* cache = context->cache();
url::Origin origin = url::Origin::Create(url); url::Origin origin = url::Origin::Create(url);
NetworkIsolationKey network_isolation_key = NetworkIsolationKey::Todo();
std::vector<ReportingEndpointGroup> parsed_header; std::vector<ReportingEndpointGroup> parsed_header;
...@@ -279,8 +280,8 @@ void ReportingHeaderParser::ParseHeader(ReportingContext* context, ...@@ -279,8 +280,8 @@ void ReportingHeaderParser::ParseHeader(ReportingContext* context,
return; return;
} }
// TODO(chlily): Pass NIK to cache. cache->OnParsedHeader(network_isolation_key, origin,
cache->OnParsedHeader(origin, std::move(parsed_header)); std::move(parsed_header));
RecordHeaderOutcome(HeaderOutcome::PARSED); RecordHeaderOutcome(HeaderOutcome::PARSED);
} }
......
...@@ -17,6 +17,7 @@ class Value; ...@@ -17,6 +17,7 @@ class Value;
namespace net { namespace net {
class NetworkIsolationKey;
class ReportingContext; class ReportingContext;
class NET_EXPORT ReportingHeaderParser { class NET_EXPORT ReportingHeaderParser {
...@@ -79,8 +80,8 @@ class NET_EXPORT ReportingHeaderParser { ...@@ -79,8 +80,8 @@ class NET_EXPORT ReportingHeaderParser {
static void RecordHeaderDiscardedForJsonInvalid(); static void RecordHeaderDiscardedForJsonInvalid();
static void RecordHeaderDiscardedForJsonTooBig(); static void RecordHeaderDiscardedForJsonTooBig();
// TODO(chlily): Pass in the NetworkIsolationKey.
static void ParseHeader(ReportingContext* context, static void ParseHeader(ReportingContext* context,
const NetworkIsolationKey& network_isolation_key,
const GURL& url, const GURL& url,
std::unique_ptr<base::Value> value); std::unique_ptr<base::Value> value);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/time/default_tick_clock.h" #include "base/time/default_tick_clock.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "net/base/network_isolation_key.h"
#include "net/reporting/reporting_cache.h" #include "net/reporting/reporting_cache.h"
#include "net/reporting/reporting_header_parser.h" #include "net/reporting/reporting_header_parser.h"
#include "net/reporting/reporting_policy.pb.h" #include "net/reporting/reporting_policy.pb.h"
...@@ -38,7 +39,8 @@ void FuzzReportingHeaderParser(const std::string& data_json, ...@@ -38,7 +39,8 @@ void FuzzReportingHeaderParser(const std::string& data_json,
// TODO: consider including proto definition for URL after moving that to // TODO: consider including proto definition for URL after moving that to
// testing/libfuzzer/proto and creating a separate converter. // testing/libfuzzer/proto and creating a separate converter.
net::ReportingHeaderParser::ParseHeader(&context, GURL("https://origin/path"), net::ReportingHeaderParser::ParseHeader(&context, net::NetworkIsolationKey(),
GURL("https://origin/path"),
std::move(data_value)); std::move(data_value));
if (context.cache()->GetEndpointCount() == 0) { if (context.cache()->GetEndpointCount() == 0) {
return; return;
......
...@@ -93,9 +93,10 @@ class ReportingServiceImpl : public ReportingService { ...@@ -93,9 +93,10 @@ class ReportingServiceImpl : public ReportingService {
} }
DVLOG(1) << "Received Reporting policy for " << url.GetOrigin(); DVLOG(1) << "Received Reporting policy for " << url.GetOrigin();
DoOrBacklogTask(base::BindOnce(&ReportingServiceImpl::DoProcessHeader, // TODO(chlily): Get the proper NetworkIsolationKey from the caller.
base::Unretained(this), url, DoOrBacklogTask(base::BindOnce(
std::move(header_value))); &ReportingServiceImpl::DoProcessHeader, base::Unretained(this),
NetworkIsolationKey::Todo(), url, std::move(header_value)));
} }
void RemoveBrowsingData(int data_type_mask, void RemoveBrowsingData(int data_type_mask,
...@@ -161,11 +162,12 @@ class ReportingServiceImpl : public ReportingService { ...@@ -161,11 +162,12 @@ class ReportingServiceImpl : public ReportingService {
0 /* attempts */); 0 /* attempts */);
} }
void DoProcessHeader(const GURL& url, void DoProcessHeader(const NetworkIsolationKey& network_isolation_key,
const GURL& url,
std::unique_ptr<base::Value> header_value) { std::unique_ptr<base::Value> header_value) {
DCHECK(initialized_); DCHECK(initialized_);
ReportingHeaderParser::ParseHeader(context_.get(), url, ReportingHeaderParser::ParseHeader(context_.get(), network_isolation_key,
std::move(header_value)); url, std::move(header_value));
} }
void DoRemoveBrowsingData( void DoRemoveBrowsingData(
......
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