| OLD | NEW |
| 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 <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 296 |
| 297 ServiceWorkerVersion::~ServiceWorkerVersion() { | 297 ServiceWorkerVersion::~ServiceWorkerVersion() { |
| 298 in_dtor_ = true; | 298 in_dtor_ = true; |
| 299 | 299 |
| 300 // The user may have closed the tab waiting for SW to start up. | 300 // The user may have closed the tab waiting for SW to start up. |
| 301 if (GetTickDuration(start_time_) > | 301 if (GetTickDuration(start_time_) > |
| 302 base::TimeDelta::FromSeconds( | 302 base::TimeDelta::FromSeconds( |
| 303 kDestructedStartingWorkerTimeoutThresholdSeconds)) { | 303 kDestructedStartingWorkerTimeoutThresholdSeconds)) { |
| 304 DCHECK(timeout_timer_.IsRunning()); | 304 DCHECK(timeout_timer_.IsRunning()); |
| 305 DCHECK(!embedded_worker_->devtools_attached()); | 305 DCHECK(!embedded_worker_->devtools_attached()); |
| 306 RecordStartWorkerResult(SERVICE_WORKER_ERROR_TIMEOUT); | 306 |
| 307 // RecordStartWorkerResult must be in start_callbacks_. |
| 308 DCHECK(!start_callbacks_.empty()); |
| 309 RecordStartWorkerResult(ServiceWorkerMetrics::EventType::UNKNOWN, |
| 310 SERVICE_WORKER_ERROR_TIMEOUT); |
| 307 } | 311 } |
| 308 | 312 |
| 309 if (context_) | 313 if (context_) |
| 310 context_->RemoveLiveVersion(version_id_); | 314 context_->RemoveLiveVersion(version_id_); |
| 311 | 315 |
| 312 if (running_status() == STARTING || running_status() == RUNNING) | 316 if (running_status() == STARTING || running_status() == RUNNING) |
| 313 embedded_worker_->Stop(); | 317 embedded_worker_->Stop(); |
| 314 embedded_worker_->RemoveListener(this); | 318 embedded_worker_->RemoveListener(this); |
| 315 } | 319 } |
| 316 | 320 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 } | 358 } |
| 355 if (!main_script_http_info_) | 359 if (!main_script_http_info_) |
| 356 return info; | 360 return info; |
| 357 info.script_response_time = main_script_http_info_->response_time; | 361 info.script_response_time = main_script_http_info_->response_time; |
| 358 if (main_script_http_info_->headers) | 362 if (main_script_http_info_->headers) |
| 359 main_script_http_info_->headers->GetLastModifiedValue( | 363 main_script_http_info_->headers->GetLastModifiedValue( |
| 360 &info.script_last_modified); | 364 &info.script_last_modified); |
| 361 return info; | 365 return info; |
| 362 } | 366 } |
| 363 | 367 |
| 364 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { | 368 void ServiceWorkerVersion::StartWorker(ServiceWorkerMetrics::EventType purpose, |
| 369 const StatusCallback& callback) { |
| 365 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 370 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 366 if (!context_) { | 371 if (!context_) { |
| 367 RecordStartWorkerResult(SERVICE_WORKER_ERROR_ABORT); | 372 RecordStartWorkerResult(purpose, SERVICE_WORKER_ERROR_ABORT); |
| 368 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); | 373 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); |
| 369 return; | 374 return; |
| 370 } | 375 } |
| 371 if (is_redundant()) { | 376 if (is_redundant()) { |
| 372 RecordStartWorkerResult(SERVICE_WORKER_ERROR_REDUNDANT); | 377 RecordStartWorkerResult(purpose, SERVICE_WORKER_ERROR_REDUNDANT); |
| 373 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_REDUNDANT)); | 378 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_REDUNDANT)); |
| 374 return; | 379 return; |
| 375 } | 380 } |
| 376 if (IsDisabled()) { | 381 if (IsDisabled()) { |
| 377 RecordStartWorkerResult(SERVICE_WORKER_ERROR_DISABLED_WORKER); | 382 RecordStartWorkerResult(purpose, SERVICE_WORKER_ERROR_DISABLED_WORKER); |
| 378 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_DISABLED_WORKER)); | 383 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_DISABLED_WORKER)); |
| 379 | 384 |
| 380 // Show a message in DevTools for developers. | 385 // Show a message in DevTools for developers. |
| 381 ReportError(SERVICE_WORKER_ERROR_DISABLED_WORKER, | 386 ReportError(SERVICE_WORKER_ERROR_DISABLED_WORKER, |
| 382 "The service worker is disabled because its start failure " | 387 "The service worker is disabled because its start failure " |
| 383 "count is too high."); | 388 "count is too high."); |
| 384 return; | 389 return; |
| 385 } | 390 } |
| 386 | 391 |
| 387 // Check that the worker is allowed to start on the given scope. Since this | 392 // Check that the worker is allowed to start on the given scope. Since this |
| 388 // worker might not be used for a specific frame/process, use -1. | 393 // worker might not be used for a specific frame/process, use -1. |
| 389 // resource_context() can return null in unit tests. | 394 // resource_context() can return null in unit tests. |
| 390 if (context_->wrapper()->resource_context() && | 395 if (context_->wrapper()->resource_context() && |
| 391 !GetContentClient()->browser()->AllowServiceWorker( | 396 !GetContentClient()->browser()->AllowServiceWorker( |
| 392 scope_, scope_, context_->wrapper()->resource_context(), -1, -1)) { | 397 scope_, scope_, context_->wrapper()->resource_context(), -1, -1)) { |
| 393 RecordStartWorkerResult(SERVICE_WORKER_ERROR_DISALLOWED); | 398 RecordStartWorkerResult(purpose, SERVICE_WORKER_ERROR_DISALLOWED); |
| 394 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_DISALLOWED)); | 399 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_DISALLOWED)); |
| 395 return; | 400 return; |
| 396 } | 401 } |
| 397 | 402 |
| 398 prestart_status_ = status_; | 403 prestart_status_ = status_; |
| 399 | 404 |
| 400 // Ensure the live registration during starting worker so that the worker can | 405 // Ensure the live registration during starting worker so that the worker can |
| 401 // get associated with it in SWDispatcherHost::OnSetHostedVersionId(). | 406 // get associated with it in SWDispatcherHost::OnSetHostedVersionId(). |
| 402 context_->storage()->FindRegistrationForId( | 407 context_->storage()->FindRegistrationForId( |
| 403 registration_id_, | 408 registration_id_, scope_.GetOrigin(), |
| 404 scope_.GetOrigin(), | |
| 405 base::Bind(&ServiceWorkerVersion::DidEnsureLiveRegistrationForStartWorker, | 409 base::Bind(&ServiceWorkerVersion::DidEnsureLiveRegistrationForStartWorker, |
| 406 weak_factory_.GetWeakPtr(), | 410 weak_factory_.GetWeakPtr(), purpose, callback)); |
| 407 callback)); | |
| 408 } | 411 } |
| 409 | 412 |
| 410 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { | 413 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { |
| 411 if (running_status() == STOPPED) { | 414 if (running_status() == STOPPED) { |
| 412 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 415 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
| 413 return; | 416 return; |
| 414 } | 417 } |
| 415 if (stop_callbacks_.empty()) { | 418 if (stop_callbacks_.empty()) { |
| 416 ServiceWorkerStatusCode status = embedded_worker_->Stop(); | 419 ServiceWorkerStatusCode status = embedded_worker_->Stop(); |
| 417 if (status != SERVICE_WORKER_OK) { | 420 if (status != SERVICE_WORKER_OK) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 custom_requests_.Remove(request_id); | 510 custom_requests_.Remove(request_id); |
| 508 if (is_redundant()) { | 511 if (is_redundant()) { |
| 509 // The stop should be already scheduled, but try to stop immediately, in | 512 // The stop should be already scheduled, but try to stop immediately, in |
| 510 // order to release worker resources soon. | 513 // order to release worker resources soon. |
| 511 StopWorkerIfIdle(); | 514 StopWorkerIfIdle(); |
| 512 } | 515 } |
| 513 return true; | 516 return true; |
| 514 } | 517 } |
| 515 | 518 |
| 516 void ServiceWorkerVersion::RunAfterStartWorker( | 519 void ServiceWorkerVersion::RunAfterStartWorker( |
| 520 ServiceWorkerMetrics::EventType purpose, |
| 517 const base::Closure& task, | 521 const base::Closure& task, |
| 518 const StatusCallback& error_callback) { | 522 const StatusCallback& error_callback) { |
| 519 if (running_status() == RUNNING) { | 523 if (running_status() == RUNNING) { |
| 520 DCHECK(start_callbacks_.empty()); | 524 DCHECK(start_callbacks_.empty()); |
| 521 task.Run(); | 525 task.Run(); |
| 522 return; | 526 return; |
| 523 } | 527 } |
| 524 StartWorker(base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), | 528 StartWorker(purpose, |
| 529 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), |
| 525 error_callback, task)); | 530 error_callback, task)); |
| 526 } | 531 } |
| 527 | 532 |
| 528 void ServiceWorkerVersion::DispatchMessageEvent( | 533 void ServiceWorkerVersion::DispatchMessageEvent( |
| 529 const base::string16& message, | 534 const base::string16& message, |
| 530 const std::vector<TransferredMessagePort>& sent_message_ports, | 535 const std::vector<TransferredMessagePort>& sent_message_ports, |
| 531 const StatusCallback& callback) { | 536 const StatusCallback& callback) { |
| 532 for (const TransferredMessagePort& port : sent_message_ports) { | 537 for (const TransferredMessagePort& port : sent_message_ports) { |
| 533 MessagePortService::GetInstance()->HoldMessages(port.id); | 538 MessagePortService::GetInstance()->HoldMessages(port.id); |
| 534 } | 539 } |
| 535 | 540 |
| 536 DispatchMessageEventInternal(message, sent_message_ports, callback); | 541 DispatchMessageEventInternal(message, sent_message_ports, callback); |
| 537 } | 542 } |
| 538 | 543 |
| 539 void ServiceWorkerVersion::DispatchMessageEventInternal( | 544 void ServiceWorkerVersion::DispatchMessageEventInternal( |
| 540 const base::string16& message, | 545 const base::string16& message, |
| 541 const std::vector<TransferredMessagePort>& sent_message_ports, | 546 const std::vector<TransferredMessagePort>& sent_message_ports, |
| 542 const StatusCallback& callback) { | 547 const StatusCallback& callback) { |
| 543 OnBeginEvent(); | 548 OnBeginEvent(); |
| 544 if (running_status() != RUNNING) { | 549 if (running_status() != RUNNING) { |
| 545 // Schedule calling this method after starting the worker. | 550 // Schedule calling this method after starting the worker. |
| 546 StartWorker(base::Bind( | 551 StartWorker(ServiceWorkerMetrics::EventType::MESSAGE, |
| 547 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), | 552 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), |
| 548 base::Bind(&RunErrorMessageCallback, sent_message_ports, callback), | 553 base::Bind(&RunErrorMessageCallback, |
| 549 base::Bind(&self::DispatchMessageEventInternal, | 554 sent_message_ports, callback), |
| 550 weak_factory_.GetWeakPtr(), message, sent_message_ports, | 555 base::Bind(&self::DispatchMessageEventInternal, |
| 551 callback))); | 556 weak_factory_.GetWeakPtr(), message, |
| 557 sent_message_ports, callback))); |
| 552 return; | 558 return; |
| 553 } | 559 } |
| 554 | 560 |
| 555 // TODO(kinuko): Cleanup this (and corresponding unit test) when message | 561 // TODO(kinuko): Cleanup this (and corresponding unit test) when message |
| 556 // event becomes extendable, round-trip event. (crbug.com/498596) | 562 // event becomes extendable, round-trip event. (crbug.com/498596) |
| 557 RestartTick(&idle_time_); | 563 RestartTick(&idle_time_); |
| 558 | 564 |
| 559 MessagePortMessageFilter* filter = | 565 MessagePortMessageFilter* filter = |
| 560 embedded_worker_->message_port_message_filter(); | 566 embedded_worker_->message_port_message_filter(); |
| 561 std::vector<int> new_routing_ids; | 567 std::vector<int> new_routing_ids; |
| 562 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids); | 568 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids); |
| 563 ServiceWorkerStatusCode status = | 569 ServiceWorkerStatusCode status = |
| 564 embedded_worker_->SendMessage(ServiceWorkerMsg_MessageToWorker( | 570 embedded_worker_->SendMessage(ServiceWorkerMsg_MessageToWorker( |
| 565 message, sent_message_ports, new_routing_ids)); | 571 message, sent_message_ports, new_routing_ids)); |
| 566 RunSoon(base::Bind(callback, status)); | 572 RunSoon(base::Bind(callback, status)); |
| 567 } | 573 } |
| 568 | 574 |
| 569 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( | 575 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( |
| 570 const NavigatorConnectClient& client, | 576 const NavigatorConnectClient& client, |
| 571 const base::string16& message, | 577 const base::string16& message, |
| 572 const std::vector<TransferredMessagePort>& sent_message_ports, | 578 const std::vector<TransferredMessagePort>& sent_message_ports, |
| 573 const StatusCallback& callback) { | 579 const StatusCallback& callback) { |
| 574 OnBeginEvent(); | 580 OnBeginEvent(); |
| 575 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to | 581 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to |
| 576 // have already put all the sent message ports on hold. So no need to do that | 582 // have already put all the sent message ports on hold. So no need to do that |
| 577 // here again. | 583 // here again. |
| 578 | 584 |
| 579 if (running_status() != RUNNING) { | 585 if (running_status() != RUNNING) { |
| 580 // Schedule calling this method after starting the worker. | 586 // Schedule calling this method after starting the worker. |
| 581 StartWorker(base::Bind( | 587 StartWorker(ServiceWorkerMetrics::EventType::MESSAGE, |
| 582 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), | 588 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), |
| 583 base::Bind(&RunErrorMessageCallback, sent_message_ports, callback), | 589 base::Bind(&RunErrorMessageCallback, |
| 584 base::Bind(&self::DispatchCrossOriginMessageEvent, | 590 sent_message_ports, callback), |
| 585 weak_factory_.GetWeakPtr(), client, message, | 591 base::Bind(&self::DispatchCrossOriginMessageEvent, |
| 586 sent_message_ports, callback))); | 592 weak_factory_.GetWeakPtr(), client, |
| 593 message, sent_message_ports, callback))); |
| 587 return; | 594 return; |
| 588 } | 595 } |
| 589 | 596 |
| 590 MessagePortMessageFilter* filter = | 597 MessagePortMessageFilter* filter = |
| 591 embedded_worker_->message_port_message_filter(); | 598 embedded_worker_->message_port_message_filter(); |
| 592 std::vector<int> new_routing_ids; | 599 std::vector<int> new_routing_ids; |
| 593 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids); | 600 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids); |
| 594 ServiceWorkerStatusCode status = | 601 ServiceWorkerStatusCode status = |
| 595 embedded_worker_->SendMessage(ServiceWorkerMsg_CrossOriginMessageToWorker( | 602 embedded_worker_->SendMessage(ServiceWorkerMsg_CrossOriginMessageToWorker( |
| 596 client, message, sent_message_ports, new_routing_ids)); | 603 client, message, sent_message_ports, new_routing_ids)); |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 base::Bind(&KillEmbeddedWorkerProcess, embedded_worker_->process_id(), | 1276 base::Bind(&KillEmbeddedWorkerProcess, embedded_worker_->process_id(), |
| 1270 RESULT_CODE_KILLED_BAD_MESSAGE)); | 1277 RESULT_CODE_KILLED_BAD_MESSAGE)); |
| 1271 return; | 1278 return; |
| 1272 } | 1279 } |
| 1273 } | 1280 } |
| 1274 set_foreign_fetch_scopes(sub_scopes); | 1281 set_foreign_fetch_scopes(sub_scopes); |
| 1275 set_foreign_fetch_origins(origins); | 1282 set_foreign_fetch_origins(origins); |
| 1276 } | 1283 } |
| 1277 | 1284 |
| 1278 void ServiceWorkerVersion::DidEnsureLiveRegistrationForStartWorker( | 1285 void ServiceWorkerVersion::DidEnsureLiveRegistrationForStartWorker( |
| 1286 ServiceWorkerMetrics::EventType purpose, |
| 1279 const StatusCallback& callback, | 1287 const StatusCallback& callback, |
| 1280 ServiceWorkerStatusCode status, | 1288 ServiceWorkerStatusCode status, |
| 1281 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 1289 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 1282 scoped_refptr<ServiceWorkerRegistration> protect = registration; | 1290 scoped_refptr<ServiceWorkerRegistration> protect = registration; |
| 1283 if (status == SERVICE_WORKER_ERROR_NOT_FOUND) { | 1291 if (status == SERVICE_WORKER_ERROR_NOT_FOUND) { |
| 1284 // When the registration has already been deleted from the storage but its | 1292 // When the registration has already been deleted from the storage but its |
| 1285 // active worker is still controlling clients, the event should be | 1293 // active worker is still controlling clients, the event should be |
| 1286 // dispatched on the worker. However, the storage cannot find the | 1294 // dispatched on the worker. However, the storage cannot find the |
| 1287 // registration. To handle the case, check the live registrations here. | 1295 // registration. To handle the case, check the live registrations here. |
| 1288 protect = context_->GetLiveRegistration(registration_id_); | 1296 protect = context_->GetLiveRegistration(registration_id_); |
| 1289 if (protect) { | 1297 if (protect) { |
| 1290 DCHECK(protect->is_deleted()); | 1298 DCHECK(protect->is_deleted()); |
| 1291 status = SERVICE_WORKER_OK; | 1299 status = SERVICE_WORKER_OK; |
| 1292 } | 1300 } |
| 1293 } | 1301 } |
| 1294 if (status != SERVICE_WORKER_OK) { | 1302 if (status != SERVICE_WORKER_OK) { |
| 1295 RecordStartWorkerResult(status); | 1303 RecordStartWorkerResult(purpose, status); |
| 1296 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); | 1304 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); |
| 1297 return; | 1305 return; |
| 1298 } | 1306 } |
| 1299 if (is_redundant()) { | 1307 if (is_redundant()) { |
| 1300 RecordStartWorkerResult(SERVICE_WORKER_ERROR_REDUNDANT); | 1308 RecordStartWorkerResult(purpose, SERVICE_WORKER_ERROR_REDUNDANT); |
| 1301 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_REDUNDANT)); | 1309 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_REDUNDANT)); |
| 1302 return; | 1310 return; |
| 1303 } | 1311 } |
| 1304 | 1312 |
| 1305 MarkIfStale(); | 1313 MarkIfStale(); |
| 1306 | 1314 |
| 1307 switch (running_status()) { | 1315 switch (running_status()) { |
| 1308 case RUNNING: | 1316 case RUNNING: |
| 1309 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 1317 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
| 1310 return; | 1318 return; |
| 1311 case STARTING: | 1319 case STARTING: |
| 1312 DCHECK(!start_callbacks_.empty()); | 1320 DCHECK(!start_callbacks_.empty()); |
| 1313 break; | 1321 break; |
| 1314 case STOPPING: | 1322 case STOPPING: |
| 1315 case STOPPED: | 1323 case STOPPED: |
| 1316 if (start_callbacks_.empty()) { | 1324 if (start_callbacks_.empty()) { |
| 1317 start_callbacks_.push_back( | 1325 start_callbacks_.push_back( |
| 1318 base::Bind(&ServiceWorkerVersion::RecordStartWorkerResult, | 1326 base::Bind(&ServiceWorkerVersion::RecordStartWorkerResult, |
| 1319 weak_factory_.GetWeakPtr())); | 1327 weak_factory_.GetWeakPtr(), purpose)); |
| 1320 } | 1328 } |
| 1321 break; | 1329 break; |
| 1322 } | 1330 } |
| 1323 | 1331 |
| 1324 // Keep the live registration while starting the worker. | 1332 // Keep the live registration while starting the worker. |
| 1325 start_callbacks_.push_back( | 1333 start_callbacks_.push_back( |
| 1326 base::Bind(&RunStartWorkerCallback, callback, protect)); | 1334 base::Bind(&RunStartWorkerCallback, callback, protect)); |
| 1327 | 1335 |
| 1328 if (running_status() == STOPPED) | 1336 if (running_status() == STOPPED) |
| 1329 StartWorkerInternal(); | 1337 StartWorkerInternal(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 } | 1509 } |
| 1502 | 1510 |
| 1503 embedded_worker_->StopIfIdle(); | 1511 embedded_worker_->StopIfIdle(); |
| 1504 } | 1512 } |
| 1505 | 1513 |
| 1506 bool ServiceWorkerVersion::HasInflightRequests() const { | 1514 bool ServiceWorkerVersion::HasInflightRequests() const { |
| 1507 return !custom_requests_.IsEmpty() || !streaming_url_request_jobs_.empty(); | 1515 return !custom_requests_.IsEmpty() || !streaming_url_request_jobs_.empty(); |
| 1508 } | 1516 } |
| 1509 | 1517 |
| 1510 void ServiceWorkerVersion::RecordStartWorkerResult( | 1518 void ServiceWorkerVersion::RecordStartWorkerResult( |
| 1519 ServiceWorkerMetrics::EventType purpose, |
| 1511 ServiceWorkerStatusCode status) { | 1520 ServiceWorkerStatusCode status) { |
| 1512 base::TimeTicks start_time = start_time_; | 1521 base::TimeTicks start_time = start_time_; |
| 1513 ClearTick(&start_time_); | 1522 ClearTick(&start_time_); |
| 1514 | 1523 |
| 1515 if (context_) | 1524 if (context_) |
| 1516 context_->UpdateVersionFailureCount(version_id_, status); | 1525 context_->UpdateVersionFailureCount(version_id_, status); |
| 1517 | 1526 |
| 1518 ServiceWorkerMetrics::RecordStartWorkerStatus(status, | 1527 ServiceWorkerMetrics::RecordStartWorkerStatus(status, purpose, |
| 1519 IsInstalled(prestart_status_)); | 1528 IsInstalled(prestart_status_)); |
| 1520 | 1529 |
| 1521 if (status == SERVICE_WORKER_OK && !start_time.is_null() && | 1530 if (status == SERVICE_WORKER_OK && !start_time.is_null() && |
| 1522 !skip_recording_startup_time_) { | 1531 !skip_recording_startup_time_) { |
| 1523 ServiceWorkerMetrics::RecordStartWorkerTime(GetTickDuration(start_time), | 1532 ServiceWorkerMetrics::RecordStartWorkerTime(GetTickDuration(start_time), |
| 1524 IsInstalled(prestart_status_)); | 1533 IsInstalled(prestart_status_)); |
| 1525 } | 1534 } |
| 1526 | 1535 |
| 1527 if (status != SERVICE_WORKER_ERROR_TIMEOUT) | 1536 if (status != SERVICE_WORKER_ERROR_TIMEOUT) |
| 1528 return; | 1537 return; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1693 void ServiceWorkerVersion::OnBeginEvent() { | 1702 void ServiceWorkerVersion::OnBeginEvent() { |
| 1694 if (should_exclude_from_uma_ || running_status() != RUNNING || | 1703 if (should_exclude_from_uma_ || running_status() != RUNNING || |
| 1695 idle_time_.is_null()) { | 1704 idle_time_.is_null()) { |
| 1696 return; | 1705 return; |
| 1697 } | 1706 } |
| 1698 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1707 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
| 1699 idle_time_); | 1708 idle_time_); |
| 1700 } | 1709 } |
| 1701 | 1710 |
| 1702 } // namespace content | 1711 } // namespace content |
| OLD | NEW |