Commit f08addc1 authored by peter's avatar peter Committed by Commit bot

Consistently handle persistent notification ids as int64_t

This changes the renderer side of Chromium to only denote persistent
notification ids as int64_ts rather than as strings.

This CL is part of a three-sided patch:
  [1] https://codereview.chromium.org/1078783002/
  [2] This CL.
  [3] https://codereview.chromium.org/1072873002/

BUG=

Review URL: https://codereview.chromium.org/1071203002

Cr-Commit-Position: refs/heads/master@{#325469}
parent 2f01fbf0
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "content/browser/notifications/notification_event_dispatcher_impl.h" #include "content/browser/notifications/notification_event_dispatcher_impl.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/strings/string_number_conversions.h"
#include "content/browser/notifications/platform_notification_context_impl.h" #include "content/browser/notifications/platform_notification_context_impl.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration.h" #include "content/browser/service_worker/service_worker_registration.h"
...@@ -77,15 +76,10 @@ void DispatchNotificationClickEventOnRegistration( ...@@ -77,15 +76,10 @@ void DispatchNotificationClickEventOnRegistration(
dispatch_complete_callback, dispatch_complete_callback,
service_worker_registration); service_worker_registration);
// TODO(peter): Pass the persistent notification id as an int64_t rather
// than as a string. This depends on the Blink API being updated.
std::string persistent_notification_id_string =
base::Int64ToString(notification_database_data.notification_id);
service_worker_registration->active_version()-> service_worker_registration->active_version()->
DispatchNotificationClickEvent( DispatchNotificationClickEvent(
dispatch_event_callback, dispatch_event_callback,
persistent_notification_id_string, notification_database_data.notification_id,
notification_database_data.notification_data); notification_database_data.notification_data);
return; return;
} }
......
...@@ -643,26 +643,24 @@ void ServiceWorkerVersion::DispatchSyncEvent(const StatusCallback& callback) { ...@@ -643,26 +643,24 @@ void ServiceWorkerVersion::DispatchSyncEvent(const StatusCallback& callback) {
void ServiceWorkerVersion::DispatchNotificationClickEvent( void ServiceWorkerVersion::DispatchNotificationClickEvent(
const StatusCallback& callback, const StatusCallback& callback,
const std::string& notification_id, int64_t persistent_notification_id,
const PlatformNotificationData& notification_data) { const PlatformNotificationData& notification_data) {
DCHECK_EQ(ACTIVATED, status()) << status(); DCHECK_EQ(ACTIVATED, status()) << status();
if (running_status() != RUNNING) { if (running_status() != RUNNING) {
// Schedule calling this method after starting the worker. // Schedule calling this method after starting the worker.
StartWorker(base::Bind(&RunTaskAfterStartWorker, StartWorker(base::Bind(
weak_factory_.GetWeakPtr(), callback, &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback,
base::Bind(&self::DispatchNotificationClickEvent, base::Bind(&self::DispatchNotificationClickEvent,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(), callback,
callback, notification_id, persistent_notification_id, notification_data)));
notification_data)));
return; return;
} }
int request_id = AddRequest(callback, &notification_click_callbacks_, int request_id = AddRequest(callback, &notification_click_callbacks_,
REQUEST_NOTIFICATION_CLICK); REQUEST_NOTIFICATION_CLICK);
ServiceWorkerStatusCode status = embedded_worker_->SendMessage( ServiceWorkerStatusCode status =
ServiceWorkerMsg_NotificationClickEvent(request_id, embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationClickEvent(
notification_id, request_id, persistent_notification_id, notification_data));
notification_data));
if (status != SERVICE_WORKER_OK) { if (status != SERVICE_WORKER_OK) {
notification_click_callbacks_.Remove(request_id); notification_click_callbacks_.Remove(request_id);
RunSoon(base::Bind(callback, status)); RunSoon(base::Bind(callback, status));
......
...@@ -215,7 +215,7 @@ class CONTENT_EXPORT ServiceWorkerVersion ...@@ -215,7 +215,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
// This must be called when the status() is ACTIVATED. // This must be called when the status() is ACTIVATED.
void DispatchNotificationClickEvent( void DispatchNotificationClickEvent(
const StatusCallback& callback, const StatusCallback& callback,
const std::string& notification_id, int64_t persistent_notification_id,
const PlatformNotificationData& notification_data); const PlatformNotificationData& notification_data);
// Sends push event to the associated embedded worker and asynchronously calls // Sends push event to the associated embedded worker and asynchronously calls
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/thread_task_runner_handle.h" #include "base/thread_task_runner_handle.h"
#include "base/threading/thread_local.h" #include "base/threading/thread_local.h"
...@@ -93,7 +92,7 @@ void NotificationManager::showPersistent( ...@@ -93,7 +92,7 @@ void NotificationManager::showPersistent(
blink::WebServiceWorkerRegistration* service_worker_registration, blink::WebServiceWorkerRegistration* service_worker_registration,
blink::WebNotificationShowCallbacks* callbacks) { blink::WebNotificationShowCallbacks* callbacks) {
DCHECK(service_worker_registration); DCHECK(service_worker_registration);
int64 service_worker_registration_id = int64_t service_worker_registration_id =
static_cast<WebServiceWorkerRegistrationImpl*>( static_cast<WebServiceWorkerRegistrationImpl*>(
service_worker_registration)->registration_id(); service_worker_registration)->registration_id();
...@@ -147,7 +146,7 @@ void NotificationManager::getNotifications( ...@@ -147,7 +146,7 @@ void NotificationManager::getNotifications(
service_worker_registration); service_worker_registration);
GURL origin = GURL(service_worker_registration_impl->scope()).GetOrigin(); GURL origin = GURL(service_worker_registration_impl->scope()).GetOrigin();
int64 service_worker_registration_id = int64_t service_worker_registration_id =
service_worker_registration_impl->registration_id(); service_worker_registration_impl->registration_id();
// TODO(peter): GenerateNotificationId is more of a request id. Consider // TODO(peter): GenerateNotificationId is more of a request id. Consider
...@@ -186,20 +185,7 @@ void NotificationManager::close(blink::WebNotificationDelegate* delegate) { ...@@ -186,20 +185,7 @@ void NotificationManager::close(blink::WebNotificationDelegate* delegate) {
void NotificationManager::closePersistent( void NotificationManager::closePersistent(
const blink::WebSerializedOrigin& origin, const blink::WebSerializedOrigin& origin,
const blink::WebString& persistent_notification_id_string) { int64_t persistent_notification_id) {
// TODO(peter): Blink should store the persistent_notification_id as an
// int64_t instead of a string. The id, created by Chromium, is a decimal
// number that fits in an int64_t, so convert it until the API updates.
base::string16 string_value = persistent_notification_id_string;
int64_t persistent_notification_id = 0;
if (!base::StringToInt64(string_value,
&persistent_notification_id)) {
NOTREACHED() << "Unable to close persistent notification; invalid id: "
<< string_value;
return;
}
thread_safe_sender_->Send(new PlatformNotificationHostMsg_ClosePersistent( thread_safe_sender_->Send(new PlatformNotificationHostMsg_ClosePersistent(
GURL(origin.string()), GURL(origin.string()),
persistent_notification_id)); persistent_notification_id));
...@@ -301,8 +287,7 @@ void NotificationManager::OnDidGetNotifications( ...@@ -301,8 +287,7 @@ void NotificationManager::OnDidGetNotifications(
for (size_t i = 0; i < notification_infos.size(); ++i) { for (size_t i = 0; i < notification_infos.size(); ++i) {
blink::WebPersistentNotificationInfo web_notification_info; blink::WebPersistentNotificationInfo web_notification_info;
web_notification_info.persistentNotificationId = web_notification_info.persistentId = notification_infos[i].first;
blink::WebString::fromUTF8(notification_infos[i].first);
web_notification_info.data = web_notification_info.data =
ToWebNotificationData(notification_infos[i].second); ToWebNotificationData(notification_infos[i].second);
...@@ -334,7 +319,7 @@ void NotificationManager::DisplayPageNotification( ...@@ -334,7 +319,7 @@ void NotificationManager::DisplayPageNotification(
void NotificationManager::DisplayPersistentNotification( void NotificationManager::DisplayPersistentNotification(
const blink::WebSerializedOrigin& origin, const blink::WebSerializedOrigin& origin,
const blink::WebNotificationData& notification_data, const blink::WebNotificationData& notification_data,
int64 service_worker_registration_id, int64_t service_worker_registration_id,
scoped_ptr<blink::WebNotificationShowCallbacks> callbacks, scoped_ptr<blink::WebNotificationShowCallbacks> callbacks,
const SkBitmap& icon) { const SkBitmap& icon) {
// TODO(peter): GenerateNotificationId is more of a request id. Consider // TODO(peter): GenerateNotificationId is more of a request id. Consider
......
...@@ -56,7 +56,7 @@ class NotificationManager : public blink::WebNotificationManager, ...@@ -56,7 +56,7 @@ class NotificationManager : public blink::WebNotificationManager,
virtual void close(blink::WebNotificationDelegate* delegate); virtual void close(blink::WebNotificationDelegate* delegate);
virtual void closePersistent( virtual void closePersistent(
const blink::WebSerializedOrigin& origin, const blink::WebSerializedOrigin& origin,
const blink::WebString& persistent_notification_id); int64_t persistent_notification_id);
virtual void notifyDelegateDestroyed( virtual void notifyDelegateDestroyed(
blink::WebNotificationDelegate* delegate); blink::WebNotificationDelegate* delegate);
virtual blink::WebNotificationPermission checkPermission( virtual blink::WebNotificationPermission checkPermission(
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
// Defines the pair of [persistent notification id] => [notification data] used // Defines the pair of [persistent notification id] => [notification data] used
// when getting the notifications for a given Service Worker registration. // when getting the notifications for a given Service Worker registration.
using PersistentNotificationInfo = using PersistentNotificationInfo =
std::pair<std::string, content::PlatformNotificationData>; std::pair<int64_t, content::PlatformNotificationData>;
#endif // CONTENT_COMMON_PLATFORM_NOTIFICATION_MESSAGES_H_ #endif // CONTENT_COMMON_PLATFORM_NOTIFICATION_MESSAGES_H_
......
...@@ -384,7 +384,7 @@ IPC_MESSAGE_CONTROL1(ServiceWorkerMsg_SyncEvent, ...@@ -384,7 +384,7 @@ IPC_MESSAGE_CONTROL1(ServiceWorkerMsg_SyncEvent,
int /* request_id */) int /* request_id */)
IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_NotificationClickEvent, IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_NotificationClickEvent,
int /* request_id */, int /* request_id */,
std::string /* notification_id */, int64_t /* persistent_notification_id */,
content::PlatformNotificationData /* notification_data */) content::PlatformNotificationData /* notification_data */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_PushEvent, IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_PushEvent,
int /* request_id */, int /* request_id */,
......
...@@ -365,14 +365,14 @@ void ServiceWorkerScriptContext::OnSyncEvent(int request_id) { ...@@ -365,14 +365,14 @@ void ServiceWorkerScriptContext::OnSyncEvent(int request_id) {
void ServiceWorkerScriptContext::OnNotificationClickEvent( void ServiceWorkerScriptContext::OnNotificationClickEvent(
int request_id, int request_id,
const std::string& notification_id, int64_t persistent_notification_id,
const PlatformNotificationData& notification_data) { const PlatformNotificationData& notification_data) {
TRACE_EVENT0("ServiceWorker", TRACE_EVENT0("ServiceWorker",
"ServiceWorkerScriptContext::OnNotificationClickEvent"); "ServiceWorkerScriptContext::OnNotificationClickEvent");
notification_click_start_timings_[request_id] = base::TimeTicks::Now(); notification_click_start_timings_[request_id] = base::TimeTicks::Now();
proxy_->dispatchNotificationClickEvent( proxy_->dispatchNotificationClickEvent(
request_id, request_id,
blink::WebString::fromUTF8(notification_id), persistent_notification_id,
ToWebNotificationData(notification_data)); ToWebNotificationData(notification_data));
} }
......
...@@ -115,7 +115,7 @@ class ServiceWorkerScriptContext { ...@@ -115,7 +115,7 @@ class ServiceWorkerScriptContext {
void OnSyncEvent(int request_id); void OnSyncEvent(int request_id);
void OnNotificationClickEvent( void OnNotificationClickEvent(
int request_id, int request_id,
const std::string& notification_id, int64_t persistent_notification_id,
const PlatformNotificationData& notification_data); const PlatformNotificationData& notification_data);
void OnPushEvent(int request_id, const std::string& data); void OnPushEvent(int request_id, const std::string& data);
void OnGeofencingEvent(int request_id, void OnGeofencingEvent(int request_id,
......
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