Add domain request detection to incident reporting service.
[chromium-blink-merge.git] / chrome / browser / safe_browsing / incident_reporting / incident.h
blob2fa84c9cfb8bf8fef20a249baaae7c2b50c50518
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_INCIDENT_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_H_
8 #include <stdint.h>
9 #include <string>
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
14 namespace safe_browsing {
16 class ClientIncidentReport_IncidentData;
18 // An incident's type. Values from this enum are used for histograms (hence the
19 // making underlying type the same as histogram samples.). Do not re-use
20 // existing values.
21 enum class IncidentType : int32_t {
22 // Start with 1 rather than zero; otherwise there won't be enough buckets for
23 // the histogram.
24 TRACKED_PREFERENCE = 1,
25 BINARY_INTEGRITY = 2,
26 BLACKLIST_LOAD = 3,
27 OMNIBOX_INTERACTION = 4,
28 VARIATIONS_SEED_SIGNATURE = 5,
29 RESOURCE_REQUEST = 6,
30 // Values for new incident types go here.
31 NUM_TYPES = 7
34 // An abstract incident. Subclasses provide type-specific functionality to
35 // enable logging and pruning by the incident reporting service.
36 class Incident {
37 public:
38 virtual ~Incident();
40 // Returns the type of the incident.
41 virtual IncidentType GetType() const = 0;
43 // Returns a key that identifies a particular instance among the type's
44 // possibilities.
45 virtual std::string GetKey() const = 0;
47 // Returns a computed fingerprint of the payload. Incidents of the same
48 // incident must result in the same digest.
49 virtual uint32_t ComputeDigest() const = 0;
51 // Returns the incident's payload.
52 virtual scoped_ptr<ClientIncidentReport_IncidentData> TakePayload();
54 protected:
55 // Constructs the payload with an empty protobuf, setting its incident time to
56 // the current time.
57 Incident();
59 // Accessors for the payload. These must not be called after the payload has
60 // been taken.
61 ClientIncidentReport_IncidentData* payload();
62 const ClientIncidentReport_IncidentData* payload() const;
64 private:
65 scoped_ptr<ClientIncidentReport_IncidentData> payload_;
67 DISALLOW_COPY_AND_ASSIGN(Incident);
70 } // namespace safe_browsing
72 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_H_