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

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

Issue 70683002: Stub out ServiceWorkerRegistration and Version classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update to ToT Created 7 years, 1 month 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_registration.h
diff --git a/content/browser/service_worker/service_worker_registration.h b/content/browser/service_worker/service_worker_registration.h
new file mode 100644
index 0000000000000000000000000000000000000000..1208ee3181dc78d7a94d485b49228e6950d8aa34
--- /dev/null
+++ b/content/browser/service_worker/service_worker_registration.h
@@ -0,0 +1,89 @@
+// Copyright (c) 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.
+
+#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_
+#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_
+
+#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/browser/service_worker/service_worker_version.h"
+#include "content/common/content_export.h"
+
+class GURL;
+
+namespace content {
+
+class ServiceWorkerVersion;
+
+// This class manages all persistence of service workers:
+// - Registrations
+// - Mapping of caches to registrations / versions
+//
+// This is the place where we manage simultaneous
+// requests for the same registrations and caches, making sure that
+// two pages that are registering the same pattern at the same time
+// have their registrations coalesced rather than overwriting each
+// other.
+//
+// This class also manages the state of the upgrade process, which
+// includes managing which ServiceWorkerVersion is "active" vs "in
+// waiting" (or "pending")
+class CONTENT_EXPORT ServiceWorkerRegistration
+ : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>) {
+ public:
+ ServiceWorkerRegistration(const GURL& pattern,
+ const GURL& script_url,
+ int64 registration_id);
+
+ void Shutdown();
+ bool is_shutdown() const { return is_shutdown_; }
+
+ int64 id() const { return registration_id_; }
+ const GURL& script_url() const { return script_url_; }
+ const GURL& pattern() const { return pattern_; }
+
+ scoped_refptr<ServiceWorkerVersion> active_version() const {
+ DCHECK(!is_shutdown_);
+ return active_version_.get();
michaeln 2013/11/14 00:27:33 You said... "I mean if we're using refcounting, we
alecflett 2013/11/14 18:35:46 While I disagree on both of these points, I defer
+ }
+
+ scoped_refptr<ServiceWorkerVersion> pending_version() const {
+ DCHECK(!is_shutdown_);
+ return pending_version_;
+ }
+
+ void set_active_version(const scoped_refptr<ServiceWorkerVersion>& version) {
+ DCHECK(!is_shutdown_);
+ active_version_ = version;
+ }
+
+ void set_pending_version(const scoped_refptr<ServiceWorkerVersion>& version) {
+ DCHECK(!is_shutdown_);
+ pending_version_ = version;
+ }
+
+ // The final synchronous switchover after all events have been
+ // fired, and the old "active version" is being shut down.
+ void ActivatePendingVersion();
+
+ private:
+ virtual ~ServiceWorkerRegistration();
+ friend class base::RefCounted<ServiceWorkerRegistration>;
+
+ const GURL& pattern_;
+ const GURL& script_url_;
michaeln 2013/11/14 00:27:33 these &'s are neat looking characters, but please
alecflett 2013/11/14 18:35:46 woah. Good catch. Done.
+ const int64 registration_id_;
+
+ scoped_refptr<ServiceWorkerVersion> active_version_;
+ scoped_refptr<ServiceWorkerVersion> pending_version_;
+
+ bool is_shutdown_;
+
+ DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration);
+};
+} // namespace content
+#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_

Powered by Google App Engine
This is Rietveld 408576698