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