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

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

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.h
diff --git a/content/browser/service_worker/service_worker_register_job.h b/content/browser/service_worker/service_worker_register_job.h
index 6278382bf383ca3515986086ea038eefd77946de..45006702d3dd7bc82776e90b779591292154b2a4 100644
--- a/content/browser/service_worker/service_worker_register_job.h
+++ b/content/browser/service_worker/service_worker_register_job.h
@@ -11,10 +11,17 @@
namespace content {
+class ServiceWorkerJobCoordinator;
+
// A ServiceWorkerRegisterJob lives only for the lifetime of a single
// registration or unregistration.
class ServiceWorkerRegisterJob {
public:
+ enum RegistrationType {
+ REGISTER,
+ UNREGISTER,
+ };
+
typedef base::Callback<void(ServiceWorkerRegistrationStatus status,
const scoped_refptr<ServiceWorkerRegistration>&
registration)> RegistrationCallback;
@@ -29,9 +36,32 @@ class ServiceWorkerRegisterJob {
// All type of jobs (Register and Unregister) complete through a
// single call to this callback on the IO thread.
ServiceWorkerRegisterJob(const base::WeakPtr<ServiceWorkerStorage>& storage,
- const RegistrationCompleteCallback& callback);
+ ServiceWorkerJobCoordinator* coordinator,
+ const GURL& pattern,
+ const GURL& script_url,
+ RegistrationType type);
~ServiceWorkerRegisterJob();
+ void AddCallback(const RegistrationCompleteCallback& callback);
+
+ // hack for now. Could be virtual
+ void Start() {
+ if (type_ == REGISTER)
+ StartRegister();
+ else
+ StartUnregister();
+ running_ = true;
+ }
kinuko 2014/01/08 08:38:36 Can you move this to .cc ?
alecflett 2014/01/08 23:59:16 oops! meant to do that before uploading. Done.
+
+ const GURL& pattern() const { return pattern_; }
+ const GURL& script_url() const {
+ DCHECK(type_ == REGISTER);
kinuko 2014/01/08 08:38:36 We seem to call this for UNREGISTER case too?
alecflett 2014/01/08 23:59:16 the && short-circuits this call) But we never sho
+ return script_url_;
+ }
+ RegistrationType type() const { return type_; }
+ bool is_running() const { return running_; }
kinuko 2014/01/08 08:38:36 This doesn't seem to be used, or relying on this f
alecflett 2014/01/08 23:59:16 this is mainly for tests - I thought I had an EXPE
+
+ private:
// The Registration flow includes most or all of the following,
// depending on what is already registered:
// - creating a ServiceWorkerRegistration instance if there isn't
@@ -44,25 +74,20 @@ class ServiceWorkerRegisterJob {
// - Waiting for older ServiceWorkerVersions to deactivate
// - designating the new version to be the 'active' version
// This method should be called once and only once per job.
- void StartRegister(const GURL& pattern, const GURL& script_url);
+ void StartRegister();
// The Unregistration process is primarily cleanup, removing
// everything that was created during the Registration process,
// including the ServiceWorkerRegistration itself.
// This method should be called once and only once per job.
- void StartUnregister(const GURL& pattern);
+ void StartUnregister();
- private:
// These are all steps in the registration and unregistration pipeline.
void RegisterPatternAndContinue(
- const GURL& pattern,
- const GURL& script_url,
const RegistrationCallback& callback,
ServiceWorkerRegistrationStatus previous_status);
void UnregisterPatternAndContinue(
- const GURL& pattern,
- const GURL& script_url,
const UnregistrationCallback& callback,
bool found,
ServiceWorkerRegistrationStatus previous_status,
@@ -75,9 +100,18 @@ class ServiceWorkerRegisterJob {
ServiceWorkerRegistrationStatus status,
const scoped_refptr<ServiceWorkerRegistration>& registration);
+ void RunCallbacks(
+ ServiceWorkerRegistrationStatus status,
+ const scoped_refptr<ServiceWorkerRegistration>& registration);
+
const base::WeakPtr<ServiceWorkerStorage> storage_;
- const RegistrationCompleteCallback callback_;
+ ServiceWorkerJobCoordinator* coordinator_;
+ const GURL pattern_;
+ GURL script_url_; // should be unset for register case
+ std::vector<RegistrationCompleteCallback> callbacks_;
base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_;
+ const RegistrationType type_;
+ bool running_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob);
};

Powered by Google App Engine
This is Rietveld 408576698