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

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

Issue 1116693002: [NOT FOR REVIEW] Significantly simplify the PlatformNotificationService //content API. (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), render_process_id_(render_process_id) {
22 }
23
24 NotificationIdGenerator::~NotificationIdGenerator() {
25 }
26
27 std::string NotificationIdGenerator::GenerateForPersistentNotification(
28 const GURL& origin,
29 const std::string& tag,
30 int64_t persistent_notification_id) const {
31 std::stringstream stream;
32
33 stream << base::Hash(browser_context_->GetPath().value());
34 stream << browser_context_->IsOffTheRecord();
35 stream << origin.GetOrigin();
36
37 // Persistent notification ids are unique for the lifetime of the notification
38 // database, orthogonal to the renderer that created the notification.
39
40 stream << !!tag.size();
41 if (tag.size())
42 stream << tag;
43 else
44 stream << base::Int64ToString(persistent_notification_id);
45
46 return stream.str();
47 }
48
49 std::string NotificationIdGenerator::GenerateForNonPersistentNotification(
50 const GURL& origin,
51 const std::string& tag,
52 int non_persistent_notification_id) const {
53 std::stringstream stream;
54
55 stream << base::Hash(browser_context_->GetPath().value());
56 stream << browser_context_->IsOffTheRecord();
57 stream << origin.GetOrigin();
58
59 // Non-persistent notification ids are unique per renderer process.
60 stream << render_process_id_;
61
62 stream << !!tag.size();
63 if (tag.size())
64 stream << tag;
65 else
66 stream << base::IntToString(non_persistent_notification_id);
67
68 return stream.str();
69 }
70
71 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698