Chromium Code Reviews| Index: components/reporting/core/browser/reporting_manager.h |
| diff --git a/components/reporting/core/browser/reporting_manager.h b/components/reporting/core/browser/reporting_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dea305b69e6c268e782f45209870a80c4afc1bb1 |
| --- /dev/null |
| +++ b/components/reporting/core/browser/reporting_manager.h |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
|
Randy Smith (Not in Mondays)
2016/10/21 20:15:11
Attaching a top-level comment at a random location
Julia Tuttle
2016/11/02 20:44:39
These need to happen before we turn it on: rudimen
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_REPORTING_CORE_BROWSER_REPORTING_MANAGER_H_ |
| +#define COMPONENTS_REPORTING_CORE_BROWSER_REPORTING_MANAGER_H_ |
| + |
| +#include <map> |
| +#include <unordered_set> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/time/tick_clock.h" |
| +#include "base/time/time.h" |
| +#include "base/values.h" |
| +#include "components/reporting/core/browser/reporting_cache.h" |
| +#include "components/reporting/core/browser/reporting_client.h" |
| +#include "components/reporting/core/browser/reporting_endpoint.h" |
| +#include "components/reporting/core/browser/reporting_report.h" |
| +#include "components/reporting/core/browser/reporting_uploader.h" |
| +#include "components/reporting/core/common/reporting_export.h" |
| +#include "net/base/backoff_entry.h" |
| +#include "url/gurl.h" |
| + |
| +namespace reporting { |
| + |
| +struct ReportingDelivery {}; |
| + |
| +class REPORTING_EXPORT ReportingManager { |
| + public: |
| + ReportingManager(std::unique_ptr<ReportingUploader> uploader, |
| + const base::Callback<bool(const GURL&)>& is_origin_secure); |
| + ~ReportingManager(); |
| + |
| + // Section 4.1 |
| + void QueueReport(std::unique_ptr<ReportingReport> report); |
| + |
| + // Section 3.2 |
| + void ProcessHeader(const GURL& origin, const std::string& header_value); |
| + |
| + // Section 4.3 step 4.1. |
| + void SendReports(); |
| + |
| + const ReportingCache& GetReportingCacheForTesting() const { return cache_; } |
| + |
| + private: |
| + // Section 3.3 |
| + struct EndpointTuple { |
| + GURL url; |
| + bool subdomains; |
| + base::TimeDelta ttl; |
| + std::string group; |
| + |
| + // Section 3.3, step 3.3. |
| + static bool FromDictionary(const base::DictionaryValue& dictionary, |
| + EndpointTuple* tuple_out, |
| + std::string* error_out); |
| + static std::vector<EndpointTuple> FromHeader( |
| + const std::string& header, |
| + const base::Callback<bool(const GURL&)>& is_origin_secure, |
| + std::vector<std::string>* errors_out); |
| + |
| + std::string ToString() const; |
| + }; |
| + |
| + // Context for Section 4.3 step 4, for convenience. |
| + struct Delivery { |
| + Delivery( |
| + const std::unique_ptr<ReportingEndpoint>& endpoint, |
| + const std::vector<const std::unique_ptr<ReportingReport>*>& reports); |
| + ~Delivery(); |
| + |
| + const std::unique_ptr<ReportingEndpoint>& endpoint; |
| + std::vector<const std::unique_ptr<ReportingReport>*> reports; |
| + }; |
| + |
| + // Section 3.2, step 5.1-4 |
| + void ProcessEndpoint(const GURL& origin, const EndpointTuple& tuple); |
| + |
| + // Section 4.2 |
| + bool DoesEndpointMatchReport(const ReportingEndpoint& endpoint, |
| + const ReportingReport& report); |
| + |
| + // Section 4.3 step 4.2. |
| + void OnDeliveryAttemptComplete(const std::unique_ptr<Delivery>& delivery, |
| + ReportingUploader::Outcome outcome); |
| + |
| + // Section 4.4 steps 1-2. |
| + std::string SerializeReports( |
| + const std::vector<const std::unique_ptr<ReportingReport>*>& reports); |
| + |
| + // Section 5.2 |
| + void CollectGarbage(); |
| + |
| + base::Callback<bool(const GURL&)> is_origin_secure_; |
| + std::unique_ptr<base::TickClock> clock_; |
| + net::BackoffEntry::Policy backoff_policy_; |
| + ReportingCache cache_; |
| + std::unique_ptr<ReportingUploader> uploader_; |
| +}; |
| + |
| +} // namespace reporting |
| + |
| +#endif // COMPONENTS_REPORTING_REPORTING_MANAGER_H_ |