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

Side by Side Diff: content/browser/notifications/notification_id_generator.cc

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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "content/browser/notifications/notification_id_generator.h"
6
7 #include <sstream>
8
9 #include "base/files/file_path.h"
10 #include "base/hash.h"
11 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "content/public/browser/browser_context.h"
14 #include "url/gurl.h"
15
16 namespace content {
17
18 NotificationIdGenerator::NotificationIdGenerator(
19 BrowserContext* browser_context,
20 int render_process_id)
21 : browser_context_(browser_context),
22 render_process_id_(render_process_id) {}
23
24 NotificationIdGenerator::~NotificationIdGenerator() {}
25
26 std::string NotificationIdGenerator::GenerateForPersistentNotification(
27 const GURL& origin,
28 const std::string& tag,
29 int64_t persistent_notification_id) const {
30 std::stringstream stream;
31
32 stream << base::Hash(browser_context_->GetPath().value());
johnme 2015/05/08 15:35:25 base::Hash is just 32-bits, and not a secure hash.
Peter Beverloo 2015/05/20 18:43:33 What would you propose to do instead, without over
33 stream << browser_context_->IsOffTheRecord();
34 stream << origin.GetOrigin();
johnme 2015/05/08 15:35:25 This is ambiguous. The following two cases will gi
Peter Beverloo 2015/05/20 18:43:33 They wouldn't, because origins end with slashes. :
35
36 // Persistent notification ids are unique for the lifetime of the notification
37 // database, orthogonal to the renderer that created the notification.
38
39 stream << !!tag.size();
40 if (tag.size())
41 stream << tag;
42 else
43 stream << base::Int64ToString(persistent_notification_id);
44
45 return stream.str();
46 }
47
48 std::string NotificationIdGenerator::GenerateForNonPersistentNotification(
49 const GURL& origin,
50 const std::string& tag,
51 int non_persistent_notification_id) const {
52 std::stringstream stream;
53
54 stream << base::Hash(browser_context_->GetPath().value());
55 stream << browser_context_->IsOffTheRecord();
56 stream << origin.GetOrigin();
57
58 // Non-persistent notification ids are unique per renderer process.
59 stream << render_process_id_;
johnme 2015/05/08 15:35:25 This is ambiguous. The following two cases will gi
Peter Beverloo 2015/05/20 18:43:33 Fixed, and added a test.
60
61 stream << !!tag.size();
62 if (tag.size())
63 stream << tag;
64 else
65 stream << base::IntToString(non_persistent_notification_id);
66
67 return stream.str();
68 }
69
70 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698