Commit 8428d739 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

notifications: Prepare for service worker UI thread core.

The thread ServiceWorkerContextCore lives on (the "core thread") will
move from the IO thread to the UI thread when the ServiceWorkerOnUI
feature is enabled.

This CL makes code in content/browser/notifications aware of the core
thread instead of assuming the IO thread. This makes the remaining
"Push*" browser_tests pass when the feature is enabled.

Bug: 824858
Change-Id: Ice834d2d4a69505b977cb469b516e0705c36202c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768602Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690276}
parent 9727a4fa
...@@ -80,29 +80,29 @@ PersistentNotificationStatus ConvertServiceWorkerStatus( ...@@ -80,29 +80,29 @@ PersistentNotificationStatus ConvertServiceWorkerStatus(
} }
// To be called when a notification event has finished with a // To be called when a notification event has finished with a
// blink::ServiceWorkerStatusCode result. Will post a task to call // blink::ServiceWorkerStatusCode result. Will run or post a task to call
// |dispatch_complete_callback| on the UI thread with a // |dispatch_complete_callback| on the UI thread with a
// PersistentNotificationStatus derived from the service worker status. // PersistentNotificationStatus derived from the service worker status.
void ServiceWorkerNotificationEventFinished( void ServiceWorkerNotificationEventFinished(
NotificationDispatchCompleteCallback dispatch_complete_callback, NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode service_worker_status) { blink::ServiceWorkerStatusCode service_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
base::PostTask( RunOrPostTaskOnThread(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, BrowserThread::UI,
base::BindOnce(std::move(dispatch_complete_callback), base::BindOnce(std::move(dispatch_complete_callback),
ConvertServiceWorkerStatus(service_worker_status))); ConvertServiceWorkerStatus(service_worker_status)));
} }
// Dispatches the given notification action event on // Dispatches the given notification action event on
// |service_worker_registration| if the registration was available. Must be // |service_worker_registration| if the registration was available. Must be
// called on the IO thread. // called on the service worker core thread.
void DispatchNotificationEventOnRegistration( void DispatchNotificationEventOnRegistration(
const NotificationDatabaseData& notification_database_data, const NotificationDatabaseData& notification_database_data,
NotificationOperationCallback dispatch_event_action, NotificationOperationCallback dispatch_event_action,
NotificationDispatchCompleteCallback dispatch_complete_callback, NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode service_worker_status, blink::ServiceWorkerStatusCode service_worker_status,
scoped_refptr<ServiceWorkerRegistration> service_worker_registration) { scoped_refptr<ServiceWorkerRegistration> service_worker_registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// This LOG(INFO) deliberately exists to help track down the cause of // This LOG(INFO) deliberately exists to help track down the cause of
// https://crbug.com/534537, where notifications sometimes do not react to // https://crbug.com/534537, where notifications sometimes do not react to
...@@ -175,8 +175,8 @@ void FindServiceWorkerRegistration( ...@@ -175,8 +175,8 @@ void FindServiceWorkerRegistration(
return; return;
} }
base::PostTask( RunOrPostTaskOnThread(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, ServiceWorkerContext::GetCoreThreadId(),
base::BindOnce(&ServiceWorkerContextWrapper::FindReadyRegistrationForId, base::BindOnce(&ServiceWorkerContextWrapper::FindReadyRegistrationForId,
service_worker_context, service_worker_context,
notification_database_data.service_worker_registration_id, notification_database_data.service_worker_registration_id,
...@@ -209,7 +209,7 @@ void ReadNotificationDatabaseData( ...@@ -209,7 +209,7 @@ void ReadNotificationDatabaseData(
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Dispatches the notificationclick event on |service_worker|. // Dispatches the notificationclick event on |service_worker|.
// Must be called on the IO thread. // Must be called on the service worker core thread.
void DispatchNotificationClickEventOnWorker( void DispatchNotificationClickEventOnWorker(
const scoped_refptr<ServiceWorkerVersion>& service_worker, const scoped_refptr<ServiceWorkerVersion>& service_worker,
const NotificationDatabaseData& notification_database_data, const NotificationDatabaseData& notification_database_data,
...@@ -217,7 +217,7 @@ void DispatchNotificationClickEventOnWorker( ...@@ -217,7 +217,7 @@ void DispatchNotificationClickEventOnWorker(
const base::Optional<base::string16>& reply, const base::Optional<base::string16>& reply,
ServiceWorkerVersion::StatusCallback callback, ServiceWorkerVersion::StatusCallback callback,
blink::ServiceWorkerStatusCode start_worker_status) { blink::ServiceWorkerStatusCode start_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (start_worker_status != blink::ServiceWorkerStatusCode::kOk) { if (start_worker_status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(start_worker_status); std::move(callback).Run(start_worker_status);
return; return;
...@@ -245,10 +245,10 @@ void DoDispatchNotificationClickEvent( ...@@ -245,10 +245,10 @@ void DoDispatchNotificationClickEvent(
const ServiceWorkerRegistration* service_worker_registration, const ServiceWorkerRegistration* service_worker_registration,
const NotificationDatabaseData& notification_database_data, const NotificationDatabaseData& notification_database_data,
NotificationDispatchCompleteCallback dispatch_complete_callback) { NotificationDispatchCompleteCallback dispatch_complete_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
base::PostTask( RunOrPostTaskOnThread(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, BrowserThread::UI,
base::BindOnce(&notifications::LogNotificationClickedEventToDevTools, base::BindOnce(&notifications::LogNotificationClickedEventToDevTools,
browser_context, notification_database_data, action_index, browser_context, notification_database_data, action_index,
reply)); reply));
...@@ -288,9 +288,9 @@ void DeleteNotificationDataFromDatabase( ...@@ -288,9 +288,9 @@ void DeleteNotificationDataFromDatabase(
const scoped_refptr<PlatformNotificationContext>& notification_context, const scoped_refptr<PlatformNotificationContext>& notification_context,
NotificationDispatchCompleteCallback dispatch_complete_callback, NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode status_code) { blink::ServiceWorkerStatusCode status_code) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
base::PostTask( RunOrPostTaskOnThread(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, BrowserThread::UI,
base::BindOnce( base::BindOnce(
&PlatformNotificationContext::DeleteNotificationData, &PlatformNotificationContext::DeleteNotificationData,
notification_context, notification_id, origin, notification_context, notification_id, origin,
...@@ -300,13 +300,13 @@ void DeleteNotificationDataFromDatabase( ...@@ -300,13 +300,13 @@ void DeleteNotificationDataFromDatabase(
} }
// Dispatches the notificationclose event on |service_worker|. // Dispatches the notificationclose event on |service_worker|.
// Must be called on the IO thread. // Must be called on the service worker core thread.
void DispatchNotificationCloseEventOnWorker( void DispatchNotificationCloseEventOnWorker(
const scoped_refptr<ServiceWorkerVersion>& service_worker, const scoped_refptr<ServiceWorkerVersion>& service_worker,
const NotificationDatabaseData& notification_database_data, const NotificationDatabaseData& notification_database_data,
ServiceWorkerVersion::StatusCallback callback, ServiceWorkerVersion::StatusCallback callback,
blink::ServiceWorkerStatusCode start_worker_status) { blink::ServiceWorkerStatusCode start_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (start_worker_status != blink::ServiceWorkerStatusCode::kOk) { if (start_worker_status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(start_worker_status); std::move(callback).Run(start_worker_status);
return; return;
...@@ -330,7 +330,7 @@ void DoDispatchNotificationCloseEvent( ...@@ -330,7 +330,7 @@ void DoDispatchNotificationCloseEvent(
const ServiceWorkerRegistration* service_worker_registration, const ServiceWorkerRegistration* service_worker_registration,
const NotificationDatabaseData& notification_database_data, const NotificationDatabaseData& notification_database_data,
NotificationDispatchCompleteCallback dispatch_complete_callback) { NotificationDispatchCompleteCallback dispatch_complete_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (by_user) { if (by_user) {
service_worker_registration->active_version()->RunAfterStartWorker( service_worker_registration->active_version()->RunAfterStartWorker(
ServiceWorkerMetrics::EventType::NOTIFICATION_CLOSE, ServiceWorkerMetrics::EventType::NOTIFICATION_CLOSE,
......
...@@ -47,7 +47,7 @@ NotificationStorage::~NotificationStorage() = default; ...@@ -47,7 +47,7 @@ NotificationStorage::~NotificationStorage() = default;
void NotificationStorage::WriteNotificationData( void NotificationStorage::WriteNotificationData(
const NotificationDatabaseData& data, const NotificationDatabaseData& data,
PlatformNotificationContext::WriteResultCallback callback) { PlatformNotificationContext::WriteResultCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
std::string serialized_data; std::string serialized_data;
if (!SerializeNotificationDatabaseData(data, &serialized_data)) { if (!SerializeNotificationDatabaseData(data, &serialized_data)) {
DLOG(ERROR) << "Unable to serialize data for a notification belonging " DLOG(ERROR) << "Unable to serialize data for a notification belonging "
...@@ -81,7 +81,7 @@ void NotificationStorage::ReadNotificationDataAndRecordInteraction( ...@@ -81,7 +81,7 @@ void NotificationStorage::ReadNotificationDataAndRecordInteraction(
const std::string& notification_id, const std::string& notification_id,
PlatformNotificationContext::Interaction interaction, PlatformNotificationContext::Interaction interaction,
PlatformNotificationContext::ReadResultCallback callback) { PlatformNotificationContext::ReadResultCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
service_worker_context_->GetRegistrationUserData( service_worker_context_->GetRegistrationUserData(
service_worker_registration_id, {CreateDataKey(notification_id)}, service_worker_registration_id, {CreateDataKey(notification_id)},
base::BindOnce(&NotificationStorage::OnReadCompleteUpdateInteraction, base::BindOnce(&NotificationStorage::OnReadCompleteUpdateInteraction,
......
...@@ -60,19 +60,25 @@ void PlatformNotificationServiceProxy::VerifyServiceWorkerScope( ...@@ -60,19 +60,25 @@ void PlatformNotificationServiceProxy::VerifyServiceWorkerScope(
DisplayResultCallback callback, DisplayResultCallback callback,
blink::ServiceWorkerStatusCode status, blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) { scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
base::OnceClosure task;
if (status == blink::ServiceWorkerStatusCode::kOk && if (status == blink::ServiceWorkerStatusCode::kOk &&
registration->scope().GetOrigin() == data.origin) { registration->scope().GetOrigin() == data.origin) {
base::PostTask( task = base::BindOnce(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE}, &PlatformNotificationServiceProxy::DoDisplayNotification, AsWeakPtr(),
base::BindOnce(&PlatformNotificationServiceProxy::DoDisplayNotification, data, registration->scope(), std::move(callback));
AsWeakPtr(), data, registration->scope(), } else {
std::move(callback))); task = base::BindOnce(std::move(callback), /* success= */ false,
/* notification_id= */ "");
}
if (ServiceWorkerContextWrapper::IsServiceWorkerOnUIEnabled()) {
std::move(task).Run();
} else { } else {
base::PostTask(FROM_HERE, base::PostTask(FROM_HERE,
{BrowserThread::UI, base::TaskPriority::USER_VISIBLE}, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(std::move(callback), /* success= */ false, std::move(task));
/* notification_id= */ ""));
} }
} }
...@@ -88,7 +94,9 @@ void PlatformNotificationServiceProxy::DisplayNotification( ...@@ -88,7 +94,9 @@ void PlatformNotificationServiceProxy::DisplayNotification(
} }
base::PostTask( base::PostTask(
FROM_HERE, {BrowserThread::IO, base::TaskPriority::USER_VISIBLE}, FROM_HERE,
{ServiceWorkerContext::GetCoreThreadId(),
base::TaskPriority::USER_VISIBLE},
base::BindOnce( base::BindOnce(
&ServiceWorkerContextWrapper::FindReadyRegistrationForId, &ServiceWorkerContextWrapper::FindReadyRegistrationForId,
service_worker_context_, data.service_worker_registration_id, service_worker_context_, data.service_worker_registration_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