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.
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORT_UPLOADER_IMPL_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORT_UPLOADER_IMPL_H_
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_uploader.h"
15 #include "net/url_request/url_fetcher_delegate.h"
20 class URLRequestContextGetter;
23 namespace safe_browsing {
25 class ClientIncidentReport;
27 // An uploader of incident reports. A report is issued via the UploadReport
28 // method. The upload can be cancelled by deleting the returned instance. The
29 // instance is no longer usable after the delegate is notified, and may safely
30 // be destroyed by the delegate.
31 class IncidentReportUploaderImpl : public IncidentReportUploader,
32 public net::URLFetcherDelegate {
34 // The id associated with the URLFetcher, for use by tests.
35 static const int kTestUrlFetcherId;
37 ~IncidentReportUploaderImpl() override;
39 // Uploads a report with a caller-provided URL context. |callback| will be run
40 // when the upload is complete. Returns NULL if |report| cannot be serialized
41 // for transmission, in which case the delegate is not notified.
42 static scoped_ptr<IncidentReportUploader> UploadReport(
43 const OnResultCallback& callback,
44 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
45 const ClientIncidentReport& report);
48 IncidentReportUploaderImpl(
49 const OnResultCallback& callback,
50 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
51 const std::string& post_data);
53 // Returns the URL to which incident reports are to be sent.
54 static GURL GetIncidentReportUrl();
56 // net::URLFetcherDelegate methods.
57 void OnURLFetchComplete(const net::URLFetcher* source) override;
59 // The underlying URL fetcher. The instance is alive from construction through
60 // OnURLFetchComplete.
61 scoped_ptr<net::URLFetcher> url_fetcher_;
63 // The time at which the upload was initiated.
64 base::TimeTicks time_begin_;
66 DISALLOW_COPY_AND_ASSIGN(IncidentReportUploaderImpl);
69 } // namespace safe_browsing
71 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORT_UPLOADER_IMPL_H_