| Index: content/browser/notifications/notification_id_generator.cc
|
| diff --git a/content/browser/notifications/notification_id_generator.cc b/content/browser/notifications/notification_id_generator.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a27c89e95b20475a4ee3446190ed65079457f951
|
| --- /dev/null
|
| +++ b/content/browser/notifications/notification_id_generator.cc
|
| @@ -0,0 +1,71 @@
|
| +// 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.
|
| +
|
| +#include "content/browser/notifications/notification_id_generator.h"
|
| +
|
| +#include <sstream>
|
| +
|
| +#include "base/files/file_path.h"
|
| +#include "base/hash.h"
|
| +#include "base/logging.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "content/public/browser/browser_context.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace content {
|
| +
|
| +NotificationIdGenerator::NotificationIdGenerator(
|
| + BrowserContext* browser_context,
|
| + int render_process_id)
|
| + : browser_context_(browser_context), render_process_id_(render_process_id) {
|
| +}
|
| +
|
| +NotificationIdGenerator::~NotificationIdGenerator() {
|
| +}
|
| +
|
| +std::string NotificationIdGenerator::GenerateForPersistentNotification(
|
| + const GURL& origin,
|
| + const std::string& tag,
|
| + int64_t persistent_notification_id) const {
|
| + std::stringstream stream;
|
| +
|
| + stream << base::Hash(browser_context_->GetPath().value());
|
| + stream << browser_context_->IsOffTheRecord();
|
| + stream << origin.GetOrigin();
|
| +
|
| + // Persistent notification ids are unique for the lifetime of the notification
|
| + // database, orthogonal to the renderer that created the notification.
|
| +
|
| + stream << !!tag.size();
|
| + if (tag.size())
|
| + stream << tag;
|
| + else
|
| + stream << base::Int64ToString(persistent_notification_id);
|
| +
|
| + return stream.str();
|
| +}
|
| +
|
| +std::string NotificationIdGenerator::GenerateForNonPersistentNotification(
|
| + const GURL& origin,
|
| + const std::string& tag,
|
| + int non_persistent_notification_id) const {
|
| + std::stringstream stream;
|
| +
|
| + stream << base::Hash(browser_context_->GetPath().value());
|
| + stream << browser_context_->IsOffTheRecord();
|
| + stream << origin.GetOrigin();
|
| +
|
| + // Non-persistent notification ids are unique per renderer process.
|
| + stream << render_process_id_;
|
| +
|
| + stream << !!tag.size();
|
| + if (tag.size())
|
| + stream << tag;
|
| + else
|
| + stream << base::IntToString(non_persistent_notification_id);
|
| +
|
| + return stream.str();
|
| +}
|
| +
|
| +} // namespace content
|
|
|