OLD | NEW |
---|---|
(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 DCHECK(origin.is_valid()); | |
31 DCHECK_EQ(origin, origin.GetOrigin()); | |
32 | |
33 std::stringstream stream; | |
34 | |
35 stream << | |
36 BASE_HASH_NAMESPACE::hash<base::FilePath>()(browser_context_->GetPath()); | |
johnme
2015/05/27 18:18:35
I'm still uncomfortable with using a hash function
Peter Beverloo
2015/05/28 12:51:44
Switched to SHA-1 after talking to bauerb@. Genera
| |
37 stream << browser_context_->IsOffTheRecord(); | |
38 stream << origin; | |
39 | |
40 // Persistent notification ids are unique for the lifetime of the notification | |
41 // database, orthogonal to the renderer that created the notification. | |
42 | |
43 stream << !!tag.size(); | |
44 if (tag.size()) | |
45 stream << tag; | |
46 else | |
47 stream << base::Int64ToString(persistent_notification_id); | |
48 | |
49 return stream.str(); | |
50 } | |
51 | |
52 std::string NotificationIdGenerator::GenerateForNonPersistentNotification( | |
53 const GURL& origin, | |
54 const std::string& tag, | |
55 int non_persistent_notification_id) const { | |
56 DCHECK(origin.is_valid()); | |
57 DCHECK_EQ(origin, origin.GetOrigin()); | |
58 | |
59 std::stringstream stream; | |
60 | |
61 stream << | |
62 BASE_HASH_NAMESPACE::hash<base::FilePath>()(browser_context_->GetPath()); | |
63 stream << browser_context_->IsOffTheRecord(); | |
64 stream << origin; | |
65 | |
66 // Non-persistent notification ids are unique per renderer process when no | |
67 // tag is being used. Tags still identify uniqueness for the given origin. | |
68 | |
69 stream << !!tag.size(); | |
70 if (!tag.size()) { | |
71 const std::string render_process_id_string = | |
72 base::IntToString(render_process_id_); | |
73 | |
74 stream << render_process_id_string.size(); | |
johnme
2015/05/27 18:18:35
This is also ambiguous. Whilst it appears to be tr
Peter Beverloo
2015/05/28 12:51:44
Done.
| |
75 stream << render_process_id_string; | |
76 | |
77 stream << base::IntToString(non_persistent_notification_id); | |
78 } else { | |
79 stream << tag; | |
80 } | |
81 | |
82 return stream.str(); | |
83 } | |
84 | |
85 } // namespace content | |
OLD | NEW |