Commit fd1fa7e7 authored by Anita Woodruff's avatar Anita Woodruff Committed by Commit Bot

[Notifications] Rename non_persistent_notification_id to request_id

- Now all the integer ids are request ids to avoid confusion with the
string notification ids.

Bug: 595685
Change-Id: Idd8008f59bb4a3db8eadf1455c6185fc7a01b338
Reviewed-on: https://chromium-review.googlesource.com/829553
Commit-Queue: Anita Woodruff <awdf@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524725}
parent 73b07571
......@@ -405,40 +405,40 @@ void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent(
void NotificationEventDispatcherImpl::RegisterNonPersistentNotification(
const std::string& notification_id,
int renderer_id,
int non_persistent_id) {
if (non_persistent_ids_.count(notification_id) &&
non_persistent_ids_[notification_id] != non_persistent_id) {
// Notify close for a previously displayed notification with the same id,
// this can happen when replacing a non-persistent notification with the
// same tag since from the JS point of view there will be two notification
// objects and the old one needs to receive the close event.
int request_id) {
if (request_ids_.count(notification_id) &&
request_ids_[notification_id] != request_id) {
// Notify close for a previously displayed notification with the same
// request id, this can happen when replacing a non-persistent notification
// with the same tag since from the JS point of view there will be two
// notification objects and the old one needs to receive the close event.
// TODO(miguelg) this is probably not the right layer to do this.
DispatchNonPersistentCloseEvent(notification_id);
}
renderer_ids_[notification_id] = renderer_id;
non_persistent_ids_[notification_id] = non_persistent_id;
request_ids_[notification_id] = request_id;
}
void NotificationEventDispatcherImpl::DispatchNonPersistentShowEvent(
const std::string& notification_id) {
if (!renderer_ids_.count(notification_id))
return;
DCHECK(non_persistent_ids_.count(notification_id));
DCHECK(request_ids_.count(notification_id));
RenderProcessHost* sender =
RenderProcessHost::FromID(renderer_ids_[notification_id]);
if (!sender)
return;
sender->Send(new PlatformNotificationMsg_DidShow(
non_persistent_ids_[notification_id]));
sender->Send(
new PlatformNotificationMsg_DidShow(request_ids_[notification_id]));
}
void NotificationEventDispatcherImpl::DispatchNonPersistentClickEvent(
const std::string& notification_id) {
if (!renderer_ids_.count(notification_id))
return;
DCHECK(non_persistent_ids_.count(notification_id));
DCHECK(request_ids_.count(notification_id));
RenderProcessHost* sender =
RenderProcessHost::FromID(renderer_ids_[notification_id]);
......@@ -448,15 +448,15 @@ void NotificationEventDispatcherImpl::DispatchNonPersistentClickEvent(
// closed.
if (!sender)
return;
sender->Send(new PlatformNotificationMsg_DidClick(
non_persistent_ids_[notification_id]));
sender->Send(
new PlatformNotificationMsg_DidClick(request_ids_[notification_id]));
}
void NotificationEventDispatcherImpl::DispatchNonPersistentCloseEvent(
const std::string& notification_id) {
if (!renderer_ids_.count(notification_id))
return;
DCHECK(non_persistent_ids_.count(notification_id));
DCHECK(request_ids_.count(notification_id));
RenderProcessHost* sender =
RenderProcessHost::FromID(renderer_ids_[notification_id]);
......@@ -467,18 +467,18 @@ void NotificationEventDispatcherImpl::DispatchNonPersistentCloseEvent(
if (!sender)
return;
sender->Send(new PlatformNotificationMsg_DidClose(
non_persistent_ids_[notification_id]));
sender->Send(
new PlatformNotificationMsg_DidClose(request_ids_[notification_id]));
// No interaction will follow anymore once the notification has been closed.
non_persistent_ids_.erase(notification_id);
request_ids_.erase(notification_id);
renderer_ids_.erase(notification_id);
}
void NotificationEventDispatcherImpl::RendererGone(int renderer_id) {
for (auto iter = renderer_ids_.begin(); iter != renderer_ids_.end();) {
if (iter->second == renderer_id) {
non_persistent_ids_.erase(iter->first);
request_ids_.erase(iter->first);
iter = renderer_ids_.erase(iter);
} else {
iter++;
......
......@@ -45,11 +45,10 @@ class NotificationEventDispatcherImpl : public NotificationEventDispatcher {
// dissappears.
void RendererGone(int renderer_id);
// Regsiter the fact that a non persistent notification has been
// displayed.
// Register the fact that a non persistent notification has been displayed.
void RegisterNonPersistentNotification(const std::string& notification_id,
int renderer_id,
int non_persistent_id);
int request_id);
private:
NotificationEventDispatcherImpl();
......@@ -58,8 +57,8 @@ class NotificationEventDispatcherImpl : public NotificationEventDispatcher {
// Notification Id -> renderer Id.
std::map<std::string, int> renderer_ids_;
// Notification Id -> non-persistent notification id.
std::map<std::string, int> non_persistent_ids_;
// Notification Id -> request Id.
std::map<std::string, int> request_ids_;
friend struct base::DefaultSingletonTraits<NotificationEventDispatcherImpl>;
......
......@@ -57,7 +57,7 @@ std::string NotificationIdGenerator::GenerateForPersistentNotification(
std::string NotificationIdGenerator::GenerateForNonPersistentNotification(
const GURL& origin,
const std::string& tag,
int non_persistent_notification_id,
int request_id,
int render_process_id) const {
DCHECK(origin.is_valid());
DCHECK_EQ(origin, origin.GetOrigin());
......@@ -72,7 +72,7 @@ std::string NotificationIdGenerator::GenerateForNonPersistentNotification(
stream << base::IntToString(render_process_id);
stream << kSeparator;
stream << base::IntToString(non_persistent_notification_id);
stream << base::IntToString(request_id);
} else {
stream << tag;
}
......
......@@ -58,12 +58,11 @@ class CONTENT_EXPORT NotificationIdGenerator {
int64_t persistent_notification_id) const;
// Generates an id for a non-persistent notification given the notification's
// origin, tag and non-persistent notification id. The non-persistent
// notification id must've been created by the |render_process_id|.
std::string GenerateForNonPersistentNotification(
const GURL& origin,
// origin, tag and request id. The request id must've been created by the
// |render_process_id|.
std::string GenerateForNonPersistentNotification(const GURL& origin,
const std::string& tag,
int non_persistent_notification_id,
int request_id,
int render_process_id) const;
private:
......
......@@ -136,7 +136,7 @@ void NotificationMessageFilter::OverrideThreadForMessage(
}
void NotificationMessageFilter::OnShowPlatformNotification(
int non_persistent_notification_id,
int request_id,
const GURL& origin,
const PlatformNotificationData& notification_data,
const NotificationResources& notification_resources) {
......@@ -158,13 +158,12 @@ void NotificationMessageFilter::OnShowPlatformNotification(
std::string notification_id =
GetNotificationIdGenerator()->GenerateForNonPersistentNotification(
origin, notification_data.tag, non_persistent_notification_id,
process_id_);
origin, notification_data.tag, request_id, process_id_);
NotificationEventDispatcherImpl* event_dispatcher =
NotificationEventDispatcherImpl::GetInstance();
non_persistent__notification_shown_ = true;
event_dispatcher->RegisterNonPersistentNotification(
notification_id, process_id_, non_persistent_notification_id);
event_dispatcher->RegisterNonPersistentNotification(notification_id,
process_id_, request_id);
service->DisplayNotification(browser_context_, notification_id, origin,
SanitizeNotificationData(notification_data),
......@@ -309,14 +308,14 @@ void NotificationMessageFilter::DidGetNotifications(
void NotificationMessageFilter::OnClosePlatformNotification(
const GURL& origin,
const std::string& tag,
int non_persistent_notification_id) {
int request_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!RenderProcessHost::FromID(process_id_))
return;
std::string notification_id =
GetNotificationIdGenerator()->GenerateForNonPersistentNotification(
origin, tag, non_persistent_notification_id, process_id_);
origin, tag, request_id, process_id_);
PlatformNotificationService* service =
GetContentClient()->browser()->GetPlatformNotificationService();
......
......@@ -53,7 +53,7 @@ class NotificationMessageFilter : public BrowserMessageFilter {
friend class BrowserThread;
void OnShowPlatformNotification(
int non_persistent_notification_id,
int request_id,
const GURL& origin,
const PlatformNotificationData& notification_data,
const NotificationResources& notification_resources);
......@@ -69,7 +69,7 @@ class NotificationMessageFilter : public BrowserMessageFilter {
const std::string& filter_tag);
void OnClosePlatformNotification(const GURL& origin,
const std::string& tag,
int non_persistent_notification_id);
int request_id);
void OnClosePersistentNotification(const GURL& origin,
const std::string& tag,
const std::string& notification_id);
......
......@@ -73,16 +73,13 @@ IPC_STRUCT_TRAITS_END()
// Messages sent from the browser to the renderer.
// Informs the renderer that the browser has displayed the notification.
IPC_MESSAGE_CONTROL1(PlatformNotificationMsg_DidShow,
int /* notification_id */)
IPC_MESSAGE_CONTROL1(PlatformNotificationMsg_DidShow, int /* request_id */)
// Informs the renderer that the notification has been closed.
IPC_MESSAGE_CONTROL1(PlatformNotificationMsg_DidClose,
int /* notification_id */)
IPC_MESSAGE_CONTROL1(PlatformNotificationMsg_DidClose, int /* request_id */)
// Informs the renderer that the notification has been clicked on.
IPC_MESSAGE_CONTROL1(PlatformNotificationMsg_DidClick,
int /* notification_id */)
IPC_MESSAGE_CONTROL1(PlatformNotificationMsg_DidClick, int /* request_id */)
// Reply to PlatformNotificationHostMsg_ShowPersistent indicating that a
// persistent notification has been shown on the platform (if |success| is
......@@ -102,7 +99,7 @@ IPC_MESSAGE_CONTROL2(PlatformNotificationMsg_DidGetNotifications,
IPC_MESSAGE_CONTROL4(
PlatformNotificationHostMsg_Show,
int /* non_persistent_notification_id */,
int /* request_id */,
GURL /* origin */,
content::PlatformNotificationData /* notification_data */,
content::NotificationResources /* notification_resources */)
......@@ -124,7 +121,7 @@ IPC_MESSAGE_CONTROL4(PlatformNotificationHostMsg_GetNotifications,
IPC_MESSAGE_CONTROL3(PlatformNotificationHostMsg_Close,
GURL /* origin */,
std::string /* tag */,
int /* non_persistent_notification_id */)
int /* request_id */)
IPC_MESSAGE_CONTROL3(PlatformNotificationHostMsg_ClosePersistent,
GURL /* origin */,
......
......@@ -93,10 +93,10 @@ void NotificationManager::Show(
GURL origin_gurl = url::Origin(origin).GetURL();
int notification_id =
int request_id =
notification_dispatcher_->GenerateNotificationId(NotificationWorkerId());
active_page_notifications_[notification_id] = ActiveNotificationData(
active_page_notifications_[request_id] = ActiveNotificationData(
delegate, origin_gurl,
notification_data.tag.Utf8(
WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD));
......@@ -105,8 +105,7 @@ void NotificationManager::Show(
// origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See
// https://crbug.com/490074 for detail.
thread_safe_sender_->Send(new PlatformNotificationHostMsg_Show(
notification_id, origin_gurl,
ToPlatformNotificationData(notification_data),
request_id, origin_gurl, ToPlatformNotificationData(notification_data),
ToNotificationResources(std::move(notification_resources))));
}
......@@ -245,8 +244,8 @@ bool NotificationManager::OnMessageReceived(const IPC::Message& message) {
return handled;
}
void NotificationManager::OnDidShow(int notification_id) {
const auto& iter = active_page_notifications_.find(notification_id);
void NotificationManager::OnDidShow(int request_id) {
const auto& iter = active_page_notifications_.find(request_id);
if (iter == active_page_notifications_.end())
return;
......@@ -269,8 +268,8 @@ void NotificationManager::OnDidShowPersistent(int request_id, bool success) {
pending_show_notification_requests_.Remove(request_id);
}
void NotificationManager::OnDidClose(int notification_id) {
const auto& iter = active_page_notifications_.find(notification_id);
void NotificationManager::OnDidClose(int request_id) {
const auto& iter = active_page_notifications_.find(request_id);
if (iter == active_page_notifications_.end())
return;
......@@ -279,8 +278,8 @@ void NotificationManager::OnDidClose(int notification_id) {
active_page_notifications_.erase(iter);
}
void NotificationManager::OnDidClick(int notification_id) {
const auto& iter = active_page_notifications_.find(notification_id);
void NotificationManager::OnDidClick(int request_id) {
const auto& iter = active_page_notifications_.find(request_id);
if (iter == active_page_notifications_.end())
return;
......
......@@ -70,10 +70,10 @@ class NotificationManager : public blink::WebNotificationManager,
NotificationDispatcher* notification_dispatcher);
// IPC message handlers.
void OnDidShow(int notification_id);
void OnDidShow(int request_id);
void OnDidShowPersistent(int request_id, bool success);
void OnDidClose(int notification_id);
void OnDidClick(int notification_id);
void OnDidClose(int request_id);
void OnDidClick(int request_id);
void OnDidGetNotifications(
int request_id,
const std::vector<PersistentNotificationInfo>& notification_infos);
......
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