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

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

Issue 1264333002: First step to refactor ServiceWorkerVersion to make event dispatching more modular. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years 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 <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 const std::vector<TransferredMessagePort>& sent_message_ports, 152 const std::vector<TransferredMessagePort>& sent_message_ports,
153 const ServiceWorkerVersion::StatusCallback& callback, 153 const ServiceWorkerVersion::StatusCallback& callback,
154 ServiceWorkerStatusCode status) { 154 ServiceWorkerStatusCode status) {
155 // Transfering the message ports failed, so destroy the ports. 155 // Transfering the message ports failed, so destroy the ports.
156 for (const TransferredMessagePort& port : sent_message_ports) { 156 for (const TransferredMessagePort& port : sent_message_ports) {
157 MessagePortService::GetInstance()->ClosePort(port.id); 157 MessagePortService::GetInstance()->ClosePort(port.id);
158 } 158 }
159 callback.Run(status); 159 callback.Run(status);
160 } 160 }
161 161
162 void RunErrorServicePortConnectCallback(
163 const ServiceWorkerVersion::ServicePortConnectCallback& callback,
164 ServiceWorkerStatusCode status) {
165 callback.Run(status, false /* accept_connection */, base::string16(),
166 base::string16());
167 }
168
169 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) { 162 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) {
170 DCHECK_CURRENTLY_ON(BrowserThread::UI); 163 DCHECK_CURRENTLY_ON(BrowserThread::UI);
171 RenderProcessHost* render_process_host = 164 RenderProcessHost* render_process_host =
172 RenderProcessHost::FromID(process_id); 165 RenderProcessHost::FromID(process_id);
173 if (render_process_host->GetHandle() != base::kNullProcessHandle) { 166 if (render_process_host->GetHandle() != base::kNullProcessHandle) {
174 bad_message::ReceivedBadMessage(render_process_host, 167 bad_message::ReceivedBadMessage(render_process_host,
175 bad_message::SERVICE_WORKER_BAD_URL); 168 bad_message::SERVICE_WORKER_BAD_URL);
176 } 169 }
177 } 170 }
178 171
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 registration_id_, scope_.GetOrigin(), 535 registration_id_, scope_.GetOrigin(),
543 base::Bind(&ServiceWorkerVersion::FoundRegistrationForUpdate, 536 base::Bind(&ServiceWorkerVersion::FoundRegistrationForUpdate,
544 weak_factory_.GetWeakPtr())); 537 weak_factory_.GetWeakPtr()));
545 } 538 }
546 539
547 void ServiceWorkerVersion::DeferScheduledUpdate() { 540 void ServiceWorkerVersion::DeferScheduledUpdate() {
548 if (update_timer_.IsRunning()) 541 if (update_timer_.IsRunning())
549 update_timer_.Reset(); 542 update_timer_.Reset();
550 } 543 }
551 544
545 int ServiceWorkerVersion::StartRequest(const StatusCallback& error_callback) {
546 OnBeginEvent();
547 DCHECK_EQ(RUNNING, running_status())
548 << "Can only start a request with a running worker.";
549 return AddRequest(error_callback, &custom_requests_, REQUEST_CUSTOM);
550 }
551
552 bool ServiceWorkerVersion::FinishRequest(int request_id) {
553 PendingRequest<StatusCallback>* request = custom_requests_.Lookup(request_id);
554 if (!request)
555 return false;
556 RemoveCallbackAndStopIfRedundant(&custom_requests_, request_id);
557 return true;
558 }
559
560 void ServiceWorkerVersion::RunAfterStartWorker(
561 const StatusCallback& error_callback,
562 const base::Closure& task) {
563 StartWorker(base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(),
564 error_callback, task));
565 }
566
552 void ServiceWorkerVersion::DispatchMessageEvent( 567 void ServiceWorkerVersion::DispatchMessageEvent(
553 const base::string16& message, 568 const base::string16& message,
554 const std::vector<TransferredMessagePort>& sent_message_ports, 569 const std::vector<TransferredMessagePort>& sent_message_ports,
555 const StatusCallback& callback) { 570 const StatusCallback& callback) {
556 for (const TransferredMessagePort& port : sent_message_ports) { 571 for (const TransferredMessagePort& port : sent_message_ports) {
557 MessagePortService::GetInstance()->HoldMessages(port.id); 572 MessagePortService::GetInstance()->HoldMessages(port.id);
558 } 573 }
559 574
560 DispatchMessageEventInternal(message, sent_message_ports, callback); 575 DispatchMessageEventInternal(message, sent_message_ports, callback);
561 } 576 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 AddRequest(callback, &geofencing_requests_, REQUEST_GEOFENCING); 794 AddRequest(callback, &geofencing_requests_, REQUEST_GEOFENCING);
780 ServiceWorkerStatusCode status = 795 ServiceWorkerStatusCode status =
781 embedded_worker_->SendMessage(ServiceWorkerMsg_GeofencingEvent( 796 embedded_worker_->SendMessage(ServiceWorkerMsg_GeofencingEvent(
782 request_id, event_type, region_id, region)); 797 request_id, event_type, region_id, region));
783 if (status != SERVICE_WORKER_OK) { 798 if (status != SERVICE_WORKER_OK) {
784 geofencing_requests_.Remove(request_id); 799 geofencing_requests_.Remove(request_id);
785 RunSoon(base::Bind(callback, status)); 800 RunSoon(base::Bind(callback, status));
786 } 801 }
787 } 802 }
788 803
789 void ServiceWorkerVersion::DispatchServicePortConnectEvent(
790 const ServicePortConnectCallback& callback,
791 const GURL& target_url,
792 const GURL& origin,
793 int port_id) {
794 OnBeginEvent();
795 DCHECK_EQ(ACTIVATED, status()) << status();
796
797 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
798 switches::kEnableExperimentalWebPlatformFeatures)) {
799 callback.Run(SERVICE_WORKER_ERROR_ABORT, false, base::string16(),
800 base::string16());
801 return;
802 }
803
804 if (running_status() != RUNNING) {
805 // Schedule calling this method after starting the worker.
806 StartWorker(
807 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(),
808 base::Bind(&RunErrorServicePortConnectCallback, callback),
809 base::Bind(&self::DispatchServicePortConnectEvent,
810 weak_factory_.GetWeakPtr(), callback, target_url,
811 origin, port_id)));
812 return;
813 }
814
815 int request_id = AddRequest(callback, &service_port_connect_requests_,
816 REQUEST_SERVICE_PORT_CONNECT);
817 if (!service_port_dispatcher_) {
818 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService(
819 mojo::GetProxy(&service_port_dispatcher_));
820 service_port_dispatcher_.set_connection_error_handler(base::Bind(
821 &ServiceWorkerVersion::OnServicePortDispatcherConnectionError,
822 weak_factory_.GetWeakPtr()));
823 }
824 service_port_dispatcher_->Connect(
825 mojo::String::From(target_url), mojo::String::From(origin), port_id,
826 base::Bind(&ServiceWorkerVersion::OnServicePortConnectEventFinished,
827 weak_factory_.GetWeakPtr(), request_id));
828 }
829
830 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( 804 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent(
831 const NavigatorConnectClient& client, 805 const NavigatorConnectClient& client,
832 const base::string16& message, 806 const base::string16& message,
833 const std::vector<TransferredMessagePort>& sent_message_ports, 807 const std::vector<TransferredMessagePort>& sent_message_ports,
834 const StatusCallback& callback) { 808 const StatusCallback& callback) {
835 OnBeginEvent(); 809 OnBeginEvent();
836 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to 810 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to
837 // have already put all the sent message ports on hold. So no need to do that 811 // have already put all the sent message ports on hold. So no need to do that
838 // here again. 812 // here again.
839 813
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 ServiceWorkerVersion::PendingRequest<CallbackType>::PendingRequest( 968 ServiceWorkerVersion::PendingRequest<CallbackType>::PendingRequest(
995 const CallbackType& callback, 969 const CallbackType& callback,
996 const base::TimeTicks& time) 970 const base::TimeTicks& time)
997 : callback(callback), start_time(time) { 971 : callback(callback), start_time(time) {
998 } 972 }
999 973
1000 template <typename CallbackType> 974 template <typename CallbackType>
1001 ServiceWorkerVersion::PendingRequest<CallbackType>::~PendingRequest() { 975 ServiceWorkerVersion::PendingRequest<CallbackType>::~PendingRequest() {
1002 } 976 }
1003 977
978 ServiceWorkerVersion::BaseMojoService::BaseMojoService(
979 ServiceWorkerVersion* worker,
980 const char* service_name)
981 : worker_(worker), service_name_(service_name) {}
982
983 ServiceWorkerVersion::BaseMojoService::~BaseMojoService() {
984 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer>::iterator iter(
985 &worker_->custom_requests_);
986 while (!iter.IsAtEnd()) {
987 PendingRequest<StatusCallback>* request = iter.GetCurrentValue();
988 if (request->mojo_service == service_name_) {
989 request->callback.Run(SERVICE_WORKER_ERROR_FAILED);
990 worker_->custom_requests_.Remove(iter.GetCurrentKey());
991 }
992 iter.Advance();
993 }
994 }
995
1004 void ServiceWorkerVersion::OnThreadStarted() { 996 void ServiceWorkerVersion::OnThreadStarted() {
1005 if (running_status() == STOPPING) 997 if (running_status() == STOPPING)
1006 return; 998 return;
1007 DCHECK_EQ(STARTING, running_status()); 999 DCHECK_EQ(STARTING, running_status());
1008 // Activate ping/pong now that JavaScript execution will start. 1000 // Activate ping/pong now that JavaScript execution will start.
1009 ping_controller_->Activate(); 1001 ping_controller_->Activate();
1010 } 1002 }
1011 1003
1012 void ServiceWorkerVersion::OnStarting() { 1004 void ServiceWorkerVersion::OnStarting() {
1013 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); 1005 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 if (!request) { 1361 if (!request) {
1370 NOTREACHED() << "Got unexpected message: " << request_id; 1362 NOTREACHED() << "Got unexpected message: " << request_id;
1371 return; 1363 return;
1372 } 1364 }
1373 1365
1374 scoped_refptr<ServiceWorkerVersion> protect(this); 1366 scoped_refptr<ServiceWorkerVersion> protect(this);
1375 request->callback.Run(SERVICE_WORKER_OK); 1367 request->callback.Run(SERVICE_WORKER_OK);
1376 RemoveCallbackAndStopIfRedundant(&geofencing_requests_, request_id); 1368 RemoveCallbackAndStopIfRedundant(&geofencing_requests_, request_id);
1377 } 1369 }
1378 1370
1379 void ServiceWorkerVersion::OnServicePortConnectEventFinished(
1380 int request_id,
1381 ServicePortConnectResult result,
1382 const mojo::String& name,
1383 const mojo::String& data) {
1384 TRACE_EVENT1("ServiceWorker",
1385 "ServiceWorkerVersion::OnServicePortConnectEventFinished",
1386 "Request id", request_id);
1387 PendingRequest<ServicePortConnectCallback>* request =
1388 service_port_connect_requests_.Lookup(request_id);
1389 if (!request) {
1390 NOTREACHED() << "Got unexpected message: " << request_id;
1391 return;
1392 }
1393
1394 scoped_refptr<ServiceWorkerVersion> protect(this);
1395 request->callback.Run(SERVICE_WORKER_OK,
1396 result == SERVICE_PORT_CONNECT_RESULT_ACCEPT,
1397 name.To<base::string16>(), data.To<base::string16>());
1398 RemoveCallbackAndStopIfRedundant(&service_port_connect_requests_, request_id);
1399 }
1400
1401 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) { 1371 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) {
1402 // Just abort if we are shutting down. 1372 // Just abort if we are shutting down.
1403 if (!context_) 1373 if (!context_)
1404 return; 1374 return;
1405 1375
1406 if (!url.is_valid()) { 1376 if (!url.is_valid()) {
1407 DVLOG(1) << "Received unexpected invalid URL from renderer process."; 1377 DVLOG(1) << "Received unexpected invalid URL from renderer process.";
1408 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1378 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1409 base::Bind(&KillEmbeddedWorkerProcess, 1379 base::Bind(&KillEmbeddedWorkerProcess,
1410 embedded_worker_->process_id(), 1380 embedded_worker_->process_id(),
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 context_->GetProviderHostByClientID(client_uuid); 1482 context_->GetProviderHostByClientID(client_uuid);
1513 if (!provider_host) { 1483 if (!provider_host) {
1514 // The client may already have been closed, just ignore. 1484 // The client may already have been closed, just ignore.
1515 return; 1485 return;
1516 } 1486 }
1517 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) { 1487 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) {
1518 // The client does not belong to the same origin as this ServiceWorker, 1488 // The client does not belong to the same origin as this ServiceWorker,
1519 // possibly due to timing issue or bad message. 1489 // possibly due to timing issue or bad message.
1520 return; 1490 return;
1521 } 1491 }
1522 provider_host->PostMessage(this, message, sent_message_ports); 1492 provider_host->PostMessageToClient(this, message, sent_message_ports);
1523 } 1493 }
1524 1494
1525 void ServiceWorkerVersion::OnFocusClient(int request_id, 1495 void ServiceWorkerVersion::OnFocusClient(int request_id,
1526 const std::string& client_uuid) { 1496 const std::string& client_uuid) {
1527 if (!context_) 1497 if (!context_)
1528 return; 1498 return;
1529 TRACE_EVENT2("ServiceWorker", 1499 TRACE_EVENT2("ServiceWorker",
1530 "ServiceWorkerVersion::OnFocusClient", 1500 "ServiceWorkerVersion::OnFocusClient",
1531 "Request id", request_id, 1501 "Request id", request_id,
1532 "Client id", client_uuid); 1502 "Client id", client_uuid);
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 return; 1955 return;
1986 } 1956 }
1987 1957
1988 embedded_worker_->StopIfIdle(); 1958 embedded_worker_->StopIfIdle();
1989 } 1959 }
1990 1960
1991 bool ServiceWorkerVersion::HasInflightRequests() const { 1961 bool ServiceWorkerVersion::HasInflightRequests() const {
1992 return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() || 1962 return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() ||
1993 !fetch_requests_.IsEmpty() || !sync_requests_.IsEmpty() || 1963 !fetch_requests_.IsEmpty() || !sync_requests_.IsEmpty() ||
1994 !notification_click_requests_.IsEmpty() || !push_requests_.IsEmpty() || 1964 !notification_click_requests_.IsEmpty() || !push_requests_.IsEmpty() ||
1995 !geofencing_requests_.IsEmpty() || 1965 !geofencing_requests_.IsEmpty() || !custom_requests_.IsEmpty() ||
1996 !service_port_connect_requests_.IsEmpty() ||
1997 !streaming_url_request_jobs_.empty(); 1966 !streaming_url_request_jobs_.empty();
1998 } 1967 }
1999 1968
2000 void ServiceWorkerVersion::RecordStartWorkerResult( 1969 void ServiceWorkerVersion::RecordStartWorkerResult(
2001 ServiceWorkerStatusCode status) { 1970 ServiceWorkerStatusCode status) {
2002 base::TimeTicks start_time = start_time_; 1971 base::TimeTicks start_time = start_time_;
2003 ClearTick(&start_time_); 1972 ClearTick(&start_time_);
2004 1973
2005 ServiceWorkerMetrics::RecordStartWorkerStatus(status, 1974 ServiceWorkerMetrics::RecordStartWorkerStatus(status,
2006 IsInstalled(prestart_status_)); 1975 IsInstalled(prestart_status_));
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 SERVICE_WORKER_ERROR_TIMEOUT); 2058 SERVICE_WORKER_ERROR_TIMEOUT);
2090 case REQUEST_NOTIFICATION_CLICK: 2059 case REQUEST_NOTIFICATION_CLICK:
2091 return RunIDMapCallback(&notification_click_requests_, info.id, 2060 return RunIDMapCallback(&notification_click_requests_, info.id,
2092 SERVICE_WORKER_ERROR_TIMEOUT); 2061 SERVICE_WORKER_ERROR_TIMEOUT);
2093 case REQUEST_PUSH: 2062 case REQUEST_PUSH:
2094 return RunIDMapCallback(&push_requests_, info.id, 2063 return RunIDMapCallback(&push_requests_, info.id,
2095 SERVICE_WORKER_ERROR_TIMEOUT); 2064 SERVICE_WORKER_ERROR_TIMEOUT);
2096 case REQUEST_GEOFENCING: 2065 case REQUEST_GEOFENCING:
2097 return RunIDMapCallback(&geofencing_requests_, info.id, 2066 return RunIDMapCallback(&geofencing_requests_, info.id,
2098 SERVICE_WORKER_ERROR_TIMEOUT); 2067 SERVICE_WORKER_ERROR_TIMEOUT);
2099 case REQUEST_SERVICE_PORT_CONNECT: 2068 case REQUEST_CUSTOM:
2100 return RunIDMapCallback(&service_port_connect_requests_, info.id, 2069 return RunIDMapCallback(&custom_requests_, info.id,
2101 SERVICE_WORKER_ERROR_TIMEOUT, 2070 SERVICE_WORKER_ERROR_TIMEOUT);
2102 false /* accept_connection */, base::string16(),
2103 base::string16());
2104 case NUM_REQUEST_TYPES: 2071 case NUM_REQUEST_TYPES:
2105 break; 2072 break;
2106 } 2073 }
2107 NOTREACHED() << "Got unexpected request type: " << info.type; 2074 NOTREACHED() << "Got unexpected request type: " << info.type;
2108 return false; 2075 return false;
2109 } 2076 }
2110 2077
2111 bool ServiceWorkerVersion::ShouldStopIfRequestTimesOut( 2078 bool ServiceWorkerVersion::ShouldStopIfRequestTimesOut(
2112 const RequestInfo& info) { 2079 const RequestInfo& info) {
2113 // Note, returning false for a type means that the On*EventFinished should not 2080 // Note, returning false for a type means that the On*EventFinished should not
2114 // call NOTREACHED if it can't find the matching request, it may have simply 2081 // call NOTREACHED if it can't find the matching request, it may have simply
2115 // timed out. 2082 // timed out.
2116 switch (info.type) { 2083 switch (info.type) {
2117 case REQUEST_SYNC: 2084 case REQUEST_SYNC:
2118 return false; 2085 return false;
2119 case REQUEST_ACTIVATE: 2086 case REQUEST_ACTIVATE:
2120 case REQUEST_INSTALL: 2087 case REQUEST_INSTALL:
2121 case REQUEST_FETCH: 2088 case REQUEST_FETCH:
2122 case REQUEST_NOTIFICATION_CLICK: 2089 case REQUEST_NOTIFICATION_CLICK:
2123 case REQUEST_PUSH: 2090 case REQUEST_PUSH:
2124 case REQUEST_GEOFENCING: 2091 case REQUEST_GEOFENCING:
2125 case REQUEST_SERVICE_PORT_CONNECT: 2092 return true;
2093 case REQUEST_CUSTOM:
2094 // TODO(mek): Custom requests need some way to specify their timeout
2095 // behavior.
2126 return true; 2096 return true;
2127 case NUM_REQUEST_TYPES: 2097 case NUM_REQUEST_TYPES:
2128 NOTREACHED() << "Got unexpected request type: " << info.type; 2098 NOTREACHED() << "Got unexpected request type: " << info.type;
2129 } 2099 }
2130 NOTREACHED() << "Got unexpected request type: " << info.type; 2100 NOTREACHED() << "Got unexpected request type: " << info.type;
2131 return false; 2101 return false;
2132 } 2102 }
2133 2103
2134 void ServiceWorkerVersion::SetAllRequestExpirations( 2104 void ServiceWorkerVersion::SetAllRequestExpirations(
2135 const base::TimeTicks& expiration) { 2105 const base::TimeTicks& expiration) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); 2206 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED);
2237 RunIDMapCallbacks(&install_requests_, 2207 RunIDMapCallbacks(&install_requests_,
2238 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); 2208 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED);
2239 RunIDMapCallbacks(&fetch_requests_, SERVICE_WORKER_ERROR_FAILED, 2209 RunIDMapCallbacks(&fetch_requests_, SERVICE_WORKER_ERROR_FAILED,
2240 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, 2210 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK,
2241 ServiceWorkerResponse()); 2211 ServiceWorkerResponse());
2242 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED); 2212 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED);
2243 RunIDMapCallbacks(&notification_click_requests_, SERVICE_WORKER_ERROR_FAILED); 2213 RunIDMapCallbacks(&notification_click_requests_, SERVICE_WORKER_ERROR_FAILED);
2244 RunIDMapCallbacks(&push_requests_, SERVICE_WORKER_ERROR_FAILED); 2214 RunIDMapCallbacks(&push_requests_, SERVICE_WORKER_ERROR_FAILED);
2245 RunIDMapCallbacks(&geofencing_requests_, SERVICE_WORKER_ERROR_FAILED); 2215 RunIDMapCallbacks(&geofencing_requests_, SERVICE_WORKER_ERROR_FAILED);
2216 RunIDMapCallbacks(&custom_requests_, SERVICE_WORKER_ERROR_FAILED);
2246 2217
2247 // Close all mojo services. This will also fire and clear all callbacks 2218 // Close all mojo services. This will also fire and clear all callbacks
2248 // for messages that are still outstanding for those services. 2219 // for messages that are still outstanding for those services.
2249 OnServicePortDispatcherConnectionError(); 2220 mojo_services_.clear();
2250
2251 OnBackgroundSyncDispatcherConnectionError(); 2221 OnBackgroundSyncDispatcherConnectionError();
2252 2222
2253 // TODO(falken): Call SWURLRequestJob::ClearStream here? 2223 // TODO(falken): Call SWURLRequestJob::ClearStream here?
2254 streaming_url_request_jobs_.clear(); 2224 streaming_url_request_jobs_.clear();
2255 2225
2256 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); 2226 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
2257 2227
2258 if (should_restart) 2228 if (should_restart)
2259 StartWorkerInternal(); 2229 StartWorkerInternal();
2260 } 2230 }
2261 2231
2262 void ServiceWorkerVersion::OnServicePortDispatcherConnectionError() {
2263 RunIDMapCallbacks(&service_port_connect_requests_,
2264 SERVICE_WORKER_ERROR_FAILED, false, base::string16(),
2265 base::string16());
2266 service_port_dispatcher_.reset();
2267 }
2268
2269 void ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError() { 2232 void ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError() {
2270 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED); 2233 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED);
2271 background_sync_dispatcher_.reset(); 2234 background_sync_dispatcher_.reset();
2272 } 2235 }
2273 2236
2237 void ServiceWorkerVersion::OnMojoConnectionError(const char* service_name) {
2238 // Simply deleting the service will cause error callbacks to be called from
2239 // the destructor of the MojoService instance.
2240 mojo_services_.erase(service_name);
2241 }
2242
2274 void ServiceWorkerVersion::OnBeginEvent() { 2243 void ServiceWorkerVersion::OnBeginEvent() {
2275 if (should_exclude_from_uma_ || running_status() != RUNNING || 2244 if (should_exclude_from_uma_ || running_status() != RUNNING ||
2276 idle_time_.is_null()) { 2245 idle_time_.is_null()) {
2277 return; 2246 return;
2278 } 2247 }
2279 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - 2248 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() -
2280 idle_time_); 2249 idle_time_);
2281 } 2250 }
2282 2251
2283 } // namespace content 2252 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698