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

Side by Side Diff: content/renderer/service_worker/service_worker_script_context.cc

Issue 205033002: Browser side of new ServiceWorker 'sync' event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Kinuko comments Created 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/service_worker/service_worker_script_context.h" 5 #include "content/renderer/service_worker/service_worker_script_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/child/webmessageportchannel_impl.h" 8 #include "content/child/webmessageportchannel_impl.h"
9 #include "content/common/service_worker/service_worker_messages.h" 9 #include "content/common/service_worker/service_worker_messages.h"
10 #include "content/renderer/service_worker/embedded_worker_context_client.h" 10 #include "content/renderer/service_worker/embedded_worker_context_client.h"
(...skipping 15 matching lines...) Expand all
26 void ServiceWorkerScriptContext::OnMessageReceived( 26 void ServiceWorkerScriptContext::OnMessageReceived(
27 int request_id, 27 int request_id,
28 const IPC::Message& message) { 28 const IPC::Message& message) {
29 DCHECK_EQ(kInvalidServiceWorkerRequestId, current_request_id_); 29 DCHECK_EQ(kInvalidServiceWorkerRequestId, current_request_id_);
30 current_request_id_ = request_id; 30 current_request_id_ = request_id;
31 bool handled = true; 31 bool handled = true;
32 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) 32 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message)
33 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) 33 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
34 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) 34 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent)
35 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Message, OnPostMessage) 35 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Message, OnPostMessage)
36 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent, OnSyncEvent)
36 IPC_MESSAGE_UNHANDLED(handled = false) 37 IPC_MESSAGE_UNHANDLED(handled = false)
37 IPC_END_MESSAGE_MAP() 38 IPC_END_MESSAGE_MAP()
38 DCHECK(handled); 39 DCHECK(handled);
39 current_request_id_ = kInvalidServiceWorkerRequestId; 40 current_request_id_ = kInvalidServiceWorkerRequestId;
40 } 41 }
41 42
42 void ServiceWorkerScriptContext::DidHandleInstallEvent( 43 void ServiceWorkerScriptContext::DidHandleInstallEvent(
43 int request_id, 44 int request_id,
44 blink::WebServiceWorkerEventResult result) { 45 blink::WebServiceWorkerEventResult result) {
45 Send(request_id, ServiceWorkerHostMsg_InstallEventFinished(result)); 46 Send(request_id, ServiceWorkerHostMsg_InstallEventFinished(result));
46 } 47 }
47 48
48 void ServiceWorkerScriptContext::DidHandleFetchEvent( 49 void ServiceWorkerScriptContext::DidHandleFetchEvent(
49 int request_id, 50 int request_id,
50 ServiceWorkerFetchEventResult result, 51 ServiceWorkerFetchEventResult result,
51 const ServiceWorkerResponse& response) { 52 const ServiceWorkerResponse& response) {
52 Send(request_id, ServiceWorkerHostMsg_FetchEventFinished(result, response)); 53 Send(request_id, ServiceWorkerHostMsg_FetchEventFinished(result, response));
53 } 54 }
54 55
56 void ServiceWorkerScriptContext::DidHandleSyncEvent(int request_id) {
57 Send(request_id, ServiceWorkerHostMsg_SyncEventFinished());
58 }
59
55 void ServiceWorkerScriptContext::Send(int request_id, 60 void ServiceWorkerScriptContext::Send(int request_id,
56 const IPC::Message& message) { 61 const IPC::Message& message) {
57 embedded_context_->SendMessageToBrowser(request_id, message); 62 embedded_context_->SendMessageToBrowser(request_id, message);
58 } 63 }
59 64
60 void ServiceWorkerScriptContext::OnInstallEvent(int active_version_id) { 65 void ServiceWorkerScriptContext::OnInstallEvent(int active_version_id) {
61 proxy_->dispatchInstallEvent(current_request_id_); 66 proxy_->dispatchInstallEvent(current_request_id_);
62 } 67 }
63 68
64 void ServiceWorkerScriptContext::OnFetchEvent( 69 void ServiceWorkerScriptContext::OnFetchEvent(
(...skipping 12 matching lines...) Expand all
77 ports.resize(sent_message_port_ids.size()); 82 ports.resize(sent_message_port_ids.size());
78 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { 83 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
79 ports[i] = new WebMessagePortChannelImpl( 84 ports[i] = new WebMessagePortChannelImpl(
80 new_routing_ids[i], sent_message_port_ids[i], loop_proxy); 85 new_routing_ids[i], sent_message_port_ids[i], loop_proxy);
81 } 86 }
82 } 87 }
83 88
84 proxy_->dispatchMessageEvent(message, ports); 89 proxy_->dispatchMessageEvent(message, ports);
85 } 90 }
86 91
92 void ServiceWorkerScriptContext::OnSyncEvent() {
93 proxy_->dispatchSyncEvent(current_request_id_);
94 }
95
87 } // namespace content 96 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/service_worker/service_worker_script_context.h ('k') | content/test/data/service_worker/sync.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698