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

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

Issue 113133013: Refactor job coordination into a separate class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove WeakPtr usage from Storage Created 6 years, 11 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_job_coordinator.cc
diff --git a/content/browser/service_worker/service_worker_job_coordinator.cc b/content/browser/service_worker/service_worker_job_coordinator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..043362acae7290a66aff40c45d58acebf2dd961a
--- /dev/null
+++ b/content/browser/service_worker/service_worker_job_coordinator.cc
@@ -0,0 +1,72 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/service_worker/service_worker_job_coordinator.h"
+
+#include "content/browser/service_worker/service_worker_registration.h"
+
+namespace content {
+
+ServiceWorkerJobCoordinator::ServiceWorkerJobCoordinator(
+ ServiceWorkerStorage* storage)
+ : storage_(storage), weak_factory_(this) {}
+
+ServiceWorkerJobCoordinator::~ServiceWorkerJobCoordinator() {}
+
+void ServiceWorkerJobCoordinator::Register(
+ const GURL& pattern,
+ const GURL& script_url,
+ const ServiceWorkerRegisterJob::RegistrationCallback& callback) {
+ scoped_ptr<ServiceWorkerRegisterJob> job(new ServiceWorkerRegisterJob(
+ storage_,
+ base::Bind(&ServiceWorkerJobCoordinator::RegisterComplete,
+ weak_factory_.GetWeakPtr(),
+ callback)));
+ job->StartRegister(pattern, script_url);
+ registration_jobs_.push_back(job.release());
+}
+
+void ServiceWorkerJobCoordinator::Unregister(
+ const GURL& pattern,
+ const ServiceWorkerRegisterJob::UnregistrationCallback& callback) {
+ scoped_ptr<ServiceWorkerRegisterJob> job(new ServiceWorkerRegisterJob(
+ storage_,
+ base::Bind(&ServiceWorkerJobCoordinator::UnregisterComplete,
+ weak_factory_.GetWeakPtr(),
+ callback)));
+ job->StartUnregister(pattern);
+ registration_jobs_.push_back(job.release());
+}
+
+void ServiceWorkerJobCoordinator::EraseJob(ServiceWorkerRegisterJob* job) {
+ ScopedVector<ServiceWorkerRegisterJob>::iterator job_position =
+ registration_jobs_.begin();
+ for (; job_position != registration_jobs_.end(); ++job_position) {
+ if (*job_position == job) {
+ registration_jobs_.erase(job_position);
+ return;
+ }
+ }
+ NOTREACHED() << "Deleting non-existent job. ";
+}
+
+void ServiceWorkerJobCoordinator::RegisterComplete(
+ const ServiceWorkerRegisterJob::RegistrationCallback& callback,
+ ServiceWorkerRegisterJob* job,
+ ServiceWorkerRegistrationStatus status,
+ ServiceWorkerRegistration* registration) {
+ callback.Run(status, registration);
+ EraseJob(job);
+}
+
+void ServiceWorkerJobCoordinator::UnregisterComplete(
+ const ServiceWorkerRegisterJob::UnregistrationCallback& callback,
+ ServiceWorkerRegisterJob* job,
+ ServiceWorkerRegistrationStatus status,
+ ServiceWorkerRegistration* previous_registration) {
+ callback.Run(status);
+ EraseJob(job);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698