Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ | |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/gtest_prod_util.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "content/browser/service_worker/service_worker_version.h" | |
| 14 #include "content/common/content_export.h" | |
| 15 | |
| 16 class GURL; | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 class ServiceWorkerVersion; | |
| 21 | |
| 22 // This class manages all persistence of service workers: | |
| 23 // - Registrations | |
| 24 // - Mapping of caches to registrations / versions | |
| 25 // | |
| 26 // This is the place where we manage simultaneous | |
| 27 // requests for the same registrations and caches, making sure that | |
| 28 // two pages that are registering the same pattern at the same time | |
| 29 // have their registrations coalesced rather than overwriting each | |
| 30 // other. | |
| 31 // | |
| 32 // This class also manages the state of the upgrade process, which | |
| 33 // includes managing which ServiceWorkerVersion is "active" vs "in | |
| 34 // waiting" (or "pending") | |
| 35 class CONTENT_EXPORT ServiceWorkerRegistration | |
| 36 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>) { | |
| 37 public: | |
| 38 ServiceWorkerRegistration(const GURL& pattern, | |
| 39 const GURL& script_url, | |
| 40 int64 registration_id); | |
| 41 | |
| 42 void Shutdown(); | |
| 43 bool is_shutdown() const { return is_shutdown_; } | |
| 44 | |
| 45 int64 id() const { return registration_id_; } | |
| 46 const GURL& script_url() const { return script_url_; } | |
| 47 const GURL& pattern() const { return pattern_; } | |
| 48 | |
| 49 scoped_refptr<ServiceWorkerVersion> active_version() const { | |
| 50 DCHECK(!is_shutdown_); | |
| 51 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
| |
| 52 } | |
| 53 | |
| 54 scoped_refptr<ServiceWorkerVersion> pending_version() const { | |
| 55 DCHECK(!is_shutdown_); | |
| 56 return pending_version_; | |
| 57 } | |
| 58 | |
| 59 void set_active_version(const scoped_refptr<ServiceWorkerVersion>& version) { | |
| 60 DCHECK(!is_shutdown_); | |
| 61 active_version_ = version; | |
| 62 } | |
| 63 | |
| 64 void set_pending_version(const scoped_refptr<ServiceWorkerVersion>& version) { | |
| 65 DCHECK(!is_shutdown_); | |
| 66 pending_version_ = version; | |
| 67 } | |
| 68 | |
| 69 // The final synchronous switchover after all events have been | |
| 70 // fired, and the old "active version" is being shut down. | |
| 71 void ActivatePendingVersion(); | |
| 72 | |
| 73 private: | |
| 74 virtual ~ServiceWorkerRegistration(); | |
| 75 friend class base::RefCounted<ServiceWorkerRegistration>; | |
| 76 | |
| 77 const GURL& pattern_; | |
| 78 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.
| |
| 79 const int64 registration_id_; | |
| 80 | |
| 81 scoped_refptr<ServiceWorkerVersion> active_version_; | |
| 82 scoped_refptr<ServiceWorkerVersion> pending_version_; | |
| 83 | |
| 84 bool is_shutdown_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); | |
| 87 }; | |
| 88 } // namespace content | |
| 89 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ | |
| OLD | NEW |