1 // Copyright 2016 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_REPORTING_REPORTING_UPLOADER_H_ 6 #define NET_REPORTING_REPORTING_UPLOADER_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "base/functional/callback.h" 12 #include "net/base/net_export.h" 13 14 class GURL; 15 16 namespace url { 17 class Origin; 18 } // namespace url 19 20 namespace net { 21 22 class IsolationInfo; 23 class URLRequestContext; 24 25 // Uploads already-serialized reports and converts responses to one of the 26 // specified outcomes. 27 class NET_EXPORT ReportingUploader { 28 public: 29 enum class Outcome { SUCCESS, REMOVE_ENDPOINT, FAILURE }; 30 31 using UploadCallback = base::OnceCallback<void(Outcome outcome)>; 32 33 virtual ~ReportingUploader(); 34 35 // Starts to upload the reports in |json| (properly tagged as JSON data) to 36 // |url|, and calls |callback| when complete (whether successful or not). 37 // All of the reports in |json| must describe requests to the same origin; 38 // |report_origin| must be that origin. Credentials may be sent with the 39 // upload if |eligible_for_credentials| is true. 40 virtual void StartUpload(const url::Origin& report_origin, 41 const GURL& url, 42 const IsolationInfo& isolation_info, 43 const std::string& json, 44 int max_depth, 45 bool eligible_for_credentials, 46 UploadCallback callback) = 0; 47 48 // Cancels pending uploads. 49 virtual void OnShutdown() = 0; 50 51 // Creates a real implementation of |ReportingUploader| that uploads reports 52 // using |context|. 53 static std::unique_ptr<ReportingUploader> Create( 54 const URLRequestContext* context); 55 56 virtual int GetPendingUploadCountForTesting() const = 0; 57 }; 58 59 } // namespace net 60 61 #endif // NET_REPORTING_REPORTING_UPLOADER_H_ 62