Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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_HANDLE_H_ | |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_HANDLE_H_ | |
| 7 | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "content/browser/service_worker/service_worker_registration.h" | |
| 12 #include "content/browser/service_worker/service_worker_version.h" | |
| 13 #include "content/common/service_worker/service_worker_types.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 class ServiceWorkerContextCore; | |
| 18 class ServiceWorkerDispatcherHost; | |
| 19 class ServiceWorkerVersion; | |
| 20 | |
| 21 // Roughly Corresponds to one ServiceWorkerRegistration object in the renderer | |
| 22 // process (WebServiceWorkerRegistrationImpl). | |
| 23 // Has references to the corresponding ServiceWorkerRegistration and | |
| 24 // ServiceWorkerVersions (therefore they're guaranteed to be alive while this | |
| 25 // handle is around). | |
| 26 class ServiceWorkerRegistrationHandle | |
| 27 : public ServiceWorkerRegistration::Listener { | |
| 28 public: | |
| 29 ServiceWorkerRegistrationHandle( | |
| 30 base::WeakPtr<ServiceWorkerContextCore> context, | |
| 31 ServiceWorkerDispatcherHost* dispatcher_host, | |
| 32 int thread_id, | |
| 33 int provider_id, | |
| 34 ServiceWorkerRegistration* registration); | |
| 35 virtual ~ServiceWorkerRegistrationHandle(); | |
| 36 | |
| 37 bool HasNoRefCount() const { return ref_count_ <= 0; } | |
| 38 void IncrementRefCount(); | |
| 39 void DecrementRefCount(); | |
| 40 | |
| 41 int thread_id() const { return thread_id_; } | |
|
michaeln
2014/08/13 04:18:17
since thread_id is always the main thread id in bl
nhiroki
2014/08/13 13:15:05
Done.
| |
| 42 int provider_id() const { return provider_id_; } | |
| 43 int handle_id() const { return handle_id_; } | |
| 44 | |
| 45 ServiceWorkerRegistration* registration() { return registration_.get(); } | |
| 46 | |
| 47 private: | |
| 48 // ServiceWorkerRegistration::Listener overrides. | |
| 49 virtual void OnVersionAttributesChanged( | |
| 50 ServiceWorkerRegistration* registration, | |
| 51 ChangedVersionAttributesMask changed_mask, | |
| 52 const ServiceWorkerRegistrationInfo& info) OVERRIDE; | |
| 53 virtual void OnRegistrationFailed( | |
| 54 ServiceWorkerRegistration* registration) OVERRIDE; | |
| 55 | |
| 56 // Sets the corresponding version field to the given version or if the given | |
| 57 // version is NULL, clears the field. | |
| 58 void SetVersionAttributes( | |
| 59 ServiceWorkerVersion* installing_version, | |
| 60 ServiceWorkerVersion* waiting_version, | |
| 61 ServiceWorkerVersion* active_version); | |
| 62 | |
| 63 // Clears all version fields. | |
| 64 void ClearVersionAttributes(); | |
| 65 | |
| 66 ServiceWorkerObjectInfo CreateServiceWorkerHandleAndPass( | |
| 67 ServiceWorkerVersion* version); | |
| 68 | |
| 69 base::WeakPtr<ServiceWorkerContextCore> context_; | |
| 70 ServiceWorkerDispatcherHost* dispatcher_host_; | |
| 71 const int thread_id_; | |
| 72 const int provider_id_; | |
| 73 const int handle_id_; | |
| 74 int ref_count_; // Created with 1. | |
| 75 | |
| 76 scoped_refptr<ServiceWorkerRegistration> registration_; | |
| 77 scoped_refptr<ServiceWorkerVersion> installing_version_; | |
| 78 scoped_refptr<ServiceWorkerVersion> waiting_version_; | |
| 79 scoped_refptr<ServiceWorkerVersion> active_version_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistrationHandle); | |
| 82 }; | |
| 83 | |
| 84 } // namespace content | |
| 85 | |
| 86 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_HANDLE_H_ | |
| OLD | NEW |