OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_ | 5 #ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_ |
6 #define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_ | 6 #define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 | 13 |
14 class GURL; | 14 class GURL; |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 class BrowserContext; | 18 class BrowserContext; |
19 | 19 |
20 // Generates deterministic notification ids for Web Notifications. | 20 // Generates deterministic notification ids for Web Notifications. |
Miguel Garcia
2016/09/02 14:33:16
Is this still only for web notifications?
Peter Beverloo
2016/09/05 15:11:01
Yes. Web Notifications is the combination of persi
| |
21 // | 21 // |
22 // The notification id must be deterministic for a given browser context, origin | 22 // The notification id must be deterministic for a given browser context, origin |
23 // and tag, when the tag is non-empty, or unique for the given notification when | 23 // and tag, when the tag is non-empty, or unique for the given notification when |
24 // the tag is empty. For non-persistent notifications, the uniqueness will be | 24 // the tag is empty. For non-persistent notifications, the uniqueness will be |
25 // based on the render process id. For persistent notifications, the generated | 25 // based on the render process id. For persistent notifications, the generated |
26 // id will be globally unique for the lifetime of the notification database. | 26 // id will be globally unique for the lifetime of the notification database. |
27 // | 27 // |
28 // Notifications coming from the same origin and having the same tag will result | 28 // Notifications coming from the same origin and having the same tag will result |
29 // in the same notification id being generated. This id may then be used to | 29 // in the same notification id being generated. This id may then be used to |
30 // update the notification in the platform notification service. | 30 // update the notification in the platform notification service. |
31 // | 31 // |
32 // The notification id will be used by the notification service for determining | 32 // The notification id will be used by the notification service for determining |
33 // when to replace notifications, and as the unique identifier when a | 33 // when to replace notifications, and as the unique identifier when a |
34 // notification has to be closed programmatically. | 34 // notification has to be closed programmatically. |
35 // | 35 // |
36 // It is important to note that, for persistent notifications, the generated | 36 // It is important to note that, for persistent notifications, the generated |
37 // notification id can outlive the browser process responsible for creating it. | 37 // notification id can outlive the browser process responsible for creating it. |
38 class CONTENT_EXPORT NotificationIdGenerator { | 38 class CONTENT_EXPORT NotificationIdGenerator { |
39 public: | 39 public: |
40 NotificationIdGenerator(BrowserContext* browser_context, | 40 explicit NotificationIdGenerator(BrowserContext* browser_context); |
41 int render_process_id); | |
42 ~NotificationIdGenerator(); | 41 ~NotificationIdGenerator(); |
43 | 42 |
44 // Returns whether |notification_id| belongs to a persistent notification. | 43 // Returns whether |notification_id| belongs to a persistent notification. |
45 static bool IsPersistentNotification( | 44 static bool IsPersistentNotification( |
46 const base::StringPiece& notification_id); | 45 const base::StringPiece& notification_id); |
47 | 46 |
48 // Returns whether |notification_id| belongs to a non-persistent notification. | 47 // Returns whether |notification_id| belongs to a non-persistent notification. |
49 static bool IsNonPersistentNotification( | 48 static bool IsNonPersistentNotification( |
50 const base::StringPiece& notification_id); | 49 const base::StringPiece& notification_id); |
51 | 50 |
52 // Generates an id for a persistent notification given the notification's | 51 // Generates an id for a persistent notification given the notification's |
53 // origin, tag and persistent notification id. The persistent notification id | 52 // origin, tag and persistent notification id. The persistent notification id |
54 // will have been created by the persistent notification database. | 53 // will have been created by the persistent notification database. |
55 std::string GenerateForPersistentNotification( | 54 std::string GenerateForPersistentNotification( |
56 const GURL& origin, | 55 const GURL& origin, |
57 const std::string& tag, | 56 const std::string& tag, |
58 int64_t persistent_notification_id) const; | 57 int64_t persistent_notification_id) const; |
59 | 58 |
60 // Generates an id for a non-persistent notification given the notification's | 59 // Generates an id for a non-persistent notification given the notification's |
61 // origin, tag and non-persistent notification id. The non-persistent | 60 // origin, tag and non-persistent notification id. The non-persistent |
62 // notification id will have created by the renderer with |render_process_id|. | 61 // notification id will have created by the renderer with |render_process_id|. |
johnme
2016/09/02 15:07:44
Nit: have been
Peter Beverloo
2016/09/05 15:11:01
Done.
| |
63 std::string GenerateForNonPersistentNotification( | 62 std::string GenerateForNonPersistentNotification( |
64 const GURL& origin, | 63 const GURL& origin, |
65 const std::string& tag, | 64 const std::string& tag, |
66 int non_persistent_notification_id) const; | 65 int non_persistent_notification_id, |
66 int render_process_id) const; | |
67 | 67 |
68 private: | 68 private: |
69 // The NotificationMessageFilter that owns |this| will outlive the context. | 69 // The NotificationMessageFilter that owns |this| will outlive the context. |
70 BrowserContext* browser_context_; | 70 BrowserContext* browser_context_; |
71 | |
72 int render_process_id_; | |
73 }; | 71 }; |
74 | 72 |
75 } // namespace context | 73 } // namespace context |
76 | 74 |
77 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_ | 75 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_ |
OLD | NEW |