QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / chrome / browser / safe_browsing / ping_manager.h
blob6c8c5270eeaa9fa09685996bb474245c6df1fad7
1 // Copyright (c) 2012 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_PING_MANAGER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_
8 // A class that reports safebrowsing statistics to Google's SafeBrowsing
9 // servers.
10 #include <set>
11 #include <string>
12 #include <vector>
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "chrome/browser/safe_browsing/protocol_manager_helper.h"
17 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
18 #include "net/url_request/url_fetcher_delegate.h"
19 #include "url/gurl.h"
21 namespace chrome_browser_net {
22 class CertificateErrorReporter;
25 namespace net {
26 class SSLInfo;
27 class URLRequestContextGetter;
28 } // namespace net
31 class SafeBrowsingPingManager : public net::URLFetcherDelegate {
32 public:
33 ~SafeBrowsingPingManager() override;
35 // Create an instance of the safe browsing ping manager.
36 static SafeBrowsingPingManager* Create(
37 net::URLRequestContextGetter* request_context_getter,
38 const SafeBrowsingProtocolConfig& config);
40 // net::URLFetcherDelegate interface.
41 void OnURLFetchComplete(const net::URLFetcher* source) override;
43 // For UMA users we report to Google when a SafeBrowsing interstitial is shown
44 // to the user. |threat_type| should be one of the types known by
45 // SafeBrowsingHitUrl.
46 void ReportSafeBrowsingHit(const GURL& malicious_url,
47 const GURL& page_url,
48 const GURL& referrer_url,
49 bool is_subresource,
50 SBThreatType threat_type,
51 const std::string& post_data,
52 bool is_extended_reporting);
54 // Users can opt-in on the SafeBrowsing interstitial to send detailed
55 // malware reports. |report| is the serialized report.
56 void ReportMalwareDetails(const std::string& report);
58 // Users can opt-in on the SSL interstitial to send reports of invalid
59 // certificate chains.
60 void ReportInvalidCertificateChain(const std::string& serialized_report);
62 void SetCertificateErrorReporterForTesting(scoped_ptr<
63 chrome_browser_net::CertificateErrorReporter> certificate_error_reporter);
65 private:
66 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest,
67 TestSafeBrowsingHitUrl);
68 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest,
69 TestMalwareDetailsUrl);
71 typedef std::set<const net::URLFetcher*> Reports;
73 // Constructs a SafeBrowsingPingManager that issues network requests
74 // using |request_context_getter|.
75 SafeBrowsingPingManager(
76 net::URLRequestContextGetter* request_context_getter,
77 const SafeBrowsingProtocolConfig& config);
79 // Generates URL for reporting safe browsing hits for UMA users.
80 GURL SafeBrowsingHitUrl(const GURL& malicious_url,
81 const GURL& page_url,
82 const GURL& referrer_url,
83 bool is_subresource,
84 SBThreatType threat_type,
85 bool is_extended_reporting) const;
86 // Generates URL for reporting malware details for users who opt-in.
87 GURL MalwareDetailsUrl() const;
89 // Current product version sent in each request.
90 std::string version_;
92 // The safe browsing client name sent in each request.
93 std::string client_name_;
95 // The context we use to issue network requests.
96 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
98 // URL prefix where browser reports hits to the safebrowsing list and
99 // sends detaild malware reports for UMA users.
100 std::string url_prefix_;
102 // Track outstanding SafeBrowsing report fetchers for clean up.
103 // We add both "hit" and "detail" fetchers in this set.
104 Reports safebrowsing_reports_;
106 // Sends reports of invalid SSL certificate chains.
107 scoped_ptr<chrome_browser_net::CertificateErrorReporter>
108 certificate_error_reporter_;
110 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingPingManager);
113 #endif // CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_