| Index: content/browser/service_worker/service_worker_version.cc
|
| diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
|
| index 470bc86f5ee2b94066316433b3d34c1670103fe0..e13a69da8baa24d4bba7013ccecea9615fef8e1d 100644
|
| --- a/content/browser/service_worker/service_worker_version.cc
|
| +++ b/content/browser/service_worker/service_worker_version.cc
|
| @@ -103,7 +103,8 @@ void RunTaskAfterStartWorker(
|
| error_callback.Run(status);
|
| return;
|
| }
|
| - if (version->running_status() != ServiceWorkerVersion::RUNNING) {
|
| + if (version->running_status() !=
|
| + ServiceWorkerVersion::RunningStatus::RUNNING) {
|
| // We've tried to start the worker (and it has succeeded), but
|
| // it looks it's not running yet.
|
| NOTREACHED() << "The worker's not running after successful StartWorker";
|
| @@ -326,8 +327,10 @@ ServiceWorkerVersion::~ServiceWorkerVersion() {
|
| if (context_)
|
| context_->RemoveLiveVersion(version_id_);
|
|
|
| - if (running_status() == STARTING || running_status() == RUNNING)
|
| + if (running_status() == RunningStatus::STARTING ||
|
| + running_status() == RunningStatus::RUNNING) {
|
| embedded_worker_->Stop();
|
| + }
|
| embedded_worker_->RemoveListener(this);
|
| }
|
|
|
| @@ -446,7 +449,7 @@ void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) {
|
| TRACE_EVENT_SCOPE_THREAD, "Script", script_url_.spec(),
|
| "Status", VersionStatusToString(status_));
|
|
|
| - if (running_status() == STOPPED) {
|
| + if (running_status() == RunningStatus::STOPPED) {
|
| RunSoon(base::Bind(callback, SERVICE_WORKER_OK));
|
| return;
|
| }
|
| @@ -509,7 +512,7 @@ int ServiceWorkerVersion::StartRequestWithCustomTimeout(
|
| const base::TimeDelta& timeout,
|
| TimeoutBehavior timeout_behavior) {
|
| OnBeginEvent();
|
| - DCHECK_EQ(RUNNING, running_status())
|
| + DCHECK_EQ(RunningStatus::RUNNING, running_status())
|
| << "Can only start a request with a running worker.";
|
| DCHECK(event_type == ServiceWorkerMetrics::EventType::INSTALL ||
|
| event_type == ServiceWorkerMetrics::EventType::ACTIVATE ||
|
| @@ -556,7 +559,7 @@ void ServiceWorkerVersion::RunAfterStartWorker(
|
| ServiceWorkerMetrics::EventType purpose,
|
| const base::Closure& task,
|
| const StatusCallback& error_callback) {
|
| - if (running_status() == RUNNING) {
|
| + if (running_status() == RunningStatus::RUNNING) {
|
| DCHECK(start_callbacks_.empty());
|
| task.Run();
|
| return;
|
| @@ -630,7 +633,8 @@ void ServiceWorkerVersion::SetStartWorkerStatusCode(
|
| void ServiceWorkerVersion::Doom() {
|
| DCHECK(!HasControllee());
|
| SetStatus(REDUNDANT);
|
| - if (running_status() == STARTING || running_status() == RUNNING) {
|
| + if (running_status() == RunningStatus::STARTING ||
|
| + running_status() == RunningStatus::RUNNING) {
|
| if (embedded_worker()->devtools_attached())
|
| stop_when_devtools_detached_ = true;
|
| else
|
| @@ -647,8 +651,10 @@ void ServiceWorkerVersion::SetDevToolsAttached(bool attached) {
|
| embedded_worker()->set_devtools_attached(attached);
|
| if (stop_when_devtools_detached_ && !attached) {
|
| DCHECK_EQ(REDUNDANT, status());
|
| - if (running_status() == STARTING || running_status() == RUNNING)
|
| + if (running_status() == RunningStatus::STARTING ||
|
| + running_status() == RunningStatus::RUNNING) {
|
| embedded_worker_->Stop();
|
| + }
|
| return;
|
| }
|
| if (attached) {
|
| @@ -667,8 +673,9 @@ void ServiceWorkerVersion::SetDevToolsAttached(bool attached) {
|
| if (!start_callbacks_.empty()) {
|
| // Reactivate the timer for start timeout.
|
| DCHECK(timeout_timer_.IsRunning());
|
| - DCHECK(running_status() == STARTING || running_status() == STOPPING)
|
| - << running_status();
|
| + DCHECK(running_status() == RunningStatus::STARTING ||
|
| + running_status() == RunningStatus::STOPPING)
|
| + << static_cast<int>(running_status());
|
| RestartTick(&start_time_);
|
| }
|
|
|
| @@ -740,7 +747,7 @@ ServiceWorkerVersion::BaseMojoServiceWrapper::~BaseMojoServiceWrapper() {
|
| }
|
|
|
| void ServiceWorkerVersion::OnThreadStarted() {
|
| - DCHECK_EQ(STARTING, running_status());
|
| + DCHECK_EQ(RunningStatus::STARTING, running_status());
|
| // Activate ping/pong now that JavaScript execution will start.
|
| ping_controller_->Activate();
|
| }
|
| @@ -750,7 +757,7 @@ void ServiceWorkerVersion::OnStarting() {
|
| }
|
|
|
| void ServiceWorkerVersion::OnStarted() {
|
| - DCHECK_EQ(RUNNING, running_status());
|
| + DCHECK_EQ(RunningStatus::RUNNING, running_status());
|
| RestartTick(&idle_time_);
|
|
|
| // Fire all start callbacks.
|
| @@ -899,8 +906,10 @@ void ServiceWorkerVersion::OnGetClientFinished(
|
|
|
| // When Clients.get() is called on the script evaluation phase, the running
|
| // status can be STARTING here.
|
| - if (running_status() != STARTING && running_status() != RUNNING)
|
| + if (running_status() != RunningStatus::STARTING &&
|
| + running_status() != RunningStatus::RUNNING) {
|
| return;
|
| + }
|
|
|
| embedded_worker_->SendMessage(
|
| ServiceWorkerMsg_DidGetClient(request_id, client_info));
|
| @@ -927,8 +936,10 @@ void ServiceWorkerVersion::OnGetClientsFinished(int request_id,
|
|
|
| // When Clients.matchAll() is called on the script evaluation phase, the
|
| // running status can be STARTING here.
|
| - if (running_status() != STARTING && running_status() != RUNNING)
|
| + if (running_status() != RunningStatus::STARTING &&
|
| + running_status() != RunningStatus::RUNNING) {
|
| return;
|
| + }
|
|
|
| embedded_worker_->SendMessage(
|
| ServiceWorkerMsg_DidGetClients(request_id, *clients));
|
| @@ -993,7 +1004,7 @@ void ServiceWorkerVersion::OnOpenWindowFinished(
|
| const ServiceWorkerClientInfo& client_info) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|
| - if (running_status() != RUNNING)
|
| + if (running_status() != RunningStatus::RUNNING)
|
| return;
|
|
|
| if (status != SERVICE_WORKER_OK) {
|
| @@ -1101,7 +1112,7 @@ void ServiceWorkerVersion::OnFocusClientFinished(
|
| const ServiceWorkerClientInfo& client_info) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|
| - if (running_status() != RUNNING)
|
| + if (running_status() != RunningStatus::RUNNING)
|
| return;
|
|
|
| embedded_worker_->SendMessage(
|
| @@ -1157,7 +1168,7 @@ void ServiceWorkerVersion::OnNavigateClientFinished(
|
| const ServiceWorkerClientInfo& client_info) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|
| - if (running_status() != RUNNING)
|
| + if (running_status() != RunningStatus::RUNNING)
|
| return;
|
|
|
| if (status != SERVICE_WORKER_OK) {
|
| @@ -1187,8 +1198,10 @@ void ServiceWorkerVersion::OnSkipWaiting(int request_id) {
|
| }
|
|
|
| void ServiceWorkerVersion::DidSkipWaiting(int request_id) {
|
| - if (running_status() == STARTING || running_status() == RUNNING)
|
| + if (running_status() == RunningStatus::STARTING ||
|
| + running_status() == RunningStatus::RUNNING) {
|
| embedded_worker_->SendMessage(ServiceWorkerMsg_DidSkipWaiting(request_id));
|
| + }
|
| }
|
|
|
| void ServiceWorkerVersion::OnClaimClients(int request_id) {
|
| @@ -1287,14 +1300,14 @@ void ServiceWorkerVersion::DidEnsureLiveRegistrationForStartWorker(
|
| MarkIfStale();
|
|
|
| switch (running_status()) {
|
| - case RUNNING:
|
| + case RunningStatus::RUNNING:
|
| RunSoon(base::Bind(callback, SERVICE_WORKER_OK));
|
| return;
|
| - case STARTING:
|
| + case RunningStatus::STARTING:
|
| DCHECK(!start_callbacks_.empty());
|
| break;
|
| - case STOPPING:
|
| - case STOPPED:
|
| + case RunningStatus::STOPPING:
|
| + case RunningStatus::STOPPED:
|
| if (start_callbacks_.empty()) {
|
| int trace_id = NextTraceId();
|
| TRACE_EVENT_ASYNC_BEGIN2(
|
| @@ -1313,13 +1326,13 @@ void ServiceWorkerVersion::DidEnsureLiveRegistrationForStartWorker(
|
| start_callbacks_.push_back(
|
| base::Bind(&RunStartWorkerCallback, callback, protect));
|
|
|
| - if (running_status() == STOPPED)
|
| + if (running_status() == RunningStatus::STOPPED)
|
| StartWorkerInternal();
|
| DCHECK(timeout_timer_.IsRunning());
|
| }
|
|
|
| void ServiceWorkerVersion::StartWorkerInternal() {
|
| - DCHECK_EQ(STOPPED, running_status());
|
| + DCHECK_EQ(RunningStatus::STOPPED, running_status());
|
|
|
| DCHECK(!metrics_);
|
| metrics_.reset(new Metrics(this));
|
| @@ -1385,9 +1398,10 @@ void ServiceWorkerVersion::SetTimeoutTimerInterval(base::TimeDelta interval) {
|
| }
|
|
|
| void ServiceWorkerVersion::OnTimeoutTimer() {
|
| - DCHECK(running_status() == STARTING || running_status() == RUNNING ||
|
| - running_status() == STOPPING)
|
| - << running_status();
|
| + DCHECK(running_status() == RunningStatus::STARTING ||
|
| + running_status() == RunningStatus::RUNNING ||
|
| + running_status() == RunningStatus::STOPPING)
|
| + << static_cast<int>(running_status());
|
|
|
| if (!context_)
|
| return;
|
| @@ -1397,7 +1411,7 @@ void ServiceWorkerVersion::OnTimeoutTimer() {
|
| // Stopping the worker hasn't finished within a certain period.
|
| if (GetTickDuration(stop_time_) >
|
| base::TimeDelta::FromSeconds(kStopWorkerTimeoutSeconds)) {
|
| - DCHECK_EQ(STOPPING, running_status());
|
| + DCHECK_EQ(RunningStatus::STOPPING, running_status());
|
| if (IsInstalled(status())) {
|
| ServiceWorkerMetrics::RecordWorkerStopped(
|
| ServiceWorkerMetrics::StopStatus::TIMEOUT);
|
| @@ -1413,7 +1427,7 @@ void ServiceWorkerVersion::OnTimeoutTimer() {
|
| embedded_worker_->AddListener(this);
|
|
|
| // Call OnStoppedInternal to fail callbacks and possibly restart.
|
| - OnStoppedInternal(EmbeddedWorkerInstance::STOPPING);
|
| + OnStoppedInternal(EmbeddedWorkerInstance::Status::STOPPING);
|
| return;
|
| }
|
|
|
| @@ -1432,11 +1446,12 @@ void ServiceWorkerVersion::OnTimeoutTimer() {
|
| ? base::TimeDelta::FromSeconds(kStartInstalledWorkerTimeoutSeconds)
|
| : base::TimeDelta::FromMinutes(kStartNewWorkerTimeoutMinutes);
|
| if (GetTickDuration(start_time_) > start_limit) {
|
| - DCHECK(running_status() == STARTING || running_status() == STOPPING)
|
| - << running_status();
|
| + DCHECK(running_status() == RunningStatus::STARTING ||
|
| + running_status() == RunningStatus::STOPPING)
|
| + << static_cast<int>(running_status());
|
| scoped_refptr<ServiceWorkerVersion> protect(this);
|
| RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_ERROR_TIMEOUT);
|
| - if (running_status() == STARTING)
|
| + if (running_status() == RunningStatus::STARTING)
|
| embedded_worker_->Stop();
|
| return;
|
| }
|
| @@ -1454,12 +1469,12 @@ void ServiceWorkerVersion::OnTimeoutTimer() {
|
| }
|
| requests_.pop();
|
| }
|
| - if (stop_for_timeout && running_status() != STOPPING)
|
| + if (stop_for_timeout && running_status() != RunningStatus::STOPPING)
|
| embedded_worker_->Stop();
|
|
|
| // For the timeouts below, there are no callbacks to timeout so there is
|
| // nothing more to do if the worker is already stopping.
|
| - if (running_status() == STOPPING)
|
| + if (running_status() == RunningStatus::STOPPING)
|
| return;
|
|
|
| // The worker has been idle for longer than a certain period.
|
| @@ -1474,12 +1489,14 @@ void ServiceWorkerVersion::OnTimeoutTimer() {
|
| }
|
|
|
| ServiceWorkerStatusCode ServiceWorkerVersion::PingWorker() {
|
| - DCHECK(running_status() == STARTING || running_status() == RUNNING);
|
| + DCHECK(running_status() == RunningStatus::STARTING ||
|
| + running_status() == RunningStatus::RUNNING);
|
| return embedded_worker_->SendMessage(ServiceWorkerMsg_Ping());
|
| }
|
|
|
| void ServiceWorkerVersion::OnPingTimeout() {
|
| - DCHECK(running_status() == STARTING || running_status() == RUNNING);
|
| + DCHECK(running_status() == RunningStatus::STARTING ||
|
| + running_status() == RunningStatus::RUNNING);
|
| // TODO(falken): Show a message to the developer that the SW was stopped due
|
| // to timeout (crbug.com/457968). Also, change the error code to
|
| // SERVICE_WORKER_ERROR_TIMEOUT.
|
| @@ -1489,8 +1506,8 @@ void ServiceWorkerVersion::OnPingTimeout() {
|
| void ServiceWorkerVersion::StopWorkerIfIdle() {
|
| if (HasInflightRequests() && !ping_controller_->IsTimedOut())
|
| return;
|
| - if (running_status() == STOPPED || running_status() == STOPPING ||
|
| - !stop_callbacks_.empty()) {
|
| + if (running_status() == RunningStatus::STOPPED ||
|
| + running_status() == RunningStatus::STOPPING || !stop_callbacks_.empty()) {
|
| return;
|
| }
|
|
|
| @@ -1538,7 +1555,7 @@ void ServiceWorkerVersion::RecordStartWorkerResult(
|
| // Build an artifical JavaScript exception to show in the ServiceWorker
|
| // log for developers; it's not user-facing so it's not a localized resource.
|
| std::string message = "ServiceWorker startup timed out. ";
|
| - if (running_status != EmbeddedWorkerInstance::STARTING) {
|
| + if (running_status != EmbeddedWorkerInstance::Status::STARTING) {
|
| message.append("The worker had unexpected status: ");
|
| message.append(EmbeddedWorkerInstance::StatusToString(running_status));
|
| } else {
|
| @@ -1639,7 +1656,7 @@ void ServiceWorkerVersion::FoundRegistrationForUpdate(
|
|
|
| void ServiceWorkerVersion::OnStoppedInternal(
|
| EmbeddedWorkerInstance::Status old_status) {
|
| - DCHECK_EQ(STOPPED, running_status());
|
| + DCHECK_EQ(RunningStatus::STOPPED, running_status());
|
| scoped_refptr<ServiceWorkerVersion> protect;
|
| if (!in_dtor_)
|
| protect = this;
|
| @@ -1647,9 +1664,10 @@ void ServiceWorkerVersion::OnStoppedInternal(
|
| DCHECK(metrics_);
|
| metrics_.reset();
|
|
|
| - bool should_restart = !is_redundant() && !start_callbacks_.empty() &&
|
| - (old_status != EmbeddedWorkerInstance::STARTING) &&
|
| - !in_dtor_ && !ping_controller_->IsTimedOut();
|
| + bool should_restart =
|
| + !is_redundant() && !start_callbacks_.empty() &&
|
| + (old_status != EmbeddedWorkerInstance::Status::STARTING) && !in_dtor_ &&
|
| + !ping_controller_->IsTimedOut();
|
|
|
| if (!stop_time_.is_null()) {
|
| TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::StopWorker",
|
| @@ -1702,7 +1720,7 @@ void ServiceWorkerVersion::OnMojoConnectionError(const char* service_name) {
|
| }
|
|
|
| void ServiceWorkerVersion::OnBeginEvent() {
|
| - if (should_exclude_from_uma_ || running_status() != RUNNING ||
|
| + if (should_exclude_from_uma_ || running_status() != RunningStatus::RUNNING ||
|
| idle_time_.is_null()) {
|
| return;
|
| }
|
|
|