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

Unified Diff: content/browser/service_worker/embedded_worker_instance.cc

Issue 1327723005: Fix crash during EmbeddedWorkerInstance startup sequence failures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix asan Created 5 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/embedded_worker_instance.cc
diff --git a/content/browser/service_worker/embedded_worker_instance.cc b/content/browser/service_worker/embedded_worker_instance.cc
index 68e473dcebc15d57c5ee825054bcb4a78ba2ea23..b33ee1b1c8bc80841c74ba5123bff5c64d178d38 100644
--- a/content/browser/service_worker/embedded_worker_instance.cc
+++ b/content/browser/service_worker/embedded_worker_instance.cc
@@ -155,6 +155,7 @@ void EmbeddedWorkerInstance::Start(int64 service_worker_version_id,
const StatusCallback& callback) {
if (!context_) {
callback.Run(SERVICE_WORKER_ERROR_ABORT);
+ // |this| may be destroyed by the callback.
return;
}
DCHECK(status_ == STOPPED);
@@ -284,11 +285,7 @@ void EmbeddedWorkerInstance::ProcessAllocated(
params.get(),
"Status", status);
if (status != SERVICE_WORKER_OK) {
- Status old_status = status_;
- status_ = STOPPED;
- service_registry_.reset();
- callback.Run(status);
- FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped(old_status));
+ OnStartFailed(callback, status);
return;
}
const int64 service_worker_version_id = params->service_worker_version_id;
@@ -318,8 +315,7 @@ void EmbeddedWorkerInstance::SendStartWorker(
// process, making process_id_ and other state invalid. If that happened,
// abort instead of trying to send the IPC.
if (status_ != STARTING) {
- callback.Run(SERVICE_WORKER_ERROR_ABORT);
- ReleaseProcess();
+ OnStartFailed(callback, SERVICE_WORKER_ERROR_ABORT);
return;
}
@@ -354,7 +350,7 @@ void EmbeddedWorkerInstance::SendStartWorker(
ServiceWorkerStatusCode status =
registry_->SendStartWorker(params.Pass(), process_id_);
if (status != SERVICE_WORKER_OK) {
- callback.Run(status);
+ OnStartFailed(callback, status);
nhiroki 2015/09/17 06:14:13 I guess this could fix issue 531345. Before this p
return;
}
DCHECK(start_callback_.is_null());
@@ -410,9 +406,11 @@ void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) {
UMA_HISTOGRAM_TIMES("EmbeddedWorkerInstance.ScriptEvaluate",
base::TimeTicks::Now() - start_timing_);
}
- start_callback_.Run(success ? SERVICE_WORKER_OK
- : SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED);
+ StatusCallback callback = start_callback_;
start_callback_.Reset();
+ callback.Run(success ? SERVICE_WORKER_OK
+ : SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED);
+ // |this| may be destroyed by the callback.
}
void EmbeddedWorkerInstance::OnStarted() {
@@ -504,6 +502,17 @@ void EmbeddedWorkerInstance::ReleaseProcess() {
start_callback_.Reset();
}
+void EmbeddedWorkerInstance::OnStartFailed(const StatusCallback& callback,
+ ServiceWorkerStatusCode status) {
+ Status old_status = status_;
+ ReleaseProcess();
+ base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr();
+ callback.Run(status);
+ if (weak_this && old_status != STOPPED)
+ FOR_EACH_OBSERVER(Listener, weak_this->listener_list_,
+ OnStopped(old_status));
kinuko 2015/09/13 08:41:11 nit: would be better to update the comment for Lis
+}
+
// static
std::string EmbeddedWorkerInstance::StatusToString(Status status) {
switch (status) {

Powered by Google App Engine
This is Rietveld 408576698