diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-13 16:23:34 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-14 10:37:21 +0000 |
commit | 38a9a29f4f9436cace7f0e7abf9c586057df8a4e (patch) | |
tree | c4e8c458dc595bc0ddb435708fa2229edfd00bd4 /chromium/net/reporting | |
parent | e684a3455bcc29a6e3e66a004e352dea4e1141e7 (diff) | |
download | qtwebengine-chromium-38a9a29f4f9436cace7f0e7abf9c586057df8a4e.tar.gz |
BASELINE: Update Chromium to 73.0.3683.37
Change-Id: I08c9af2948b645f671e5d933aca1f7a90ea372f2
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/net/reporting')
-rw-r--r-- | chromium/net/reporting/reporting_cache.cc | 18 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_cache_observer.cc | 17 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_cache_observer.h | 32 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_cache_unittest.cc | 64 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_context.cc | 25 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_context.h | 13 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_delivery_agent.cc | 14 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_garbage_collector.cc | 14 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_header_parser_unittest.cc | 3 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_observer.cc | 15 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_observer.h | 28 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_service.cc | 10 | ||||
-rw-r--r-- | chromium/net/reporting/reporting_service_unittest.cc | 25 |
13 files changed, 166 insertions, 112 deletions
diff --git a/chromium/net/reporting/reporting_cache.cc b/chromium/net/reporting/reporting_cache.cc index 21776f56c53..01a7e06f558 100644 --- a/chromium/net/reporting/reporting_cache.cc +++ b/chromium/net/reporting/reporting_cache.cc @@ -97,7 +97,7 @@ class ReportingCacheImpl : public ReportingCache { RemoveReportInternal(to_evict); } - context_->NotifyCacheUpdated(); + context_->NotifyCachedReportsUpdated(); } void GetReports( @@ -195,7 +195,7 @@ class ReportingCacheImpl : public ReportingCache { reports_[report]->attempts++; } - context_->NotifyCacheUpdated(); + context_->NotifyCachedReportsUpdated(); } void IncrementEndpointDeliveries(const url::Origin& origin, @@ -227,7 +227,7 @@ class ReportingCacheImpl : public ReportingCache { } } - context_->NotifyCacheUpdated(); + context_->NotifyCachedReportsUpdated(); } void RemoveAllReports(ReportingReport::Outcome outcome) override { @@ -244,7 +244,7 @@ class ReportingCacheImpl : public ReportingCache { for (const ReportingReport* report : reports_to_remove) RemoveReportInternal(report); - context_->NotifyCacheUpdated(); + context_->NotifyCachedReportsUpdated(); } void SetClient(const url::Origin& origin, @@ -282,7 +282,7 @@ class ReportingCacheImpl : public ReportingCache { RemoveClient(to_evict); } - context_->NotifyCacheUpdated(); + context_->NotifyCachedClientsUpdated(); } void MarkClientUsed(const ReportingClient* client) override { @@ -407,7 +407,7 @@ class ReportingCacheImpl : public ReportingCache { for (const ReportingClient* client : clients_to_remove) RemoveClient(client); - context_->NotifyCacheUpdated(); + context_->NotifyCachedClientsUpdated(); } void RemoveClientForOriginAndEndpoint(const url::Origin& origin, @@ -418,7 +418,7 @@ class ReportingCacheImpl : public ReportingCache { return; RemoveClient(client); - context_->NotifyCacheUpdated(); + context_->NotifyCachedClientsUpdated(); } void RemoveClientsForEndpoint(const GURL& endpoint) override { @@ -433,7 +433,7 @@ class ReportingCacheImpl : public ReportingCache { RemoveClient(client); if (!clients_to_remove.empty()) - context_->NotifyCacheUpdated(); + context_->NotifyCachedClientsUpdated(); } void RemoveAllClients() override { @@ -441,7 +441,7 @@ class ReportingCacheImpl : public ReportingCache { wildcard_clients_.clear(); client_metadata_.clear(); - context_->NotifyCacheUpdated(); + context_->NotifyCachedClientsUpdated(); } ClientStatistics GetStatisticsForOriginAndEndpoint( diff --git a/chromium/net/reporting/reporting_cache_observer.cc b/chromium/net/reporting/reporting_cache_observer.cc new file mode 100644 index 00000000000..444fdb97f53 --- /dev/null +++ b/chromium/net/reporting/reporting_cache_observer.cc @@ -0,0 +1,17 @@ +// Copyright 2017 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 "net/reporting/reporting_cache_observer.h" + +namespace net { + +void ReportingCacheObserver::OnReportsUpdated() {} + +void ReportingCacheObserver::OnClientsUpdated() {} + +ReportingCacheObserver::ReportingCacheObserver() = default; + +ReportingCacheObserver::~ReportingCacheObserver() = default; + +} // namespace net diff --git a/chromium/net/reporting/reporting_cache_observer.h b/chromium/net/reporting/reporting_cache_observer.h new file mode 100644 index 00000000000..aec1183528f --- /dev/null +++ b/chromium/net/reporting/reporting_cache_observer.h @@ -0,0 +1,32 @@ +// Copyright 2017 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 NET_REPORTING_REPORTING_CACHE_OBSERVER_H_ +#define NET_REPORTING_REPORTING_CACHE_OBSERVER_H_ + +#include "base/macros.h" +#include "net/base/net_export.h" + +namespace net { + +class NET_EXPORT ReportingCacheObserver { + public: + // Called whenever any change is made to the reports in the ReportingCache. + virtual void OnReportsUpdated(); + + // Called whenever any change is made to the client entries in the + // ReportingCache. + virtual void OnClientsUpdated(); + + protected: + ReportingCacheObserver(); + + ~ReportingCacheObserver(); + + DISALLOW_COPY_AND_ASSIGN(ReportingCacheObserver); +}; + +} // namespace net + +#endif // NET_REPORTING_REPORTING_CACHE_OBSERVER_H_ diff --git a/chromium/net/reporting/reporting_cache_unittest.cc b/chromium/net/reporting/reporting_cache_unittest.cc index 93fd1e686f4..a6d1f6a3423 100644 --- a/chromium/net/reporting/reporting_cache_unittest.cc +++ b/chromium/net/reporting/reporting_cache_unittest.cc @@ -12,8 +12,8 @@ #include "base/test/values_test_util.h" #include "base/time/time.h" #include "base/values.h" +#include "net/reporting/reporting_cache_observer.h" #include "net/reporting/reporting_client.h" -#include "net/reporting/reporting_observer.h" #include "net/reporting/reporting_report.h" #include "net/reporting/reporting_test_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -23,16 +23,24 @@ namespace net { namespace { -class TestReportingObserver : public ReportingObserver { +class TestReportingCacheObserver : public ReportingCacheObserver { public: - TestReportingObserver() : cache_update_count_(0) {} + TestReportingCacheObserver() + : cached_reports_update_count_(0), cached_clients_update_count_(0) {} - void OnCacheUpdated() override { ++cache_update_count_; } + void OnReportsUpdated() override { ++cached_reports_update_count_; } + void OnClientsUpdated() override { ++cached_clients_update_count_; } - int cache_update_count() const { return cache_update_count_; } + int cached_reports_update_count() const { + return cached_reports_update_count_; + } + int cached_clients_update_count() const { + return cached_clients_update_count_; + } private: - int cache_update_count_; + int cached_reports_update_count_; + int cached_clients_update_count_; }; class ReportingCacheTest : public ReportingTestBase { @@ -43,12 +51,12 @@ class ReportingCacheTest : public ReportingTestBase { policy.max_client_count = 5; UsePolicy(policy); - context()->AddObserver(&observer_); + context()->AddCacheObserver(&observer_); } - ~ReportingCacheTest() override { context()->RemoveObserver(&observer_); } + ~ReportingCacheTest() override { context()->RemoveCacheObserver(&observer_); } - TestReportingObserver* observer() { return &observer_; } + TestReportingCacheObserver* observer() { return &observer_; } size_t report_count() { std::vector<const ReportingReport*> reports; @@ -134,7 +142,7 @@ class ReportingCacheTest : public ReportingTestBase { const base::TimeTicks kExpires2_ = kExpires1_ + base::TimeDelta::FromDays(7); private: - TestReportingObserver observer_; + TestReportingCacheObserver observer_; }; TEST_F(ReportingCacheTest, Reports) { @@ -144,7 +152,7 @@ TEST_F(ReportingCacheTest, Reports) { cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_, std::make_unique<base::DictionaryValue>(), 0, kNow_, 0); - EXPECT_EQ(1, observer()->cache_update_count()); + EXPECT_EQ(1, observer()->cached_reports_update_count()); cache()->GetReports(&reports); ASSERT_EQ(1u, reports.size()); @@ -161,7 +169,7 @@ TEST_F(ReportingCacheTest, Reports) { EXPECT_FALSE(cache()->IsReportDoomedForTesting(report)); cache()->IncrementReportsAttempts(reports); - EXPECT_EQ(2, observer()->cache_update_count()); + EXPECT_EQ(2, observer()->cached_reports_update_count()); cache()->GetReports(&reports); ASSERT_EQ(1u, reports.size()); @@ -170,7 +178,7 @@ TEST_F(ReportingCacheTest, Reports) { EXPECT_EQ(1, report->attempts); cache()->RemoveReports(reports, ReportingReport::Outcome::UNKNOWN); - EXPECT_EQ(3, observer()->cache_update_count()); + EXPECT_EQ(3, observer()->cached_reports_update_count()); cache()->GetReports(&reports); EXPECT_TRUE(reports.empty()); @@ -181,14 +189,14 @@ TEST_F(ReportingCacheTest, RemoveAllReports) { std::make_unique<base::DictionaryValue>(), 0, kNow_, 0); cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_, std::make_unique<base::DictionaryValue>(), 0, kNow_, 0); - EXPECT_EQ(2, observer()->cache_update_count()); + EXPECT_EQ(2, observer()->cached_reports_update_count()); std::vector<const ReportingReport*> reports; cache()->GetReports(&reports); EXPECT_EQ(2u, reports.size()); cache()->RemoveAllReports(ReportingReport::Outcome::UNKNOWN); - EXPECT_EQ(3, observer()->cache_update_count()); + EXPECT_EQ(3, observer()->cached_reports_update_count()); cache()->GetReports(&reports); EXPECT_TRUE(reports.empty()); @@ -197,7 +205,7 @@ TEST_F(ReportingCacheTest, RemoveAllReports) { TEST_F(ReportingCacheTest, RemovePendingReports) { cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_, std::make_unique<base::DictionaryValue>(), 0, kNow_, 0); - EXPECT_EQ(1, observer()->cache_update_count()); + EXPECT_EQ(1, observer()->cached_reports_update_count()); std::vector<const ReportingReport*> reports; cache()->GetReports(&reports); @@ -212,7 +220,7 @@ TEST_F(ReportingCacheTest, RemovePendingReports) { cache()->RemoveReports(reports, ReportingReport::Outcome::UNKNOWN); EXPECT_TRUE(cache()->IsReportPendingForTesting(reports[0])); EXPECT_TRUE(cache()->IsReportDoomedForTesting(reports[0])); - EXPECT_EQ(2, observer()->cache_update_count()); + EXPECT_EQ(2, observer()->cached_reports_update_count()); // After removing report, future calls to GetReports should not return it. std::vector<const ReportingReport*> visible_reports; @@ -228,7 +236,7 @@ TEST_F(ReportingCacheTest, RemovePendingReports) { TEST_F(ReportingCacheTest, RemoveAllPendingReports) { cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_, std::make_unique<base::DictionaryValue>(), 0, kNow_, 0); - EXPECT_EQ(1, observer()->cache_update_count()); + EXPECT_EQ(1, observer()->cached_reports_update_count()); std::vector<const ReportingReport*> reports; cache()->GetReports(&reports); @@ -243,7 +251,7 @@ TEST_F(ReportingCacheTest, RemoveAllPendingReports) { cache()->RemoveAllReports(ReportingReport::Outcome::UNKNOWN); EXPECT_TRUE(cache()->IsReportPendingForTesting(reports[0])); EXPECT_TRUE(cache()->IsReportDoomedForTesting(reports[0])); - EXPECT_EQ(2, observer()->cache_update_count()); + EXPECT_EQ(2, observer()->cached_reports_update_count()); // After removing report, future calls to GetReports should not return it. std::vector<const ReportingReport*> visible_reports; @@ -327,7 +335,7 @@ TEST_F(ReportingCacheTest, GetReportsAsValue) { TEST_F(ReportingCacheTest, Endpoints) { SetClient(kOrigin1_, kEndpoint1_, false, kGroup1_, kExpires1_); - EXPECT_EQ(1, observer()->cache_update_count()); + EXPECT_EQ(1, observer()->cached_clients_update_count()); const ReportingClient* client = FindClientInCache(cache(), kOrigin1_, kEndpoint1_); @@ -339,7 +347,7 @@ TEST_F(ReportingCacheTest, Endpoints) { EXPECT_EQ(kExpires1_, client->expires); SetClient(kOrigin1_, kEndpoint1_, true, kGroup2, kExpires2_); - EXPECT_EQ(2, observer()->cache_update_count()); + EXPECT_EQ(2, observer()->cached_clients_update_count()); client = FindClientInCache(cache(), kOrigin1_, kEndpoint1_); ASSERT_TRUE(client); @@ -350,7 +358,7 @@ TEST_F(ReportingCacheTest, Endpoints) { EXPECT_EQ(kExpires2_, client->expires); cache()->RemoveClients(std::vector<const ReportingClient*>{client}); - EXPECT_EQ(3, observer()->cache_update_count()); + EXPECT_EQ(3, observer()->cached_clients_update_count()); client = FindClientInCache(cache(), kOrigin1_, kEndpoint1_); EXPECT_FALSE(client); @@ -374,10 +382,10 @@ TEST_F(ReportingCacheTest, RemoveClientForOriginAndEndpoint) { SetClient(kOrigin1_, kEndpoint1_, false, kGroup1_, kExpires1_); SetClient(kOrigin1_, kEndpoint2_, false, kGroup2, kExpires1_); SetClient(kOrigin2_, kEndpoint1_, false, kGroup1_, kExpires1_); - EXPECT_EQ(3, observer()->cache_update_count()); + EXPECT_EQ(3, observer()->cached_clients_update_count()); cache()->RemoveClientForOriginAndEndpoint(kOrigin1_, kEndpoint1_); - EXPECT_EQ(4, observer()->cache_update_count()); + EXPECT_EQ(4, observer()->cached_clients_update_count()); std::vector<const ReportingClient*> clients; cache()->GetClientsForOriginAndGroup(kOrigin1_, kGroup1_, &clients); @@ -394,10 +402,10 @@ TEST_F(ReportingCacheTest, RemoveClientsForEndpoint) { SetClient(kOrigin1_, kEndpoint1_, false, kGroup1_, kExpires1_); SetClient(kOrigin1_, kEndpoint2_, false, kGroup2, kExpires1_); SetClient(kOrigin2_, kEndpoint1_, false, kGroup1_, kExpires1_); - EXPECT_EQ(3, observer()->cache_update_count()); + EXPECT_EQ(3, observer()->cached_clients_update_count()); cache()->RemoveClientsForEndpoint(kEndpoint1_); - EXPECT_EQ(4, observer()->cache_update_count()); + EXPECT_EQ(4, observer()->cached_clients_update_count()); std::vector<const ReportingClient*> clients; cache()->GetClientsForOriginAndGroup(kOrigin1_, kGroup1_, &clients); @@ -461,10 +469,10 @@ TEST_F(ReportingCacheTest, GetClientsAsValue) { TEST_F(ReportingCacheTest, RemoveAllClients) { SetClient(kOrigin1_, kEndpoint1_, false, kGroup1_, kExpires1_); SetClient(kOrigin2_, kEndpoint2_, false, kGroup1_, kExpires1_); - EXPECT_EQ(2, observer()->cache_update_count()); + EXPECT_EQ(2, observer()->cached_clients_update_count()); cache()->RemoveAllClients(); - EXPECT_EQ(3, observer()->cache_update_count()); + EXPECT_EQ(3, observer()->cached_clients_update_count()); std::vector<const ReportingClient*> clients; cache()->GetClients(&clients); diff --git a/chromium/net/reporting/reporting_context.cc b/chromium/net/reporting/reporting_context.cc index 04ee3b5d2bb..8dd28a46cc6 100644 --- a/chromium/net/reporting/reporting_context.cc +++ b/chromium/net/reporting/reporting_context.cc @@ -17,12 +17,12 @@ #include "net/base/backoff_entry.h" #include "net/base/rand_callback.h" #include "net/reporting/reporting_cache.h" +#include "net/reporting/reporting_cache_observer.h" #include "net/reporting/reporting_delegate.h" #include "net/reporting/reporting_delivery_agent.h" #include "net/reporting/reporting_endpoint_manager.h" #include "net/reporting/reporting_garbage_collector.h" #include "net/reporting/reporting_network_change_observer.h" -#include "net/reporting/reporting_observer.h" #include "net/reporting/reporting_policy.h" #include "net/reporting/reporting_uploader.h" @@ -55,19 +55,24 @@ std::unique_ptr<ReportingContext> ReportingContext::Create( ReportingContext::~ReportingContext() = default; -void ReportingContext::AddObserver(ReportingObserver* observer) { - DCHECK(!observers_.HasObserver(observer)); - observers_.AddObserver(observer); +void ReportingContext::AddCacheObserver(ReportingCacheObserver* observer) { + DCHECK(!cache_observers_.HasObserver(observer)); + cache_observers_.AddObserver(observer); } -void ReportingContext::RemoveObserver(ReportingObserver* observer) { - DCHECK(observers_.HasObserver(observer)); - observers_.RemoveObserver(observer); +void ReportingContext::RemoveCacheObserver(ReportingCacheObserver* observer) { + DCHECK(cache_observers_.HasObserver(observer)); + cache_observers_.RemoveObserver(observer); } -void ReportingContext::NotifyCacheUpdated() { - for (auto& observer : observers_) - observer.OnCacheUpdated(); +void ReportingContext::NotifyCachedReportsUpdated() { + for (auto& observer : cache_observers_) + observer.OnReportsUpdated(); +} + +void ReportingContext::NotifyCachedClientsUpdated() { + for (auto& observer : cache_observers_) + observer.OnClientsUpdated(); } ReportingContext::ReportingContext(const ReportingPolicy& policy, diff --git a/chromium/net/reporting/reporting_context.h b/chromium/net/reporting/reporting_context.h index 0c63bba09ff..2c27c751068 100644 --- a/chromium/net/reporting/reporting_context.h +++ b/chromium/net/reporting/reporting_context.h @@ -22,12 +22,12 @@ class TickClock; namespace net { class ReportingCache; +class ReportingCacheObserver; class ReportingDelegate; class ReportingDeliveryAgent; class ReportingEndpointManager; class ReportingGarbageCollector; class ReportingNetworkChangeObserver; -class ReportingObserver; class ReportingUploader; class URLRequestContext; @@ -57,10 +57,11 @@ class NET_EXPORT ReportingContext { return garbage_collector_.get(); } - void AddObserver(ReportingObserver* observer); - void RemoveObserver(ReportingObserver* observer); + void AddCacheObserver(ReportingCacheObserver* observer); + void RemoveCacheObserver(ReportingCacheObserver* observer); - void NotifyCacheUpdated(); + void NotifyCachedReportsUpdated(); + void NotifyCachedClientsUpdated(); protected: ReportingContext(const ReportingPolicy& policy, @@ -77,8 +78,8 @@ class NET_EXPORT ReportingContext { const base::TickClock* tick_clock_; std::unique_ptr<ReportingUploader> uploader_; - base::ObserverList<ReportingObserver, /* check_empty= */ true>::Unchecked - observers_; + base::ObserverList<ReportingCacheObserver, /* check_empty= */ true>::Unchecked + cache_observers_; std::unique_ptr<ReportingDelegate> delegate_; diff --git a/chromium/net/reporting/reporting_delivery_agent.cc b/chromium/net/reporting/reporting_delivery_agent.cc index a0f87af463a..c6daa0ecbd5 100644 --- a/chromium/net/reporting/reporting_delivery_agent.cc +++ b/chromium/net/reporting/reporting_delivery_agent.cc @@ -17,9 +17,9 @@ #include "base/timer/timer.h" #include "base/values.h" #include "net/reporting/reporting_cache.h" +#include "net/reporting/reporting_cache_observer.h" #include "net/reporting/reporting_delegate.h" #include "net/reporting/reporting_endpoint_manager.h" -#include "net/reporting/reporting_observer.h" #include "net/reporting/reporting_report.h" #include "net/reporting/reporting_uploader.h" #include "url/gurl.h" @@ -52,26 +52,28 @@ void SerializeReports(const std::vector<const ReportingReport*>& reports, } class ReportingDeliveryAgentImpl : public ReportingDeliveryAgent, - public ReportingObserver { + public ReportingCacheObserver { public: ReportingDeliveryAgentImpl(ReportingContext* context) : context_(context), timer_(std::make_unique<base::OneShotTimer>()), weak_factory_(this) { - context_->AddObserver(this); + context_->AddCacheObserver(this); } // ReportingDeliveryAgent implementation: - ~ReportingDeliveryAgentImpl() override { context_->RemoveObserver(this); } + ~ReportingDeliveryAgentImpl() override { + context_->RemoveCacheObserver(this); + } void SetTimerForTesting(std::unique_ptr<base::OneShotTimer> timer) override { DCHECK(!timer_->IsRunning()); timer_ = std::move(timer); } - // ReportingObserver implementation: - void OnCacheUpdated() override { + // ReportingCacheObserver implementation: + void OnReportsUpdated() override { if (CacheHasReports() && !timer_->IsRunning()) { SendReports(); StartTimer(); diff --git a/chromium/net/reporting/reporting_garbage_collector.cc b/chromium/net/reporting/reporting_garbage_collector.cc index e56cd9043ef..62f9bb5aa98 100644 --- a/chromium/net/reporting/reporting_garbage_collector.cc +++ b/chromium/net/reporting/reporting_garbage_collector.cc @@ -11,8 +11,8 @@ #include "base/time/time.h" #include "base/timer/timer.h" #include "net/reporting/reporting_cache.h" +#include "net/reporting/reporting_cache_observer.h" #include "net/reporting/reporting_context.h" -#include "net/reporting/reporting_observer.h" #include "net/reporting/reporting_policy.h" #include "net/reporting/reporting_report.h" @@ -21,17 +21,17 @@ namespace net { namespace { class ReportingGarbageCollectorImpl : public ReportingGarbageCollector, - public ReportingObserver { + public ReportingCacheObserver { public: ReportingGarbageCollectorImpl(ReportingContext* context) : context_(context), timer_(std::make_unique<base::OneShotTimer>()) { - context_->AddObserver(this); + context_->AddCacheObserver(this); } // ReportingGarbageCollector implementation: ~ReportingGarbageCollectorImpl() override { - context_->RemoveObserver(this); + context_->RemoveCacheObserver(this); } void SetTimerForTesting(std::unique_ptr<base::OneShotTimer> timer) override { @@ -39,7 +39,7 @@ class ReportingGarbageCollectorImpl : public ReportingGarbageCollector, } // ReportingObserver implementation: - void OnCacheUpdated() override { + void OnReportsUpdated() override { if (timer_->IsRunning()) return; @@ -67,12 +67,12 @@ class ReportingGarbageCollectorImpl : public ReportingGarbageCollector, } // Don't restart the timer on the garbage collector's own updates. - context_->RemoveObserver(this); + context_->RemoveCacheObserver(this); context_->cache()->RemoveReports(failed_reports, ReportingReport::Outcome::ERASED_FAILED); context_->cache()->RemoveReports(expired_reports, ReportingReport::Outcome::ERASED_EXPIRED); - context_->AddObserver(this); + context_->AddCacheObserver(this); } ReportingContext* context_; diff --git a/chromium/net/reporting/reporting_header_parser_unittest.cc b/chromium/net/reporting/reporting_header_parser_unittest.cc index 6c900e02ffe..253b5ecb103 100644 --- a/chromium/net/reporting/reporting_header_parser_unittest.cc +++ b/chromium/net/reporting/reporting_header_parser_unittest.cc @@ -8,6 +8,7 @@ #include <vector> #include "base/json/json_reader.h" +#include "base/stl_util.h" #include "base/test/simple_test_tick_clock.h" #include "base/time/time.h" #include "base/values.h" @@ -81,7 +82,7 @@ TEST_F(ReportingHeaderParserTest, Invalid) { "{\"max_age\":1, \"endpoints\": [{\"url\":\"https://b/\"}]}]", "wrapped in list"}}; - for (size_t i = 0; i < arraysize(kInvalidHeaderTestCases); ++i) { + for (size_t i = 0; i < base::size(kInvalidHeaderTestCases); ++i) { auto& test_case = kInvalidHeaderTestCases[i]; ParseHeader(kUrl_, test_case.header_value); diff --git a/chromium/net/reporting/reporting_observer.cc b/chromium/net/reporting/reporting_observer.cc deleted file mode 100644 index a37548c73c8..00000000000 --- a/chromium/net/reporting/reporting_observer.cc +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017 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 "net/reporting/reporting_observer.h" - -namespace net { - -void ReportingObserver::OnCacheUpdated() {} - -ReportingObserver::ReportingObserver() = default; - -ReportingObserver::~ReportingObserver() = default; - -} // namespace net diff --git a/chromium/net/reporting/reporting_observer.h b/chromium/net/reporting/reporting_observer.h deleted file mode 100644 index cb05389b6f3..00000000000 --- a/chromium/net/reporting/reporting_observer.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2017 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 NET_REPORTING_REPORTING_OBSERVER_H_ -#define NET_REPORTING_REPORTING_OBSERVER_H_ - -#include "base/macros.h" -#include "net/base/net_export.h" - -namespace net { - -class NET_EXPORT ReportingObserver { - public: - // Called whenever any change is made to the ReportingCache. - virtual void OnCacheUpdated(); - - protected: - ReportingObserver(); - - ~ReportingObserver(); - - DISALLOW_COPY_AND_ASSIGN(ReportingObserver); -}; - -} // namespace net - -#endif // NET_REPORTING_REPORTING_OBSERVER_H_ diff --git a/chromium/net/reporting/reporting_service.cc b/chromium/net/reporting/reporting_service.cc index 1b8ca071c07..58122f8d592 100644 --- a/chromium/net/reporting/reporting_service.cc +++ b/chromium/net/reporting/reporting_service.cc @@ -49,8 +49,14 @@ class ReportingServiceImpl : public ReportingService { if (!context_->delegate()->CanQueueReport(url::Origin::Create(url))) return; - context_->cache()->AddReport(url, user_agent, group, type, std::move(body), - depth, context_->tick_clock()->NowTicks(), 0); + // Strip username, password, and ref fragment from the URL. + GURL sanitized_url = url.GetAsReferrer(); + if (!sanitized_url.is_valid()) + return; + + context_->cache()->AddReport(sanitized_url, user_agent, group, type, + std::move(body), depth, + context_->tick_clock()->NowTicks(), 0); } void ProcessHeader(const GURL& url, diff --git a/chromium/net/reporting/reporting_service_unittest.cc b/chromium/net/reporting/reporting_service_unittest.cc index 42613edebeb..3ca87ce870c 100644 --- a/chromium/net/reporting/reporting_service_unittest.cc +++ b/chromium/net/reporting/reporting_service_unittest.cc @@ -61,6 +61,31 @@ TEST_F(ReportingServiceTest, QueueReport) { EXPECT_EQ(kType_, reports[0]->type); } +TEST_F(ReportingServiceTest, QueueReportSanitizeUrl) { + // Same as kUrl_ but with username, password, and fragment. + GURL url = GURL("https://username:password@origin/path#fragment"); + service()->QueueReport(url, kUserAgent_, kGroup_, kType_, + std::make_unique<base::DictionaryValue>(), 0); + + std::vector<const ReportingReport*> reports; + context()->cache()->GetReports(&reports); + ASSERT_EQ(1u, reports.size()); + EXPECT_EQ(kUrl_, reports[0]->url); + EXPECT_EQ(kUserAgent_, reports[0]->user_agent); + EXPECT_EQ(kGroup_, reports[0]->group); + EXPECT_EQ(kType_, reports[0]->type); +} + +TEST_F(ReportingServiceTest, DontQueueReportInvalidUrl) { + GURL url = GURL("https://"); + service()->QueueReport(url, kUserAgent_, kGroup_, kType_, + std::make_unique<base::DictionaryValue>(), 0); + + std::vector<const ReportingReport*> reports; + context()->cache()->GetReports(&reports); + ASSERT_EQ(0u, reports.size()); +} + TEST_F(ReportingServiceTest, ProcessHeader) { service()->ProcessHeader(kUrl_, "{\"endpoints\":[{\"url\":\"" + kEndpoint_.spec() + |