Fix emulator build error
[platform/framework/web/chromium-efl.git] / components / permissions / permission_actions_history.h
1 // Copyright 2020 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.
4
5 #ifndef COMPONENTS_PERMISSIONS_PERMISSION_ACTIONS_HISTORY_H_
6 #define COMPONENTS_PERMISSIONS_PERMISSION_ACTIONS_HISTORY_H_
7
8 #include "base/memory/raw_ptr.h"
9 #include "base/notreached.h"
10 #include "base/time/time.h"
11 #include "components/keyed_service/core/keyed_service.h"
12 #include "components/permissions/permission_request_enums.h"
13 #include "components/permissions/permission_uma_util.h"
14 #include "components/permissions/permission_util.h"
15 #include "components/permissions/prediction_service/prediction_request_features.h"
16 #include "components/pref_registry/pref_registry_syncable.h"
17
18 enum class PermissionAction;
19 enum class RequestType;
20 class PrefService;
21
22 namespace user_prefs {
23 class PrefRegistrySyncable;
24 }
25
26 namespace permissions {
27 // This class records and stores all actions taken on permission prompts. It
28 // also has utility functions to interact with the history.
29 class PermissionActionsHistory : public KeyedService {
30  public:
31   struct Entry {
32     PermissionAction action;
33     base::Time time;
34
35     bool operator==(const Entry that) const {
36       return std::tie(this->action, this->time) ==
37              std::tie(that.action, that.time);
38     }
39     bool operator!=(const Entry that) const { return !(*this == that); }
40   };
41
42   enum class EntryFilter {
43     WANT_ALL_PROMPTS,
44     WANT_LOUD_PROMPTS_ONLY,
45     WANT_QUIET_PROMPTS_ONLY,
46   };
47
48   explicit PermissionActionsHistory(PrefService* pref_service);
49
50   PermissionActionsHistory(const PermissionActionsHistory&) = delete;
51   PermissionActionsHistory& operator=(const PermissionActionsHistory&) = delete;
52
53   ~PermissionActionsHistory() override = default;
54
55   // Get the history of recorded actions that happened after a particular time.
56   // Optionally a permission request type can be specified which will only
57   // return actions of that type.
58   std::vector<Entry> GetHistory(const base::Time& begin,
59                                 EntryFilter entry_filter);
60   std::vector<Entry> GetHistory(const base::Time& begin,
61                                 RequestType type,
62                                 EntryFilter entry_filter);
63
64   // Record that a particular action has occurred at this time.
65   // `base::Time::Now()` is used to retrieve the current time.
66   void RecordAction(PermissionAction action,
67                     RequestType type,
68                     PermissionPromptDisposition prompt_disposition);
69
70   // Delete logs of past user interactions. To be called when clearing
71   // browsing data.
72   void ClearHistory(const base::Time& delete_begin,
73                     const base::Time& delete_end);
74
75   PrefService* GetPrefServiceForTesting();
76
77   static void FillInActionCounts(
78       PredictionRequestFeatures::ActionCounts* counts,
79       const std::vector<PermissionActionsHistory::Entry>& permission_actions);
80
81   // Registers the preferences related to blocklisting in the given PrefService.
82   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
83
84  private:
85   std::vector<Entry> GetHistoryInternal(const base::Time& begin,
86                                         const std::string& key,
87                                         EntryFilter entry_filter);
88
89   raw_ptr<PrefService> pref_service_;
90 };
91
92 }  // namespace permissions
93 #endif  // COMPONENTS_PERMISSIONS_PERMISSION_ACTIONS_HISTORY_H_