Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Unified Diff: net/reporting/reporting_service.h

Issue 2249213002: [OBSOLETE] Reporting: Initial implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Try fixing unittest compile error on Android? Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/BUILD.gn ('k') | net/reporting/reporting_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/reporting/reporting_service.h
diff --git a/net/reporting/reporting_service.h b/net/reporting/reporting_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..c1625b5ad3b8ba6bed11dce112fe0f9d9cbb8959
--- /dev/null
+++ b/net/reporting/reporting_service.h
@@ -0,0 +1,126 @@
+// Copyright 2016 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_SERVICE_H_
+#define NET_REPORTING_REPORTING_SERVICE_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 "net/base/backoff_entry.h"
+#include "net/base/net_export.h"
+#include "net/base/network_change_notifier.h"
+#include "net/reporting/reporting_uploader.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "url/gurl.h"
+
+namespace net {
+
+class NET_EXPORT ReportingService
+ : public NetworkChangeNotifier::NetworkChangeObserver {
+ public:
+ struct NET_EXPORT Policy {
+ // Constructs a default policy that is appropriate for use in a browser
+ // context.
+ Policy();
+
+ // Returns a default policy that is appropriate for use in non-browser
+ // contexts. Notably, some parameters are tweaked to prioritize reliability
+ // of report delivery in ways that would inappropriately allow correlation
+ // of user behavior across networks in a browser context.
+ static Policy GetNonBrowserDefault();
+
+ // Time to keep an unused endpoint around, or zero for no limit.
+ base::TimeDelta endpoint_lifetime;
+ // Exponential backoff policy for uploading to endpoints.
+ BackoffEntry::Policy endpoint_backoff;
+ // Maximum number of failures before discarding an endpoint (once the
+ // BackoffEntry is okay with it).
+ int max_endpoint_failures;
+ // Maximum number of endpoints to keep around.
+ size_t max_endpoint_count;
+
+ // Time to keep a queued report around.
+ base::TimeDelta report_lifetime;
+ // Maximum number of failed delivery attempts before discarding a report.
+ size_t max_report_failures;
+ // Maximum number of queued reports to keep around.
+ size_t max_report_count;
+
+ // Whether to persist the report queue across network changes or not.
+ bool persist_reports_across_network_changes;
+ };
+
+ ReportingService(const Policy& policy);
+ ~ReportingService() override;
+
+ void set_uploader(std::unique_ptr<ReportingUploader> uploader);
+ void QueueReport(std::unique_ptr<base::Value> body,
+ const GURL& url,
+ const GURL& origin,
+ const std::string& group,
+ const std::string& type);
+ void ProcessHeader(const GURL& origin, const std::string& header_value);
+ void SendReports();
+
+ // NetworkChangeNotifier::NetworkChangeObserver implementation:
+ void OnNetworkChanged(NetworkChangeNotifier::ConnectionType type) override;
+
+ void set_clock_for_testing(std::unique_ptr<base::TickClock> clock);
+ size_t GetReportCountForTesting();
+ bool HasEndpointForTesting(const GURL& endpoint_url);
+ bool HasClientForTesting(const GURL& endpoint_url, const GURL& origin_url);
+ int GetEndpointFailuresForTesting(const GURL& endpoint_url);
+ void CollectGarbageForTesting();
+
+ private:
+ // Per-origin configuration and state for an endpoint.
+ struct Client;
+
+ // An endpoint to which one or more origins (represented by clients) want to
+ // upload reports.
+ struct Endpoint;
+
+ // A report queued by another component to be delivered by Reporting.
+ class Report;
+
+ // The parsed data from a header representing a single endpoint configuration.
+ struct EndpointTuple;
+
+ struct Delivery;
+
+ using EndpointMap = std::map<GURL, std::unique_ptr<Endpoint>>;
+ // TODO: Switch to a linked list for faster removal.
+ using ReportVector = std::vector<std::unique_ptr<Report>>;
+
+ void ProcessEndpointTuple(const GURL& origin, const EndpointTuple& tuple);
+
+ void OnDeliveryAttemptComplete(const std::unique_ptr<Delivery>& delivery,
+ ReportingUploader::Outcome outcome);
+
+ void CollectGarbage();
+
+ Endpoint* FindEndpointForReport(const Report& report);
+ bool DoesEndpointMatchReport(const Endpoint& endpoint, const Report& report);
+ std::string SerializeReports(const std::vector<Report*>& reports);
+
+ Endpoint* GetEndpointByURL(const GURL& url);
+ void DequeueReport(Report* report);
+
+ Policy policy_;
+ std::unique_ptr<base::TickClock> clock_;
+ std::unique_ptr<ReportingUploader> uploader_;
+
+ ReportVector reports_;
+ EndpointMap endpoints_;
+};
+
+} // namespace net
+
+#endif // COMPONENTS_REPORTING_REPORTING_SERVICE_H_
« no previous file with comments | « net/BUILD.gn ('k') | net/reporting/reporting_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698