Commit d9c512d4 authored by Peter Beverloo's avatar Peter Beverloo Committed by Commit Bot

Remove profile knowledge from the NotificationIdGenerator

It's the responsibility of the NotificationDisplayService to distinguish
between multiple profiles, so we're effectively including profile data
with notifications twice. Let's remove the less important instance.

Bug: 748436
Change-Id: Ie88c91fa115573589e2dafd61f5e028ea27cd03d
Reviewed-on: https://chromium-review.googlesource.com/796796
Commit-Queue: Peter Beverloo <peter@chromium.org>
Reviewed-by: default avatarAnita Woodruff <awdf@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520577}
parent c000b6b5
......@@ -6,14 +6,9 @@
#include <sstream>
#include "base/base64.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/sha1.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "url/gurl.h"
namespace content {
......@@ -24,29 +19,8 @@ const char kNonPersistentNotificationPrefix[] = "n:";
const char kSeparator = '#';
// Computes a hash based on the path in which the |browser_context| is stored.
// Since we only store the hash, SHA-1 is used to make the probability of
// collisions negligible.
std::string ComputeBrowserContextHash(BrowserContext* browser_context) {
const base::FilePath path = browser_context->GetPath();
#if defined(OS_WIN)
std::string path_hash = base::SHA1HashString(base::WideToUTF8(path.value()));
#else
std::string path_hash = base::SHA1HashString(path.value());
#endif
return base::HexEncode(path_hash.c_str(), path_hash.length());
}
} // namespace
NotificationIdGenerator::NotificationIdGenerator(
BrowserContext* browser_context)
: browser_context_(browser_context) {}
NotificationIdGenerator::~NotificationIdGenerator() {}
// static
bool NotificationIdGenerator::IsPersistentNotification(
const base::StringPiece& notification_id) {
......@@ -69,8 +43,6 @@ std::string NotificationIdGenerator::GenerateForPersistentNotification(
std::stringstream stream;
stream << kPersistentNotificationPrefix;
stream << ComputeBrowserContextHash(browser_context_);
stream << base::IntToString(browser_context_->IsOffTheRecord());
stream << origin;
stream << base::IntToString(!tag.empty());
......@@ -93,8 +65,6 @@ std::string NotificationIdGenerator::GenerateForNonPersistentNotification(
std::stringstream stream;
stream << kNonPersistentNotificationPrefix;
stream << ComputeBrowserContextHash(browser_context_);
stream << base::IntToString(browser_context_->IsOffTheRecord());
stream << origin;
stream << base::IntToString(!tag.empty());
......
......@@ -8,6 +8,7 @@
#include <stdint.h>
#include <string>
#include "base/macros.h"
#include "base/strings/string_piece.h"
#include "content/common/content_export.h"
......@@ -15,15 +16,13 @@ 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
// id will be globally unique for the lifetime of the notification database.
// The notification id must be deterministic for a given 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 id will be
// globally unique for the lifetime of the notification database.
//
// Notifications coming from the same origin and having the same tag will result
// in the same notification id being generated. This id may then be used to
......@@ -35,10 +34,12 @@ class BrowserContext;
//
// It is important to note that, for persistent notifications, the generated
// notification id can outlive the browser process responsible for creating it.
//
// Note that the PlatformNotificationService is expected to handle
// distinguishing identical generated ids from different browser contexts.
class CONTENT_EXPORT NotificationIdGenerator {
public:
explicit NotificationIdGenerator(BrowserContext* browser_context);
~NotificationIdGenerator();
NotificationIdGenerator() = default;
// Returns whether |notification_id| belongs to a persistent notification.
static bool IsPersistentNotification(
......@@ -66,8 +67,7 @@ class CONTENT_EXPORT NotificationIdGenerator {
int render_process_id) const;
private:
// The NotificationMessageFilter that owns |this| will outlive the context.
BrowserContext* browser_context_;
DISALLOW_COPY_AND_ASSIGN(NotificationIdGenerator);
};
} // namespace context
......
......@@ -36,8 +36,7 @@ PlatformNotificationContextImpl::PlatformNotificationContextImpl(
const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context)
: path_(path),
browser_context_(browser_context),
service_worker_context_(service_worker_context),
notification_id_generator_(browser_context) {
service_worker_context_(service_worker_context) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment