Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / safe_browsing / incident_reporting / resource_request_detector.h
blob6d3b5348188685f0f5357094816b61c092e51827
1 // Copyright 2015 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_RESOURCE_REQUEST_DETECTOR_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_RESOURCE_REQUEST_DETECTOR_H_
8 #include "base/containers/hash_tables.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h"
14 namespace net {
15 class URLRequest;
18 namespace safe_browsing {
20 class ClientIncidentReport_IncidentData_ResourceRequestIncident;
22 // Observes network requests and reports suspicious activity.
23 class ResourceRequestDetector {
24 public:
25 explicit ResourceRequestDetector(
26 scoped_ptr<IncidentReceiver> incident_receiver);
27 ~ResourceRequestDetector();
29 // Analyzes the |request| and triggers an incident report on suspicious
30 // script inclusion.
31 void OnResourceRequest(const net::URLRequest* request);
33 protected:
34 // Testing hook.
35 void set_allow_null_profile_for_testing(bool allow_null_profile_for_testing);
37 private:
38 void InitializeHashSets();
40 void DetectDomainRequests(const net::URLRequest* request);
41 void DetectScriptRequests(const net::URLRequest* request);
43 void ReportIncidentOnUIThread(
44 int render_process_id,
45 int render_frame_id,
46 scoped_ptr<ClientIncidentReport_IncidentData_ResourceRequestIncident>
47 incident_data);
49 scoped_ptr<IncidentReceiver> incident_receiver_;
50 base::hash_set<std::string> script_set_;
51 base::hash_set<std::string> domain_set_;
52 bool allow_null_profile_for_testing_;
54 base::WeakPtrFactory<ResourceRequestDetector> weak_ptr_factory_;
56 DISALLOW_COPY_AND_ASSIGN(ResourceRequestDetector);
59 } // namespace safe_browsing
61 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_RESOURCE_REQUEST_DETECTOR_H_