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

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

Issue 2746783002: [ServiceWorker] Mojofy InstallEvent of Service Worker (Closed)
Patch Set: Fix the test failure 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 096ad12c1cd27b61c40677ca82c64e46ff29630c..0cc6e23c6638a9656c018e1fc1ec5b5dfc040575 100644
--- a/content/renderer/service_worker/service_worker_context_client.cc
+++ b/content/renderer/service_worker/service_worker_context_client.cc
@@ -273,6 +273,8 @@ struct ServiceWorkerContextClient::WorkerContextData {
IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>;
using SkipWaitingCallbacksMap =
IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>;
+ using InstallEventCallbacksMap =
+ IDMap<std::unique_ptr<DispatchInstallEventCallback>>;
using ActivateEventCallbacksMap =
IDMap<std::unique_ptr<DispatchActivateEventCallback>>;
using BackgroundFetchAbortEventCallbacksMap =
@@ -294,6 +296,8 @@ struct ServiceWorkerContextClient::WorkerContextData {
IDMap<std::unique_ptr<DispatchExtendableMessageEventCallback>>;
using NavigationPreloadRequestsMap = IDMap<
std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>;
+ using InstallEventMethodsMap =
+ std::map<int, mojom::ServiceWorkerInstallEventMethodsAssociatedPtr>;
explicit WorkerContextData(ServiceWorkerContextClient* owner)
: event_dispatcher_binding(owner),
@@ -318,6 +322,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 +375,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 +574,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 +735,16 @@ 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
horo 2017/04/27 09:22:21 Change AbortPendingEventCallbacks in line 248 to :
xiaofengzhang 2017/04/28 07:14:24 Done. Great! Thanks a lot!
+ // parameters so that here can't use AbortPendingEventCallbacks.
+ for (WorkerContextData::InstallEventCallbacksMap::iterator it(
+ &context_->install_event_callbacks);
+ !it.IsAtEnd(); it.Advance()) {
+ std::move(*it.GetCurrentValue())
+ .Run(SERVICE_WORKER_ERROR_ABORT, false /* has_fetch_handler */,
+ 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);
@@ -898,12 +917,18 @@ void ServiceWorkerContextClient::DidHandleExtendableMessageEvent(
}
void ServiceWorkerContextClient::DidHandleInstallEvent(
- int request_id,
+ int event_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- Send(new ServiceWorkerHostMsg_InstallEventFinished(
- GetRoutingID(), request_id, result, proxy_->HasFetchEventHandler(),
- base::Time::FromDoubleT(event_dispatch_time)));
+ DispatchInstallEventCallback* callback =
+ context_->install_event_callbacks.Lookup(event_id);
+ DCHECK(callback);
+ DCHECK(*callback);
+ std::move(*callback).Run(EventResultToStatus(result),
+ proxy_->HasFetchEventHandler(),
+ base::Time::FromDoubleT(event_dispatch_time));
+ context_->install_event_callbacks.Remove(event_id);
+ context_->install_methods_map.erase(event_id);
}
void ServiceWorkerContextClient::RespondToFetchEventWithNoResponse(
@@ -1126,11 +1151,13 @@ void ServiceWorkerContextClient::Claim(
}
void ServiceWorkerContextClient::RegisterForeignFetchScopes(
+ int event_id,
horo 2017/04/27 09:22:21 nit: install_event_id is more understandable.
xiaofengzhang 2017/04/28 07:14:24 Done.
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(
@@ -1282,6 +1309,23 @@ void ServiceWorkerContextClient::DispatchBackgroundFetchedEvent(
request_id, blink::WebString::FromUTF8(tag), web_fetches);
}
+void ServiceWorkerContextClient::DispatchInstallEvent(
+ mojom::ServiceWorkerInstallEventMethodsAssociatedPtrInfo client,
+ DispatchInstallEventCallback callback) {
+ TRACE_EVENT0("ServiceWorker",
+ "ServiceWorkerContextClient::DispatchInstallEvent");
+
+ int event_id = context_->install_event_callbacks.Add(
+ base::MakeUnique<DispatchInstallEventCallback>(std::move(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,
DispatchExtendableMessageEventCallback callback) {
@@ -1318,12 +1362,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