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

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

Issue 126603002: Implement registration job ordering (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments in tests 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_register_job.cc
diff --git a/content/browser/service_worker/service_worker_register_job.cc b/content/browser/service_worker/service_worker_register_job.cc
index 86976d4359c019f4a6b48320116b0d213a5b5176..6cd09b9bc927a6b5155c57a57de05932d2db4c1b 100644
--- a/content/browser/service_worker/service_worker_register_job.cc
+++ b/content/browser/service_worker/service_worker_register_job.cc
@@ -4,6 +4,7 @@
#include "content/browser/service_worker/service_worker_register_job.h"
+#include "content/browser/service_worker/service_worker_job_coordinator.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/public/browser/browser_thread.h"
#include "url/gurl.h"
@@ -12,13 +13,26 @@ namespace content {
ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(
const base::WeakPtr<ServiceWorkerStorage>& storage,
- const RegistrationCompleteCallback& callback)
- : storage_(storage), callback_(callback), weak_factory_(this) {}
+ ServiceWorkerJobCoordinator* coordinator,
+ const GURL& pattern,
+ const GURL& script_url,
+ RegistrationType type)
+ : storage_(storage),
+ coordinator_(coordinator),
+ pattern_(pattern),
+ script_url_(script_url),
+ weak_factory_(this),
+ type_(type) {}
kinuko 2014/01/08 08:38:36 running_ is not initialized (or I hope we can just
alecflett 2014/01/08 23:59:16 Done.
ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob() {}
-void ServiceWorkerRegisterJob::StartRegister(const GURL& pattern,
- const GURL& script_url) {
+void ServiceWorkerRegisterJob::AddCallback(
+ const RegistrationCompleteCallback& callback) {
+ callbacks_.push_back(callback);
+}
+
+void ServiceWorkerRegisterJob::StartRegister() {
+
// Set up a chain of callbacks, in reverse order. Each of these
// callbacks may be called asynchronously by the previous callback.
RegistrationCallback finish_registration(base::Bind(
@@ -27,21 +41,17 @@ void ServiceWorkerRegisterJob::StartRegister(const GURL& pattern,
UnregistrationCallback register_new(
base::Bind(&ServiceWorkerRegisterJob::RegisterPatternAndContinue,
weak_factory_.GetWeakPtr(),
- pattern,
- script_url,
finish_registration));
ServiceWorkerStorage::FindRegistrationCallback unregister_old(
base::Bind(&ServiceWorkerRegisterJob::UnregisterPatternAndContinue,
weak_factory_.GetWeakPtr(),
- pattern,
- script_url,
register_new));
- storage_->FindRegistrationForPattern(pattern, unregister_old);
+ storage_->FindRegistrationForPattern(pattern_, unregister_old);
}
-void ServiceWorkerRegisterJob::StartUnregister(const GURL& pattern) {
+void ServiceWorkerRegisterJob::StartUnregister() {
// Set up a chain of callbacks, in reverse order. Each of these
// callbacks may be called asynchronously by the previous callback.
UnregistrationCallback finish_unregistration(
@@ -51,16 +61,12 @@ void ServiceWorkerRegisterJob::StartUnregister(const GURL& pattern) {
ServiceWorkerStorage::FindRegistrationCallback unregister(
base::Bind(&ServiceWorkerRegisterJob::UnregisterPatternAndContinue,
weak_factory_.GetWeakPtr(),
- pattern,
- GURL(),
finish_unregistration));
- storage_->FindRegistrationForPattern(pattern, unregister);
+ storage_->FindRegistrationForPattern(pattern_, unregister);
}
void ServiceWorkerRegisterJob::RegisterPatternAndContinue(
- const GURL& pattern,
- const GURL& script_url,
const RegistrationCallback& callback,
ServiceWorkerRegistrationStatus previous_status) {
if (previous_status != REGISTRATION_OK) {
@@ -76,15 +82,13 @@ void ServiceWorkerRegisterJob::RegisterPatternAndContinue(
// TODO: Eventually RegisterInternal will be replaced by an asynchronous
// operation. Pass its resulting status through 'callback'.
scoped_refptr<ServiceWorkerRegistration> registration =
- storage_->RegisterInternal(pattern, script_url);
+ storage_->RegisterInternal(pattern_, script_url_);
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
base::Bind(callback, REGISTRATION_OK, registration));
}
void ServiceWorkerRegisterJob::UnregisterPatternAndContinue(
- const GURL& pattern,
- const GURL& new_script_url,
const UnregistrationCallback& callback,
bool found,
ServiceWorkerRegistrationStatus previous_status,
@@ -92,26 +96,41 @@ void ServiceWorkerRegisterJob::UnregisterPatternAndContinue(
// The previous registration may not exist, which is ok.
if (previous_status == REGISTRATION_OK && found &&
- (new_script_url.is_empty() ||
- previous_registration->script_url() != new_script_url)) {
+ (script_url_.is_empty() ||
+ previous_registration->script_url() != script_url_)) {
// TODO: Eventually UnregisterInternal will be replaced by an
// asynchronous operation. Pass its resulting status though
// 'callback'.
- storage_->UnregisterInternal(pattern);
+ storage_->UnregisterInternal(pattern_);
+ DCHECK(previous_registration->is_shutdown());
}
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(callback, previous_status));
}
+void ServiceWorkerRegisterJob::RunCallbacks(
+ ServiceWorkerRegistrationStatus status,
+ const scoped_refptr<ServiceWorkerRegistration>& registration) {
+ for (std::vector<RegistrationCompleteCallback>::iterator it =
+ callbacks_.begin();
+ it != callbacks_.end();
+ ++it) {
+ it->Run(this, status, registration);
+ }
+}
void ServiceWorkerRegisterJob::RegisterComplete(
ServiceWorkerRegistrationStatus status,
const scoped_refptr<ServiceWorkerRegistration>& registration) {
- callback_.Run(this, status, registration);
+ RunCallbacks(status, registration);
+ running_ = false;
+ coordinator_->FinishJob(this);
}
void ServiceWorkerRegisterJob::UnregisterComplete(
ServiceWorkerRegistrationStatus status) {
- callback_.Run(this, status, NULL);
+ RunCallbacks(status, NULL);
+ running_ = false;
+ coordinator_->FinishJob(this);
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698