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

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

Issue 2763453002: [ServiceWorker] Convert ping-pong IPC into mojo interface ServiceWorkerEventDispatcher (Closed)
Patch Set: Created 3 years, 9 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 base::TimeDelta::FromSeconds(kPingTimeoutSeconds)) { 235 base::TimeDelta::FromSeconds(kPingTimeoutSeconds)) {
236 ping_state_ = PING_TIMED_OUT; 236 ping_state_ = PING_TIMED_OUT;
237 version_->OnPingTimeout(); 237 version_->OnPingTimeout();
238 return; 238 return;
239 } 239 }
240 240
241 // Check if we want to send a next ping. 241 // Check if we want to send a next ping.
242 if (ping_state_ != PINGING || !ping_time_.is_null()) 242 if (ping_state_ != PINGING || !ping_time_.is_null())
243 return; 243 return;
244 244
245 if (version_->PingWorker() != SERVICE_WORKER_OK) { 245 version_->PingWorker();
246 // TODO(falken): Maybe try resending Ping a few times first?
247 ping_state_ = PING_TIMED_OUT;
248 version_->OnPingTimeout();
249 return;
250 }
251 version_->RestartTick(&ping_time_); 246 version_->RestartTick(&ping_time_);
252 } 247 }
253 248
254 void SimulateTimeoutForTesting() { 249 void SimulateTimeoutForTesting() {
255 version_->PingWorker(); 250 version_->PingWorker();
256 ping_state_ = PING_TIMED_OUT; 251 ping_state_ = PING_TIMED_OUT;
257 version_->OnPingTimeout(); 252 version_->OnPingTimeout();
258 } 253 }
259 254
260 private: 255 private:
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 OnClearCachedMetadata) 956 OnClearCachedMetadata)
962 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, 957 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient,
963 OnPostMessageToClient) 958 OnPostMessageToClient)
964 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, 959 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient,
965 OnFocusClient) 960 OnFocusClient)
966 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NavigateClient, OnNavigateClient) 961 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NavigateClient, OnNavigateClient)
967 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting, 962 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting,
968 OnSkipWaiting) 963 OnSkipWaiting)
969 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, 964 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients,
970 OnClaimClients) 965 OnClaimClients)
971 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_Pong, OnPongFromWorker)
972 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterForeignFetchScopes, 966 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterForeignFetchScopes,
973 OnRegisterForeignFetchScopes) 967 OnRegisterForeignFetchScopes)
974 IPC_MESSAGE_UNHANDLED(handled = false) 968 IPC_MESSAGE_UNHANDLED(handled = false)
975 IPC_END_MESSAGE_MAP() 969 IPC_END_MESSAGE_MAP()
976 return handled; 970 return handled;
977 } 971 }
978 972
979 void ServiceWorkerVersion::OnStartSentAndScriptEvaluated( 973 void ServiceWorkerVersion::OnStartSentAndScriptEvaluated(
980 ServiceWorkerStatusCode status) { 974 ServiceWorkerStatusCode status) {
981 if (status != SERVICE_WORKER_OK) { 975 if (status != SERVICE_WORKER_OK) {
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 if (GetTickDuration(idle_time_) > 1645 if (GetTickDuration(idle_time_) >
1652 base::TimeDelta::FromSeconds(kIdleWorkerTimeoutSeconds)) { 1646 base::TimeDelta::FromSeconds(kIdleWorkerTimeoutSeconds)) {
1653 StopWorkerIfIdle(); 1647 StopWorkerIfIdle();
1654 return; 1648 return;
1655 } 1649 }
1656 1650
1657 // Check ping status. 1651 // Check ping status.
1658 ping_controller_->CheckPingStatus(); 1652 ping_controller_->CheckPingStatus();
1659 } 1653 }
1660 1654
1661 ServiceWorkerStatusCode ServiceWorkerVersion::PingWorker() { 1655 void ServiceWorkerVersion::PingWorker() {
1662 DCHECK(running_status() == EmbeddedWorkerStatus::STARTING || 1656 DCHECK(running_status() == EmbeddedWorkerStatus::STARTING ||
1663 running_status() == EmbeddedWorkerStatus::RUNNING); 1657 running_status() == EmbeddedWorkerStatus::RUNNING);
1664 return embedded_worker_->SendMessage(ServiceWorkerMsg_Ping()); 1658 // base::Unretained here is safe because event_dispatcher is owned by |this|.
1659 event_dispatcher()->Ping(base::Bind(&ServiceWorkerVersion::OnPongFromWorker,
leonhsl(Using Gerrit) 2017/03/20 03:47:15 I can confirm that |event_dispatcher_| here should
falken 2017/03/21 06:54:04 Yes I wasn't entirely sure myself. Sender::Send()
1660 base::Unretained(this)));
1665 } 1661 }
1666 1662
1667 void ServiceWorkerVersion::OnPingTimeout() { 1663 void ServiceWorkerVersion::OnPingTimeout() {
1668 DCHECK(running_status() == EmbeddedWorkerStatus::STARTING || 1664 DCHECK(running_status() == EmbeddedWorkerStatus::STARTING ||
1669 running_status() == EmbeddedWorkerStatus::RUNNING); 1665 running_status() == EmbeddedWorkerStatus::RUNNING);
1670 // TODO(falken): Change the error code to SERVICE_WORKER_ERROR_TIMEOUT. 1666 // TODO(falken): Change the error code to SERVICE_WORKER_ERROR_TIMEOUT.
1671 embedded_worker_->AddMessageToConsole(blink::WebConsoleMessage::LevelVerbose, 1667 embedded_worker_->AddMessageToConsole(blink::WebConsoleMessage::LevelVerbose,
1672 kNotRespondingErrorMesage); 1668 kNotRespondingErrorMesage);
1673 StopWorkerIfIdle(); 1669 StopWorkerIfIdle();
1674 } 1670 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 1896
1901 void ServiceWorkerVersion::CleanUpExternalRequest( 1897 void ServiceWorkerVersion::CleanUpExternalRequest(
1902 const std::string& request_uuid, 1898 const std::string& request_uuid,
1903 ServiceWorkerStatusCode status) { 1899 ServiceWorkerStatusCode status) {
1904 if (status == SERVICE_WORKER_OK) 1900 if (status == SERVICE_WORKER_OK)
1905 return; 1901 return;
1906 external_request_uuid_to_request_id_.erase(request_uuid); 1902 external_request_uuid_to_request_id_.erase(request_uuid);
1907 } 1903 }
1908 1904
1909 } // namespace content 1905 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698