[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / notifications / notification_id_generator.h
blob6686b182b036555e504eda5399e6cb00d7658ebe
1 // Copyright 2015 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.
5 #ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_
6 #define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_
8 #include <stdint.h>
9 #include <string>
11 #include "content/common/content_export.h"
13 class GURL;
15 namespace content {
17 class BrowserContext;
19 // Generates deterministic notification ids for Web Notifications.
21 // The notification id must be deterministic for a given browser context, origin
22 // and tag, when the tag is non-empty, or unique for the given notification when
23 // the tag is empty. For non-persistent notifications, the uniqueness will be
24 // based on the render process id. For persistent notifications, the generated
25 // id will be globally unique for the lifetime of the notification database.
27 // Notifications coming from the same origin and having the same tag will result
28 // in the same notification id being generated. This id may then be used to
29 // update the notification in the platform notification service.
31 // The notification id will be used by the notification service for determining
32 // when to replace notifications, and as the unique identifier when a
33 // notification has to be closed programmatically.
35 // It is important to note that, for persistent notifications, the generated
36 // notification id can outlive the browser process responsible for creating it.
37 class CONTENT_EXPORT NotificationIdGenerator {
38 public:
39 NotificationIdGenerator(BrowserContext* browser_context,
40 int render_process_id);
41 ~NotificationIdGenerator();
43 // Generates an id for a persistent notification given the notification's
44 // origin, tag and persistent notification id. The persistent notification id
45 // will have been created by the persistent notification database.
46 std::string GenerateForPersistentNotification(
47 const GURL& origin,
48 const std::string& tag,
49 int64_t persistent_notification_id) const;
51 // Generates an id for a non-persistent notification given the notification's
52 // origin, tag and non-persistent notification id. The non-persistent
53 // notification id will have created by the renderer with |render_process_id|.
54 std::string GenerateForNonPersistentNotification(
55 const GURL& origin,
56 const std::string& tag,
57 int non_persistent_notification_id) const;
59 private:
60 // The NotificationMessageFilter that owns |this| will outlive the context.
61 BrowserContext* browser_context_;
63 int render_process_id_;
66 } // namespace context
68 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_