Fix emulator build error
[platform/framework/web/chromium-efl.git] / components / permissions / notifications_engagement_service.h
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.
4
5 #ifndef COMPONENTS_PERMISSIONS_NOTIFICATIONS_ENGAGEMENT_SERVICE_H_
6 #define COMPONENTS_PERMISSIONS_NOTIFICATIONS_ENGAGEMENT_SERVICE_H_
7
8 #include "base/memory/raw_ptr.h"
9 #include "base/time/time.h"
10 #include "components/content_settings/core/browser/host_content_settings_map.h"
11 #include "components/keyed_service/core/keyed_service.h"
12
13 class GURL;
14 class PrefService;
15
16 namespace content {
17 class BrowserContext;
18 }  // namespace content
19
20 namespace permissions {
21
22 // This class records and stores notification engagement per origin for the
23 // past 30 days. Engagements per origin are bucketed daily: A notification
24 // engagement or display is assigned to the midnight in local time.
25 class NotificationsEngagementService : public KeyedService {
26  public:
27   explicit NotificationsEngagementService(content::BrowserContext* context,
28                                           PrefService* pref_service);
29
30   NotificationsEngagementService(const NotificationsEngagementService&) =
31       delete;
32   NotificationsEngagementService& operator=(
33       const NotificationsEngagementService&) = delete;
34
35   ~NotificationsEngagementService() override = default;
36
37   // KeyedService implementation.
38   void Shutdown() override;
39
40   void RecordNotificationDisplayed(const GURL& url);
41   void RecordNotificationDisplayed(const GURL& url, int display_count);
42   void RecordNotificationInteraction(const GURL& url);
43
44   static std::string GetBucketLabel(base::Time time);
45   static absl::optional<base::Time> ParsePeriodBeginFromBucketLabel(
46       const std::string& label);
47
48  private:
49   void IncrementCounts(const GURL& url,
50                        const int display_count_delta,
51                        const int click_count_delta);
52
53   // Used to update the notification engagement per URL.
54   raw_ptr<HostContentSettingsMap> settings_map_;
55
56   raw_ptr<PrefService> pref_service_;
57 };
58
59 }  // namespace permissions
60
61 #endif  // COMPONENTS_PERMISSIONS_NOTIFICATIONS_ENGAGEMENT_SERVICE_H_