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..dd6dba3b2dc35d25d856307456c444dfc5053d7d 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; |
@@ -563,7 +568,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 +729,18 @@ void ServiceWorkerContextClient::WillDestroyWorkerContext( |
// (while we're still on the worker thread). |
proxy_ = NULL; |
- // Aborts all the pending events callbacks. |
+ // Clear all install event methods. |
+ install_methods_map_.clear(); |
+ |
+ // 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 +910,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); |
+ install_methods_map_.erase(request_id); |
} |
void ServiceWorkerContextClient::RespondToFetchEventWithNoResponse( |
@@ -1119,11 +1138,18 @@ void ServiceWorkerContextClient::Claim( |
} |
void ServiceWorkerContextClient::RegisterForeignFetchScopes( |
+ const int event_id, |
leonhsl(Using Gerrit)
2017/04/23 03:33:10
No need to use 'const'.
xiaofengzhang
2017/04/24 05:02:41
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()))); |
+ std::vector<GURL> urls; |
+ for (const auto& url : sub_scopes) |
+ urls.push_back(url); |
+ |
+ std::vector<url::Origin> url_origins; |
+ for (const auto& origin : origins) |
+ url_origins.push_back(origin); |
+ |
+ install_methods_map_[event_id]->RegisterForeignFetchScopes(urls, url_origins); |
leonhsl(Using Gerrit)
2017/04/23 03:33:10
Need to DCHECK that install_methods_map_[event_id]
xiaofengzhang
2017/04/24 05:02:41
Done.
|
} |
void ServiceWorkerContextClient::DispatchSyncEvent( |
@@ -1271,6 +1297,24 @@ 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 request_id = context_->install_event_callbacks.Add( |
leonhsl(Using Gerrit)
2017/04/23 03:33:10
Better to uniform the naming as 'event_id' with Li
xiaofengzhang
2017/04/24 05:02:41
Done.
|
+ base::MakeUnique<DispatchInstallEventCallback>(callback)); |
+ |
+ auto it = install_methods_map_.find(request_id); |
shimazu
2017/04/24 05:00:13
DCHECK(install_methods_map_.find(request_id) == in
|
+ DCHECK(it == install_methods_map_.end()); |
+ mojom::ServiceWorkerInstallEventMethodsAssociatedPtr install_method_client_; |
leonhsl(Using Gerrit)
2017/04/23 03:33:10
install_method_client_ --> install_methods ?
xiaofengzhang
2017/04/24 05:02:41
Done.
|
+ install_method_client_.Bind(std::move(client)); |
+ install_methods_map_[request_id] = std::move(install_method_client_); |
+ |
+ proxy_->DispatchInstallEvent(request_id); |
+} |
+ |
void ServiceWorkerContextClient::DispatchExtendableMessageEvent( |
mojom::ExtendableMessageEventPtr event, |
const DispatchExtendableMessageEventCallback& callback) { |
@@ -1306,12 +1350,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, |