1 // Copyright 2019 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 THIRD_PARTY_BLINK_PUBLIC_COMMON_SCHEDULER_WEB_SCHEDULER_TRACKED_FEATURE_H_
6 #define THIRD_PARTY_BLINK_PUBLIC_COMMON_SCHEDULER_WEB_SCHEDULER_TRACKED_FEATURE_H_
7 
8 #include <stdint.h>
9 
10 #include "third_party/blink/public/common/common_export.h"
11 
12 namespace blink {
13 namespace scheduler {
14 
15 // A list of features which influence scheduling behaviour (throttling /
16 // freezing / back-forward cache) and which might be sent to the browser process
17 // for metrics-related purposes.
18 //
19 // Please keep in sync with WebSchedulerTrackedFeature in
20 // tools/metrics/histograms/enums.xml. These values should not be renumbered.
21 enum class WebSchedulerTrackedFeature {
22   kWebSocket = 0,
23   kWebRTC = 1,
24 
25   // TODO(rakina): Move tracking of cache-control usage from
26   // WebSchedulerTrackedFeature to RenderFrameHost.
27   kMainResourceHasCacheControlNoCache = 2,
28   kMainResourceHasCacheControlNoStore = 3,
29   kSubresourceHasCacheControlNoCache = 4,
30   kSubresourceHasCacheControlNoStore = 5,
31 
32   kPageShowEventListener = 6,
33   kPageHideEventListener = 7,
34   kBeforeUnloadEventListener = 8,
35   kUnloadEventListener = 9,
36   kFreezeEventListener = 10,
37   kResumeEventListener = 11,
38 
39   kContainsPlugins = 12,
40   kDocumentLoaded = 13,
41   kDedicatedWorkerOrWorklet = 14,
42 
43   // There are some other values defined for specific request context types
44   // (e.g., XHR). This value corresponds to a network requests not covered by
45   // specific context types down below.
46   kOutstandingNetworkRequestOthers = 15,
47 
48   // kServiceWorkerControlledPage = 16. Removed after implementing ServiceWorker
49   // support.
50 
51   kOutstandingIndexedDBTransaction = 17,
52 
53   // Whether the page tried to request a permission regardless of the outcome.
54   // TODO(altimin): Track this more accurately depending on the data.
55   // See permission.mojom for more details.
56   kRequestedGeolocationPermission = 19,
57   kRequestedNotificationsPermission = 20,
58   kRequestedMIDIPermission = 21,
59   kRequestedAudioCapturePermission = 22,
60   kRequestedVideoCapturePermission = 23,
61   kRequestedBackForwardCacheBlockedSensors = 24,
62   // This covers all background-related permissions, including background sync,
63   // background fetch and others.
64   kRequestedBackgroundWorkPermission = 26,
65 
66   kBroadcastChannel = 27,
67 
68   kIndexedDBConnection = 28,
69 
70   // kWebGL = 29. Removed after implementing WebGL support.
71   kWebVR = 30,
72   kWebXR = 31,
73 
74   kSharedWorker = 32,
75 
76   kWebLocks = 33,
77   kWebHID = 34,
78   kWakeLock = 35,
79   kWebShare = 36,
80 
81   kRequestedStorageAccessGrant = 37,
82   kWebNfc = 38,
83   kWebFileSystem = 39,
84 
85   kOutstandingNetworkRequestFetch = 40,
86   kOutstandingNetworkRequestXHR = 41,
87 
88   kAppBanner = 42,
89   kPrinting = 43,
90   kWebDatabase = 44,
91   kPictureInPicture = 45,
92   kPortal = 46,
93   kSpeechRecognizer = 47,
94   kIdleManager = 48,
95   kPaymentManager = 49,
96   kSpeechSynthesis = 50,
97   kKeyboardLock = 51,
98   kWebOTPService = 52,
99   kOutstandingNetworkRequestDirectSocket = 53,
100 
101   // NB: This enum is used in a bitmask, so kMaxValue must be less than 64.
102   kMaxValue = kOutstandingNetworkRequestDirectSocket
103 };
104 
105 static_assert(static_cast<uint32_t>(WebSchedulerTrackedFeature::kMaxValue) < 64,
106               "This enum is used in a bitmask, so the values should fit into a"
107               "64-bit integer");
108 
109 BLINK_COMMON_EXPORT const char* FeatureToString(
110     WebSchedulerTrackedFeature feature);
111 
112 // Converts a WebSchedulerTrackedFeature to a bit for use in a bitmask.
FeatureToBit(WebSchedulerTrackedFeature feature)113 BLINK_COMMON_EXPORT constexpr uint64_t FeatureToBit(
114     WebSchedulerTrackedFeature feature) {
115   return 1ull << static_cast<uint32_t>(feature);
116 }
117 
118 // Sticky features can't be unregistered and remain active for the rest of the
119 // lifetime of the page.
120 BLINK_COMMON_EXPORT bool IsFeatureSticky(WebSchedulerTrackedFeature feature);
121 
122 // All the sticky features in bitmask form.
123 BLINK_COMMON_EXPORT uint64_t StickyFeaturesBitmask();
124 
125 }  // namespace scheduler
126 }  // namespace blink
127 
128 #endif  // THIRD_PARTY_BLINK_PUBLIC_COMMON_SCHEDULER_WEB_SCHEDULER_TRACKED_FEATURE_H_
129