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

Side by Side Diff: content/browser/service_worker/service_worker_version.cc

Issue 1171173002: [Background Sync] Use Mojo IPC to fire background sync events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove Chromium IPC for Sync from unit tests' Created 5 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/service_worker/service_worker_version.h" 5 #include "content/browser/service_worker/service_worker_version.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "content/browser/bad_message.h" 17 #include "content/browser/bad_message.h"
18 #include "content/browser/child_process_security_policy_impl.h" 18 #include "content/browser/child_process_security_policy_impl.h"
19 #include "content/browser/message_port_message_filter.h" 19 #include "content/browser/message_port_message_filter.h"
20 #include "content/browser/message_port_service.h" 20 #include "content/browser/message_port_service.h"
21 #include "content/browser/service_worker/embedded_worker_instance.h" 21 #include "content/browser/service_worker/embedded_worker_instance.h"
22 #include "content/browser/service_worker/embedded_worker_registry.h" 22 #include "content/browser/service_worker/embedded_worker_registry.h"
23 #include "content/browser/service_worker/service_worker_context_core.h" 23 #include "content/browser/service_worker/service_worker_context_core.h"
24 #include "content/browser/service_worker/service_worker_context_wrapper.h" 24 #include "content/browser/service_worker/service_worker_context_wrapper.h"
25 #include "content/browser/service_worker/service_worker_metrics.h" 25 #include "content/browser/service_worker/service_worker_metrics.h"
26 #include "content/browser/service_worker/service_worker_mojo_event_dispatcher.h"
26 #include "content/browser/service_worker/service_worker_registration.h" 27 #include "content/browser/service_worker/service_worker_registration.h"
27 #include "content/browser/service_worker/service_worker_utils.h" 28 #include "content/browser/service_worker/service_worker_utils.h"
28 #include "content/browser/service_worker/stashed_port_manager.h" 29 #include "content/browser/service_worker/stashed_port_manager.h"
29 #include "content/browser/storage_partition_impl.h" 30 #include "content/browser/storage_partition_impl.h"
30 #include "content/common/service_worker/service_worker_messages.h" 31 #include "content/common/service_worker/service_worker_messages.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/content_browser_client.h" 33 #include "content/public/browser/content_browser_client.h"
33 #include "content/public/browser/page_navigator.h" 34 #include "content/public/browser/page_navigator.h"
34 #include "content/public/browser/render_frame_host.h" 35 #include "content/public/browser/render_frame_host.h"
35 #include "content/public/browser/render_process_host.h" 36 #include "content/public/browser/render_process_host.h"
36 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
37 #include "content/public/browser/web_contents_observer.h" 38 #include "content/public/browser/web_contents_observer.h"
38 #include "content/public/common/child_process_host.h" 39 #include "content/public/common/child_process_host.h"
39 #include "content/public/common/content_client.h" 40 #include "content/public/common/content_client.h"
40 #include "content/public/common/content_switches.h" 41 #include "content/public/common/content_switches.h"
41 #include "content/public/common/result_codes.h" 42 #include "content/public/common/result_codes.h"
43 #include "content/public/common/service_registry.h"
42 #include "net/http/http_response_headers.h" 44 #include "net/http/http_response_headers.h"
43 #include "net/http/http_response_info.h" 45 #include "net/http/http_response_info.h"
44 46
45 namespace content { 47 namespace content {
46 48
47 using StatusCallback = ServiceWorkerVersion::StatusCallback; 49 using StatusCallback = ServiceWorkerVersion::StatusCallback;
48 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; 50 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>;
49 using GetClientsCallback = 51 using GetClientsCallback =
50 base::Callback<void(scoped_ptr<ServiceWorkerClients>)>; 52 base::Callback<void(scoped_ptr<ServiceWorkerClients>)>;
51 53
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 // Schedule calling this method after starting the worker. 791 // Schedule calling this method after starting the worker.
790 StartWorker(base::Bind(&RunTaskAfterStartWorker, 792 StartWorker(base::Bind(&RunTaskAfterStartWorker,
791 weak_factory_.GetWeakPtr(), callback, 793 weak_factory_.GetWeakPtr(), callback,
792 base::Bind(&self::DispatchSyncEvent, 794 base::Bind(&self::DispatchSyncEvent,
793 weak_factory_.GetWeakPtr(), 795 weak_factory_.GetWeakPtr(),
794 callback))); 796 callback)));
795 return; 797 return;
796 } 798 }
797 799
798 int request_id = AddRequest(callback, &sync_callbacks_, REQUEST_SYNC); 800 int request_id = AddRequest(callback, &sync_callbacks_, REQUEST_SYNC);
799 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( 801 ServiceWorkerMojoEventDispatcher* mojo_event_dispatcher =
800 ServiceWorkerMsg_SyncEvent(request_id)); 802 context_->GetMojoEventDispatcher(embedded_worker_->process_id());
801 if (status != SERVICE_WORKER_OK) { 803 DCHECK(mojo_event_dispatcher);
802 sync_callbacks_.Remove(request_id); 804 mojo_event_dispatcher->DispatchSyncEvent(
803 RunSoon(base::Bind(callback, status)); 805 embedded_worker_->thread_id(),
804 } 806 base::Bind(&self::OnSyncEventFinished, weak_factory_.GetWeakPtr(),
807 request_id));
805 } 808 }
806 809
807 void ServiceWorkerVersion::DispatchNotificationClickEvent( 810 void ServiceWorkerVersion::DispatchNotificationClickEvent(
808 const StatusCallback& callback, 811 const StatusCallback& callback,
809 int64_t persistent_notification_id, 812 int64_t persistent_notification_id,
810 const PlatformNotificationData& notification_data) { 813 const PlatformNotificationData& notification_data) {
811 DCHECK_EQ(ACTIVATED, status()) << status(); 814 DCHECK_EQ(ACTIVATED, status()) << status();
812 if (running_status() != RUNNING) { 815 if (running_status() != RUNNING) {
813 // Schedule calling this method after starting the worker. 816 // Schedule calling this method after starting the worker.
814 StartWorker(base::Bind( 817 StartWorker(base::Bind(
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 bool handled = true; 1174 bool handled = true;
1172 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) 1175 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message)
1173 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, 1176 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients,
1174 OnGetClients) 1177 OnGetClients)
1175 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, 1178 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished,
1176 OnActivateEventFinished) 1179 OnActivateEventFinished)
1177 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, 1180 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished,
1178 OnInstallEventFinished) 1181 OnInstallEventFinished)
1179 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, 1182 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished,
1180 OnFetchEventFinished) 1183 OnFetchEventFinished)
1181 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished,
1182 OnSyncEventFinished)
1183 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, 1184 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished,
1184 OnNotificationClickEventFinished) 1185 OnNotificationClickEventFinished)
1185 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, 1186 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished,
1186 OnPushEventFinished) 1187 OnPushEventFinished)
1187 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, 1188 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished,
1188 OnGeofencingEventFinished) 1189 OnGeofencingEventFinished)
1189 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, 1190 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished,
1190 OnCrossOriginConnectEventFinished) 1191 OnCrossOriginConnectEventFinished)
1191 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, 1192 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow,
1192 OnOpenWindow) 1193 OnOpenWindow)
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 1345
1345 // TODO(kinuko): Record other event statuses too. 1346 // TODO(kinuko): Record other event statuses too.
1346 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); 1347 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE);
1347 metrics_->RecordEventStatus(handled); 1348 metrics_->RecordEventStatus(handled);
1348 1349
1349 scoped_refptr<ServiceWorkerVersion> protect(this); 1350 scoped_refptr<ServiceWorkerVersion> protect(this);
1350 callback->Run(SERVICE_WORKER_OK, result, response); 1351 callback->Run(SERVICE_WORKER_OK, result, response);
1351 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); 1352 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id);
1352 } 1353 }
1353 1354
1354 void ServiceWorkerVersion::OnSyncEventFinished( 1355 void ServiceWorkerVersion::OnSyncEventFinished(int request_id,
1355 int request_id, 1356 ServiceWorkerStatusCode status) {
1356 blink::WebServiceWorkerEventResult result) {
1357 TRACE_EVENT1("ServiceWorker", 1357 TRACE_EVENT1("ServiceWorker",
1358 "ServiceWorkerVersion::OnSyncEventFinished", 1358 "ServiceWorkerVersion::OnSyncEventFinished",
1359 "Request id", request_id); 1359 "Request id", request_id);
1360 StatusCallback* callback = sync_callbacks_.Lookup(request_id); 1360 StatusCallback* callback = sync_callbacks_.Lookup(request_id);
1361 if (!callback) { 1361 if (!callback) {
1362 NOTREACHED() << "Got unexpected message: " << request_id; 1362 NOTREACHED() << "Got unexpected message: " << request_id;
1363 return; 1363 return;
1364 } 1364 }
1365 1365
1366 ServiceWorkerStatusCode status = SERVICE_WORKER_OK;
1367 if (result == blink::WebServiceWorkerEventResultRejected) {
1368 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED;
1369 }
1370
1371 scoped_refptr<ServiceWorkerVersion> protect(this); 1366 scoped_refptr<ServiceWorkerVersion> protect(this);
1372 callback->Run(status); 1367 callback->Run(status);
1373 RemoveCallbackAndStopIfRedundant(&sync_callbacks_, request_id); 1368 RemoveCallbackAndStopIfRedundant(&sync_callbacks_, request_id);
1374 } 1369 }
1375 1370
1376 void ServiceWorkerVersion::OnNotificationClickEventFinished( 1371 void ServiceWorkerVersion::OnNotificationClickEventFinished(
1377 int request_id) { 1372 int request_id) {
1378 TRACE_EVENT1("ServiceWorker", 1373 TRACE_EVENT1("ServiceWorker",
1379 "ServiceWorkerVersion::OnNotificationClickEventFinished", 1374 "ServiceWorkerVersion::OnNotificationClickEventFinished",
1380 "Request id", request_id); 1375 "Request id", request_id);
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 2153
2159 streaming_url_request_jobs_.clear(); 2154 streaming_url_request_jobs_.clear();
2160 2155
2161 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); 2156 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
2162 2157
2163 if (should_restart) 2158 if (should_restart)
2164 StartWorkerInternal(false /* pause_after_download */); 2159 StartWorkerInternal(false /* pause_after_download */);
2165 } 2160 }
2166 2161
2167 } // namespace content 2162 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | content/common/background_sync_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698