Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1553)

Unified Diff: content/browser/notifications/notification_id_generator.h

Issue 1133813002: Introduce the NotificationIdGenerator in //content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/notifications/notification_id_generator.h
diff --git a/content/browser/notifications/notification_id_generator.h b/content/browser/notifications/notification_id_generator.h
new file mode 100644
index 0000000000000000000000000000000000000000..b16e53c6ad841c5bb6bb1c27d62a66437f9c6757
--- /dev/null
+++ b/content/browser/notifications/notification_id_generator.h
@@ -0,0 +1,60 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_
+#define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_
+
+#include <stdint.h>
+#include <string>
+
+#include "content/common/content_export.h"
+
+class GURL;
+
+namespace content {
+
+class BrowserContext;
+
+// Generates deterministic notification ids for Web Notifications.
+//
+// The notification id must be deterministic for a given browser context, origin
+// and tag, when the tag is non-empty, or unique for the given notification when
+// the tag is empty. For non-persistent notifications, the uniqueness will be
+// based on the render process id. For persistent notifications, the generated
johnme 2015/05/08 15:35:25 Can render process ids ever get reused (without th
Peter Beverloo 2015/05/20 18:43:33 No. See ChildProcessHostImpl::GenerateChildProcess
+// id will be globally unique for on the lifetime of the notification database.
johnme 2015/05/08 15:35:25 s/for on/for/
Peter Beverloo 2015/05/20 18:43:33 Done.
+//
+// The notification id will be used by the notification service for determining
+// when to replace notifications, and as the unique identifier when a
+// notification has to be closed programmatically.
+//
+// It is important to note that, for persistent notifications, the generated
+// notification id can outlive the browser process responsible for creating it.
+class CONTENT_EXPORT NotificationIdGenerator {
johnme 2015/05/08 15:35:25 Since multiple distinct notifications may share a
Peter Beverloo 2015/05/20 18:43:33 The technical term for this form of ID would be a
+ public:
+ NotificationIdGenerator(BrowserContext* browser_context,
+ int render_process_id);
+ ~NotificationIdGenerator();
+
+ // Generates an id for a persistent notification given the notification's
+ // origin, tag and persistent notification id.
+ std::string GenerateForPersistentNotification(
+ const GURL& origin,
+ const std::string& tag,
+ int64_t persistent_notification_id) const;
+
+ // Generates an id for a non-persistent notification given the notification's
+ // origin, tag and non-persistent notification id.
johnme 2015/05/08 15:35:26 Where do these non_persistent_notification_ids com
Peter Beverloo 2015/05/20 18:43:34 Done.
+ std::string GenerateForNonPersistentNotification(
+ const GURL& origin,
+ const std::string& tag,
+ int non_persistent_notification_id) const;
+
+ private:
+ BrowserContext* browser_context_;
johnme 2015/05/08 15:35:25 Perhaps add a comment like "Required to outlive th
Peter Beverloo 2015/05/20 18:43:34 Done.
+ int render_process_id_;
+};
+
+} // namespace context
+
+#endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_ID_GENERATOR_H_

Powered by Google App Engine
This is Rietveld 408576698