1 // Copyright 2020 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 EXTENSIONS_COMMON_IDENTIFIABILITY_METRICS_H_
6 #define EXTENSIONS_COMMON_IDENTIFIABILITY_METRICS_H_
7 
8 #include <string>
9 
10 #include "extensions/common/extension_id.h"
11 #include "services/metrics/public/cpp/ukm_source_id.h"
12 #include "third_party/blink/public/common/privacy_budget/identifiable_surface.h"
13 
14 class GURL;
15 
16 namespace extensions {
17 
18 // Encodes |type| and |extension_id| as an identifiability surface.
19 blink::IdentifiableSurface SurfaceForExtension(
20     blink::IdentifiableSurface::Type type,
21     const ExtensionId& extension_id);
22 
23 // Used for histograms. Do not reorder.
24 enum class ExtensionResourceAccessResult : int {
25   kSuccess,
26   kCancel,   // Only logged on navigation when the navigation is cancelled and
27              // the document stays in place.
28   kFailure,  // resource load failed or navigation to some sort of error page.
29 };
30 
31 // Records results of attempts to access an extension resource at the url
32 // |gurl|. Done as part of a study to see if this is being used as a
33 // fingerprinting method.
34 void RecordExtensionResourceAccessResult(ukm::SourceIdObj ukm_source_id,
35                                          const GURL& gurl,
36                                          ExtensionResourceAccessResult result);
37 
38 // Records that the extension |extension_id| has injected a content script into
39 // page identified by |ukm_source_id|.
40 void RecordContentScriptInjection(ukm::SourceIdObj ukm_source_id,
41                                   const ExtensionId& extension_id);
42 
43 // Records that the extension |extension_id| has blocked a network request on
44 // page identified by |ukm_source_id|.
45 void RecordNetworkRequestBlocked(ukm::SourceIdObj ukm_source_id,
46                                  const ExtensionId& extension_id);
47 
48 }  // namespace extensions
49 
50 #endif  // EXTENSIONS_COMMON_IDENTIFIABILITY_METRICS_H_
51