1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_PERMISSIONS_ORIGIN_KEYED_PERMISSION_ACTION_SERVICE_H_
6 #define COMPONENTS_PERMISSIONS_ORIGIN_KEYED_PERMISSION_ACTION_SERVICE_H_
10 #include "base/time/time.h"
11 #include "components/content_settings/core/common/content_settings_types.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "components/permissions/permission_util.h"
16 namespace permissions {
18 enum class PermissionAction;
19 enum class RequestType;
21 typedef std::pair<PermissionAction, base::TimeTicks> PermissionActionTime;
23 // Service that keeps track of the last permission action per content setting,
24 // keyed on origins. The data is kept in-memory only and is not persisted across
25 // browser sessions. This service is used for metrics evaluation.
26 class OriginKeyedPermissionActionService : public KeyedService {
28 OriginKeyedPermissionActionService();
29 ~OriginKeyedPermissionActionService() override;
31 OriginKeyedPermissionActionService(
32 const OriginKeyedPermissionActionService&) = delete;
33 OriginKeyedPermissionActionService& operator=(
34 const OriginKeyedPermissionActionService&) = delete;
36 absl::optional<PermissionActionTime> GetLastActionEntry(
38 ContentSettingsType type);
40 void RecordAction(const GURL& origin,
41 ContentSettingsType type,
42 PermissionAction action);
44 void RecordActionWithTimeForTesting(const GURL& origin,
45 ContentSettingsType type,
46 PermissionAction action,
47 base::TimeTicks time);
50 std::map<GURL, std::map<ContentSettingsType, PermissionActionTime>> map_;
53 } // namespace permissions
55 #endif // COMPONENTS_PERMISSIONS_ORIGIN_KEYED_PERMISSION_ACTION_SERVICE_H_