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

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

Issue 1029553002: [DevTools] Introduce Unregister/Start/Stop/Inspect buttons to ServiceWorkersView [1/2 chromium] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix indent Created 5 years, 9 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/service_worker_context_wrapper.cc
diff --git a/content/browser/service_worker/service_worker_context_wrapper.cc b/content/browser/service_worker/service_worker_context_wrapper.cc
index 5faa7d0323f8aa25572c6afc5fe986e266b8c91d..3edcb54c622516e141d2255eec60d9daf4f4af90 100644
--- a/content/browser/service_worker/service_worker_context_wrapper.cc
+++ b/content/browser/service_worker/service_worker_context_wrapper.cc
@@ -22,6 +22,7 @@
#include "content/browser/service_worker/service_worker_quota_client.h"
#include "content/browser/service_worker/service_worker_request_handler.h"
#include "content/browser/service_worker/service_worker_utils.h"
+#include "content/browser/service_worker/service_worker_version.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
@@ -45,6 +46,30 @@ void RunSoon(const base::Closure& closure) {
base::MessageLoop::current()->PostTask(FROM_HERE, closure);
}
+void WorkerStarted(const ServiceWorkerContextWrapper::StatusCallback& callback,
+ ServiceWorkerStatusCode status) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, status));
+}
+
+void StartActiveWorkerOnIO(
+ const ServiceWorkerContextWrapper::StatusCallback& callback,
+ ServiceWorkerStatusCode status,
+ const scoped_refptr<ServiceWorkerRegistration>& registration) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (status == SERVICE_WORKER_OK) {
+ // Pass the reference of |registration| to WorkerStarted callback to prevent
+ // it from being deleted while starting the worker. If the refcount of
+ // |registration| is 1, it will be deleted after WorkerStarted is called.
+ registration->active_version()->StartWorker(
+ base::Bind(WorkerStarted, callback));
+ return;
+ }
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, SERVICE_WORKER_ERROR_NOT_FOUND));
+}
+
} // namespace
void ServiceWorkerContext::AddExcludedHeadersForFetchEvent(
@@ -220,6 +245,27 @@ void ServiceWorkerContextWrapper::UnregisterServiceWorker(
base::Bind(&FinishUnregistrationOnIO, continuation));
}
+void ServiceWorkerContextWrapper::StartServiceWorker(
+ const GURL& pattern,
+ const StatusCallback& callback) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this,
+ pattern, callback));
+ return;
+ }
+ if (!context_core_.get()) {
+ LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED));
+ return;
+ }
+ context_core_->storage()->FindRegistrationForPattern(
+ pattern, base::Bind(&StartActiveWorkerOnIO, callback));
+}
+
static void DidFindRegistrationForDocument(
const net::CompletionCallback& callback,
ServiceWorkerStatusCode status,

Powered by Google App Engine
This is Rietveld 408576698