Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_registration_handle.h
blob9439027041b405cd82fbf7cf3c6242d7121d2ccc
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.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_HANDLE_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_HANDLE_H_
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"
15 namespace content {
17 class ServiceWorkerContextCore;
18 class ServiceWorkerDispatcherHost;
19 class ServiceWorkerVersion;
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 CONTENT_EXPORT ServiceWorkerRegistrationHandle(
30 base::WeakPtr<ServiceWorkerContextCore> context,
31 ServiceWorkerDispatcherHost* dispatcher_host,
32 int provider_id,
33 ServiceWorkerRegistration* registration);
34 virtual ~ServiceWorkerRegistrationHandle();
36 ServiceWorkerRegistrationObjectInfo GetObjectInfo();
37 ServiceWorkerObjectInfo CreateServiceWorkerHandleAndPass(
38 ServiceWorkerVersion* version);
40 bool HasNoRefCount() const { return ref_count_ <= 0; }
41 void IncrementRefCount();
42 void DecrementRefCount();
44 int provider_id() const { return provider_id_; }
45 int handle_id() const { return handle_id_; }
47 ServiceWorkerRegistration* registration() { return registration_.get(); }
49 private:
50 // ServiceWorkerRegistration::Listener overrides.
51 void OnVersionAttributesChanged(
52 ServiceWorkerRegistration* registration,
53 ChangedVersionAttributesMask changed_mask,
54 const ServiceWorkerRegistrationInfo& info) override;
55 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override;
56 void OnUpdateFound(ServiceWorkerRegistration* registration) override;
58 // Sets the corresponding version field to the given version or if the given
59 // version is NULL, clears the field.
60 void SetVersionAttributes(
61 ServiceWorkerVersion* installing_version,
62 ServiceWorkerVersion* waiting_version,
63 ServiceWorkerVersion* active_version);
65 // Clears all version fields.
66 void ClearVersionAttributes();
68 base::WeakPtr<ServiceWorkerContextCore> context_;
69 ServiceWorkerDispatcherHost* dispatcher_host_;
70 const int provider_id_;
71 const int handle_id_;
72 int ref_count_; // Created with 1.
74 scoped_refptr<ServiceWorkerRegistration> registration_;
75 scoped_refptr<ServiceWorkerVersion> installing_version_;
76 scoped_refptr<ServiceWorkerVersion> waiting_version_;
77 scoped_refptr<ServiceWorkerVersion> active_version_;
79 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistrationHandle);
82 } // namespace content
84 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_HANDLE_H_