Skip to content

Commit

Permalink
service worker: Add instrumentation for crash on bad timing.
Browse files Browse the repository at this point in the history
The crash is a renderer kill when the browser receives timing data
that goes back in time. TimeTicks is supposed to be monotonically
increasing.

Bug: 881100
Change-Id: I3337b3e4102dfebfb3d2eeeb28cef85ecaf5e4ea
Reviewed-on: https://chromium-review.googlesource.com/c/1322251
Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605989}
  • Loading branch information
mfalken authored and Commit Bot committed Nov 7, 2018
1 parent faa9ab4 commit 599b266
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions content/renderer/service_worker/service_worker_context_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -737,13 +737,34 @@ void ServiceWorkerContextClient::WorkerContextStarted(
void ServiceWorkerContextClient::WillEvaluateScript() {
DCHECK(worker_task_runner_->RunsTasksInCurrentSequence());
start_timing_->script_evaluation_start_time = base::TimeTicks::Now();

// Temporary CHECK for https://crbug.com/881100
int64_t t0 =
start_timing_->start_worker_received_time.since_origin().InMicroseconds();
int64_t t1 = start_timing_->script_evaluation_start_time.since_origin()
.InMicroseconds();
base::debug::Alias(&t0);
base::debug::Alias(&t1);
CHECK_LE(start_timing_->start_worker_received_time,
start_timing_->script_evaluation_start_time);

(*instance_host_)->OnScriptEvaluationStart();
}

void ServiceWorkerContextClient::DidEvaluateScript(bool success) {
DCHECK(worker_task_runner_->RunsTasksInCurrentSequence());
start_timing_->script_evaluation_end_time = base::TimeTicks::Now();

// Temporary CHECK for https://crbug.com/881100
int64_t t0 = start_timing_->script_evaluation_start_time.since_origin()
.InMicroseconds();
int64_t t1 =
start_timing_->script_evaluation_end_time.since_origin().InMicroseconds();
base::debug::Alias(&t0);
base::debug::Alias(&t1);
CHECK_LE(start_timing_->script_evaluation_start_time,
start_timing_->script_evaluation_end_time);

blink::mojom::ServiceWorkerStartStatus status =
success ? blink::mojom::ServiceWorkerStartStatus::kNormalCompletion
: blink::mojom::ServiceWorkerStartStatus::kAbruptCompletion;
Expand Down Expand Up @@ -1368,6 +1389,21 @@ void ServiceWorkerContextClient::SendWorkerStarted(
service_worker_version_id_, service_worker_scope_, script_url_);
}

// Temporary CHECK for https://crbug.com/881100
int64_t t0 =
start_timing_->start_worker_received_time.since_origin().InMicroseconds();
int64_t t1 = start_timing_->script_evaluation_start_time.since_origin()
.InMicroseconds();
int64_t t2 =
start_timing_->script_evaluation_end_time.since_origin().InMicroseconds();
base::debug::Alias(&t0);
base::debug::Alias(&t1);
base::debug::Alias(&t2);
CHECK_LE(start_timing_->start_worker_received_time,
start_timing_->script_evaluation_start_time);
CHECK_LE(start_timing_->script_evaluation_start_time,
start_timing_->script_evaluation_end_time);

(*instance_host_)
->OnStarted(status, WorkerThread::GetCurrentId(),
std::move(start_timing_));
Expand Down

0 comments on commit 599b266

Please sign in to comment.