1// Copyright 2014 The Chromium Authors. All rights reserved.
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 COMPONENTS_DOMAIN_RELIABILITY_UPLOADER_H_
6#define COMPONENTS_DOMAIN_RELIABILITY_UPLOADER_H_
7
8#include <map>
9
10#include "base/callback_forward.h"
11#include "base/memory/ref_counted.h"
12#include "components/domain_reliability/domain_reliability_export.h"
13#include "url/gurl.h"
14
15namespace net {
16class URLFetcher;
17class URLRequest;
18class URLRequestContextGetter;
19}  // namespace net
20
21namespace domain_reliability {
22
23// Uploads Domain Reliability reports to collectors.
24class DOMAIN_RELIABILITY_EXPORT DomainReliabilityUploader {
25 public:
26  typedef base::Callback<void(bool success)> UploadCallback;
27
28  DomainReliabilityUploader();
29
30  virtual ~DomainReliabilityUploader();
31
32  // Creates an uploader that uses the given |url_request_context_getter| to
33  // get a URLRequestContext to use for uploads. (See test_util.h for a mock
34  // version.)
35  static scoped_ptr<DomainReliabilityUploader> Create(const scoped_refptr<
36      net::URLRequestContextGetter>& url_request_context_getter);
37
38  // Uploads |report_json| to |upload_url| and calls |callback| when the upload
39  // has either completed or failed.
40  virtual void UploadReport(const std::string& report_json,
41                            const GURL& upload_url,
42                            const UploadCallback& callback) = 0;
43
44  virtual void set_discard_uploads(bool discard_uploads) = 0;
45
46  static bool URLRequestIsUpload(const net::URLRequest& request);
47};
48
49}  // namespace domain_reliability
50
51#endif  // COMPONENTS_DOMAIN_RELIABILITY_UPLOADER_H_
52