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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 const GURL& script_url, | 300 const GURL& script_url, |
301 int64 version_id, | 301 int64 version_id, |
302 base::WeakPtr<ServiceWorkerContextCore> context) | 302 base::WeakPtr<ServiceWorkerContextCore> context) |
303 : version_id_(version_id), | 303 : version_id_(version_id), |
304 registration_id_(kInvalidServiceWorkerVersionId), | 304 registration_id_(kInvalidServiceWorkerVersionId), |
305 script_url_(script_url), | 305 script_url_(script_url), |
306 status_(NEW), | 306 status_(NEW), |
307 context_(context), | 307 context_(context), |
308 script_cache_map_(this, context), | 308 script_cache_map_(this, context), |
309 ping_state_(NOT_PINGING), | 309 ping_state_(NOT_PINGING), |
310 is_doomed_(false), | |
311 skip_waiting_(false), | |
312 weak_factory_(this) { | 310 weak_factory_(this) { |
313 DCHECK(context_); | 311 DCHECK(context_); |
314 DCHECK(registration); | 312 DCHECK(registration); |
315 if (registration) { | 313 if (registration) { |
316 registration_id_ = registration->id(); | 314 registration_id_ = registration->id(); |
317 scope_ = registration->pattern(); | 315 scope_ = registration->pattern(); |
318 } | 316 } |
319 context_->AddLiveVersion(this); | 317 context_->AddLiveVersion(this); |
320 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); | 318 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); |
321 embedded_worker_->AddListener(this); | 319 embedded_worker_->AddListener(this); |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 DoomInternal(); | 779 DoomInternal(); |
782 } | 780 } |
783 | 781 |
784 void ServiceWorkerVersion::SetDevToolsAttached(bool attached) { | 782 void ServiceWorkerVersion::SetDevToolsAttached(bool attached) { |
785 embedded_worker()->set_devtools_attached(attached); | 783 embedded_worker()->set_devtools_attached(attached); |
786 if (attached) { | 784 if (attached) { |
787 // Set to null time so we don't record the startup time metric. | 785 // Set to null time so we don't record the startup time metric. |
788 ClearTick(&start_time_); | 786 ClearTick(&start_time_); |
789 return; | 787 return; |
790 } | 788 } |
791 if (!timeout_timer_.IsRunning()) | 789 if (timeout_timer_.IsRunning() && running_status() == STARTING) { |
792 StartTimeoutTimer(); | 790 // Reactivate the timer for start timeout. |
791 RestartTick(&start_time_); | |
falken
2015/03/13 07:14:10
The start timeout sometimes should be in effect fo
nhiroki
2015/03/16 01:58:02
Thank you, I didn't notice it. Tweaked the conditi
| |
792 | |
793 // Once the DevTools is attached, we cannot record an accurate startup time. | |
794 skip_recording_startup_time_ = true; | |
falken
2015/03/13 07:14:10
This line and line 785-786 essentially do the same
nhiroki
2015/03/16 01:58:02
Exactly. Merged this into line 785.
| |
795 } | |
793 } | 796 } |
794 | 797 |
795 void ServiceWorkerVersion::SetMainScriptHttpResponseInfo( | 798 void ServiceWorkerVersion::SetMainScriptHttpResponseInfo( |
796 const net::HttpResponseInfo& http_info) { | 799 const net::HttpResponseInfo& http_info) { |
797 main_script_http_info_.reset(new net::HttpResponseInfo(http_info)); | 800 main_script_http_info_.reset(new net::HttpResponseInfo(http_info)); |
798 } | 801 } |
799 | 802 |
800 const net::HttpResponseInfo* | 803 const net::HttpResponseInfo* |
801 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { | 804 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { |
802 return main_script_http_info_.get(); | 805 return main_script_http_info_.get(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 // the listener prevents any pending completion callbacks from causing | 882 // the listener prevents any pending completion callbacks from causing |
880 // messages to be sent to the stopped worker. | 883 // messages to be sent to the stopped worker. |
881 cache_listener_.reset(); | 884 cache_listener_.reset(); |
882 | 885 |
883 // Restart worker if we have any start callbacks and the worker isn't doomed. | 886 // Restart worker if we have any start callbacks and the worker isn't doomed. |
884 if (should_restart) { | 887 if (should_restart) { |
885 if (embedded_worker_->devtools_attached()) | 888 if (embedded_worker_->devtools_attached()) |
886 ClearTick(&start_time_); | 889 ClearTick(&start_time_); |
887 else | 890 else |
888 RestartTick(&start_time_); | 891 RestartTick(&start_time_); |
892 skip_recording_startup_time_ = false; | |
889 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_)); | 893 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_)); |
890 embedded_worker_->Start( | 894 embedded_worker_->Start( |
891 version_id_, scope_, script_url_, false /* pause_after_download */, | 895 version_id_, scope_, script_url_, false /* pause_after_download */, |
892 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, | 896 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, |
893 weak_factory_.GetWeakPtr())); | 897 weak_factory_.GetWeakPtr())); |
894 } | 898 } |
895 } | 899 } |
896 | 900 |
897 void ServiceWorkerVersion::OnReportException( | 901 void ServiceWorkerVersion::OnReportException( |
898 const base::string16& error_message, | 902 const base::string16& error_message, |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1442 ServiceWorkerMsg_DidGetClients(request_id, clients)); | 1446 ServiceWorkerMsg_DidGetClients(request_id, clients)); |
1443 } | 1447 } |
1444 | 1448 |
1445 void ServiceWorkerVersion::StartTimeoutTimer() { | 1449 void ServiceWorkerVersion::StartTimeoutTimer() { |
1446 DCHECK(!timeout_timer_.IsRunning()); | 1450 DCHECK(!timeout_timer_.IsRunning()); |
1447 | 1451 |
1448 if (embedded_worker_->devtools_attached()) | 1452 if (embedded_worker_->devtools_attached()) |
1449 ClearTick(&start_time_); | 1453 ClearTick(&start_time_); |
1450 else | 1454 else |
1451 RestartTick(&start_time_); | 1455 RestartTick(&start_time_); |
1456 skip_recording_startup_time_ = false; | |
1452 start_callbacks_.push_back( | 1457 start_callbacks_.push_back( |
1453 base::Bind(&ServiceWorkerVersion::RecordStartWorkerResult, | 1458 base::Bind(&ServiceWorkerVersion::RecordStartWorkerResult, |
1454 weak_factory_.GetWeakPtr())); | 1459 weak_factory_.GetWeakPtr())); |
1455 | 1460 |
1456 ClearTick(&idle_time_); | 1461 ClearTick(&idle_time_); |
1457 ClearTick(&ping_time_); | 1462 ClearTick(&ping_time_); |
1458 ping_state_ = NOT_PINGING; | 1463 ping_state_ = NOT_PINGING; |
1459 | 1464 |
1460 timeout_timer_.Start(FROM_HERE, | 1465 timeout_timer_.Start(FROM_HERE, |
1461 base::TimeDelta::FromSeconds(kTimeoutTimerDelaySeconds), | 1466 base::TimeDelta::FromSeconds(kTimeoutTimerDelaySeconds), |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1561 base::TimeTicks start_time = start_time_; | 1566 base::TimeTicks start_time = start_time_; |
1562 ClearTick(&start_time_); | 1567 ClearTick(&start_time_); |
1563 | 1568 |
1564 // Failing to start a doomed worker isn't interesting and very common when | 1569 // Failing to start a doomed worker isn't interesting and very common when |
1565 // update dooms because the script is byte-to-byte identical. | 1570 // update dooms because the script is byte-to-byte identical. |
1566 if (is_doomed_) | 1571 if (is_doomed_) |
1567 return; | 1572 return; |
1568 | 1573 |
1569 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.Status", status, | 1574 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.Status", status, |
1570 SERVICE_WORKER_ERROR_MAX_VALUE); | 1575 SERVICE_WORKER_ERROR_MAX_VALUE); |
1571 if (status == SERVICE_WORKER_OK && !start_time.is_null()) { | 1576 if (status == SERVICE_WORKER_OK && !start_time.is_null() && |
1577 !skip_recording_startup_time_) { | |
1572 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StartWorker.Time", | 1578 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.StartWorker.Time", |
1573 GetTickDuration(start_time)); | 1579 GetTickDuration(start_time)); |
1574 } | 1580 } |
1575 | 1581 |
1576 if (status != SERVICE_WORKER_ERROR_TIMEOUT) | 1582 if (status != SERVICE_WORKER_ERROR_TIMEOUT) |
1577 return; | 1583 return; |
1578 EmbeddedWorkerInstance::StartingPhase phase = | 1584 EmbeddedWorkerInstance::StartingPhase phase = |
1579 EmbeddedWorkerInstance::NOT_STARTING; | 1585 EmbeddedWorkerInstance::NOT_STARTING; |
1580 EmbeddedWorkerInstance::Status running_status = embedded_worker_->status(); | 1586 EmbeddedWorkerInstance::Status running_status = embedded_worker_->status(); |
1581 // Build an artifical JavaScript exception to show in the ServiceWorker | 1587 // Build an artifical JavaScript exception to show in the ServiceWorker |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1615 int request_id) { | 1621 int request_id) { |
1616 callbacks->Remove(request_id); | 1622 callbacks->Remove(request_id); |
1617 if (is_doomed_) { | 1623 if (is_doomed_) { |
1618 // The stop should be already scheduled, but try to stop immediately, in | 1624 // The stop should be already scheduled, but try to stop immediately, in |
1619 // order to release worker resources soon. | 1625 // order to release worker resources soon. |
1620 StopWorkerIfIdle(); | 1626 StopWorkerIfIdle(); |
1621 } | 1627 } |
1622 } | 1628 } |
1623 | 1629 |
1624 } // namespace content | 1630 } // namespace content |
OLD | NEW |