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

Unified Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2746783002: [ServiceWorker] Mojofy InstallEvent of Service Worker (Closed)
Patch Set: Address shimazu's comment #66 and leon's #69 Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/service_worker/service_worker_context_client.cc
diff --git a/content/renderer/service_worker/service_worker_context_client.cc b/content/renderer/service_worker/service_worker_context_client.cc
index c621edab6160329a6aa92b7cfdb21bd5fb3e205d..41e87054929e6f3f481f465010234c71e8c59b0d 100644
--- a/content/renderer/service_worker/service_worker_context_client.cc
+++ b/content/renderer/service_worker/service_worker_context_client.cc
@@ -272,6 +272,8 @@ struct ServiceWorkerContextClient::WorkerContextData {
IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>;
using SkipWaitingCallbacksMap =
IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>;
+ using InstallEventCallbacksMap =
+ IDMap<std::unique_ptr<const DispatchInstallEventCallback>>;
using ActivateEventCallbacksMap =
IDMap<std::unique_ptr<const DispatchActivateEventCallback>>;
using BackgroundFetchAbortEventCallbacksMap =
@@ -317,6 +319,9 @@ struct ServiceWorkerContextClient::WorkerContextData {
// Pending callbacks for ClaimClients().
ClaimClientsCallbacksMap claim_clients_callbacks;
+ // Pending callbacks for Install Events.
+ InstallEventCallbacksMap install_event_callbacks;
+
// Pending callbacks for Activate Events.
ActivateEventCallbacksMap activate_event_callbacks;
@@ -368,6 +373,10 @@ struct ServiceWorkerContextClient::WorkerContextData {
// Pending navigation preload requests.
NavigationPreloadRequestsMap preload_requests;
+ // Maps every install event id with its corresponding
+ // mojom::ServiceWorkerInstallEventMethodsAssociatedPt.
+ InstallEventMethodsMap install_methods_map;
+
base::ThreadChecker thread_checker;
base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory;
base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory;
@@ -563,7 +572,6 @@ void ServiceWorkerContextClient::OnMessageReceived(
CHECK_EQ(embedded_worker_id_, embedded_worker_id);
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message)
- IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
@@ -725,7 +733,15 @@ void ServiceWorkerContextClient::WillDestroyWorkerContext(
// (while we're still on the worker thread).
proxy_ = NULL;
- // Aborts all the pending events callbacks.
+ // Aborts the all pending install event callbacks which has three
+ // parameters so that here can't use AbortPendingEventCallbacks.
+ for (WorkerContextData::InstallEventCallbacksMap::iterator it(
+ &context_->install_event_callbacks);
+ !it.IsAtEnd(); it.Advance()) {
+ it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, false,
+ base::Time::Now());
+ }
+ // Aborts all other pending events callbacks.
AbortPendingEventCallbacks(context_->activate_event_callbacks);
AbortPendingEventCallbacks(context_->background_fetch_abort_event_callbacks);
AbortPendingEventCallbacks(context_->background_fetch_click_event_callbacks);
@@ -895,9 +911,13 @@ void ServiceWorkerContextClient::DidHandleInstallEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- Send(new ServiceWorkerHostMsg_InstallEventFinished(
- GetRoutingID(), request_id, result, proxy_->HasFetchEventHandler(),
- base::Time::FromDoubleT(event_dispatch_time)));
+ const DispatchInstallEventCallback* callback =
+ context_->install_event_callbacks.Lookup(request_id);
+ DCHECK(callback);
+ callback->Run(EventResultToStatus(result), proxy_->HasFetchEventHandler(),
+ base::Time::FromDoubleT(event_dispatch_time));
+ context_->install_event_callbacks.Remove(request_id);
+ context_->install_methods_map.erase(request_id);
}
void ServiceWorkerContextClient::RespondToFetchEventWithNoResponse(
@@ -1119,11 +1139,13 @@ void ServiceWorkerContextClient::Claim(
}
void ServiceWorkerContextClient::RegisterForeignFetchScopes(
+ int event_id,
const blink::WebVector<blink::WebURL>& sub_scopes,
const blink::WebVector<blink::WebSecurityOrigin>& origins) {
- Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes(
- GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()),
- std::vector<url::Origin>(origins.begin(), origins.end())));
+ DCHECK(context_->install_methods_map[event_id].is_bound());
+ context_->install_methods_map[event_id]->RegisterForeignFetchScopes(
+ std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()),
+ std::vector<url::Origin>(origins.begin(), origins.end()));
}
void ServiceWorkerContextClient::DispatchSyncEvent(
@@ -1271,6 +1293,23 @@ void ServiceWorkerContextClient::DispatchBackgroundFetchedEvent(
request_id, blink::WebString::FromUTF8(tag), web_fetches);
}
+void ServiceWorkerContextClient::DispatchInstallEvent(
+ mojom::ServiceWorkerInstallEventMethodsAssociatedPtrInfo client,
+ const DispatchInstallEventCallback& callback) {
+ TRACE_EVENT0("ServiceWorker",
+ "ServiceWorkerContextClient::DispatchInstallEvent");
+
+ int event_id = context_->install_event_callbacks.Add(
+ base::MakeUnique<DispatchInstallEventCallback>(callback));
+
+ DCHECK(!context_->install_methods_map.count(event_id));
+ mojom::ServiceWorkerInstallEventMethodsAssociatedPtr install_methods;
+ install_methods.Bind(std::move(client));
+ context_->install_methods_map[event_id] = std::move(install_methods);
+
+ proxy_->DispatchInstallEvent(event_id);
+}
+
void ServiceWorkerContextClient::DispatchExtendableMessageEvent(
mojom::ExtendableMessageEventPtr event,
const DispatchExtendableMessageEventCallback& callback) {
@@ -1306,12 +1345,6 @@ void ServiceWorkerContextClient::DispatchExtendableMessageEvent(
WebServiceWorkerImpl::CreateHandle(worker));
}
-void ServiceWorkerContextClient::OnInstallEvent(int request_id) {
- TRACE_EVENT0("ServiceWorker",
- "ServiceWorkerContextClient::OnInstallEvent");
- proxy_->DispatchInstallEvent(request_id);
-}
-
void ServiceWorkerContextClient::DispatchFetchEvent(
int fetch_event_id,
const ServiceWorkerFetchRequest& request,

Powered by Google App Engine
This is Rietveld 408576698