OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "content/browser/service_worker/service_worker_registration.h" | |
13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
14 #include "content/common/service_worker/service_worker_types.h" | 15 #include "content/common/service_worker/service_worker_types.h" |
15 #include "content/public/common/resource_type.h" | 16 #include "content/public/common/resource_type.h" |
16 | 17 |
17 namespace IPC { | 18 namespace IPC { |
18 class Sender; | 19 class Sender; |
19 } | 20 } |
20 | 21 |
21 namespace webkit_blob { | 22 namespace webkit_blob { |
22 class BlobStorageContext; | 23 class BlobStorageContext; |
23 } | 24 } |
24 | 25 |
25 namespace content { | 26 namespace content { |
26 | 27 |
27 class ServiceWorkerContextCore; | 28 class ServiceWorkerContextCore; |
28 class ServiceWorkerDispatcherHost; | 29 class ServiceWorkerDispatcherHost; |
29 class ServiceWorkerRequestHandler; | 30 class ServiceWorkerRequestHandler; |
30 class ServiceWorkerVersion; | 31 class ServiceWorkerVersion; |
31 | 32 |
32 // This class is the browser-process representation of a service worker | 33 // This class is the browser-process representation of a service worker |
33 // provider. There is a provider per document and the lifetime of this | 34 // provider. There is a provider per document and the lifetime of this |
34 // object is tied to the lifetime of its document in the renderer process. | 35 // object is tied to the lifetime of its document in the renderer process. |
35 // This class holds service worker state that is scoped to an individual | 36 // This class holds service worker state that is scoped to an individual |
36 // document. | 37 // document. |
37 // | 38 // |
38 // Note this class can also host a running service worker, in which | 39 // Note this class can also host a running service worker, in which |
39 // case it will observe resource loads made directly by the service worker. | 40 // case it will observe resource loads made directly by the service worker. |
40 class CONTENT_EXPORT ServiceWorkerProviderHost | 41 class CONTENT_EXPORT ServiceWorkerProviderHost |
41 : public base::SupportsWeakPtr<ServiceWorkerProviderHost> { | 42 : public ServiceWorkerRegistration::Listener, |
43 public base::SupportsWeakPtr<ServiceWorkerProviderHost> { | |
42 public: | 44 public: |
43 ServiceWorkerProviderHost(int process_id, | 45 ServiceWorkerProviderHost(int process_id, |
44 int provider_id, | 46 int provider_id, |
45 base::WeakPtr<ServiceWorkerContextCore> context, | 47 base::WeakPtr<ServiceWorkerContextCore> context, |
46 ServiceWorkerDispatcherHost* dispatcher_host); | 48 ServiceWorkerDispatcherHost* dispatcher_host); |
47 ~ServiceWorkerProviderHost(); | 49 virtual ~ServiceWorkerProviderHost(); |
50 | |
51 // ServiceWorkerRegistration::Listener overrides. | |
michaeln
2014/08/05 23:57:15
please put this in the private section since this
nhiroki
2014/08/06 06:57:27
Moved.
| |
52 virtual void OnVersionAttributesChanged( | |
53 ServiceWorkerRegistration* registration, | |
54 ChangedVersionAttributesMask changed_mask, | |
55 const ServiceWorkerRegistrationInfo& info) OVERRIDE; | |
48 | 56 |
49 int process_id() const { return process_id_; } | 57 int process_id() const { return process_id_; } |
50 int provider_id() const { return provider_id_; } | 58 int provider_id() const { return provider_id_; } |
51 | 59 |
52 bool IsHostToRunningServiceWorker() { | 60 bool IsHostToRunningServiceWorker() { |
53 return running_hosted_version_ != NULL; | 61 return running_hosted_version_ != NULL; |
54 } | 62 } |
55 | 63 |
56 // Getters for the navigator.serviceWorker attribute values. | 64 // Getters for the navigator.serviceWorker attribute values. |
57 ServiceWorkerVersion* controlling_version() const { | 65 ServiceWorkerVersion* controlling_version() const { |
(...skipping 16 matching lines...) Expand all Loading... | |
74 } | 82 } |
75 | 83 |
76 void SetDocumentUrl(const GURL& url); | 84 void SetDocumentUrl(const GURL& url); |
77 const GURL& document_url() const { return document_url_; } | 85 const GURL& document_url() const { return document_url_; } |
78 | 86 |
79 // Associates |version| to the corresponding field or if |version| is NULL | 87 // Associates |version| to the corresponding field or if |version| is NULL |
80 // clears the field. | 88 // clears the field. |
81 void SetControllerVersion(ServiceWorkerVersion* version); | 89 void SetControllerVersion(ServiceWorkerVersion* version); |
82 void SetActiveVersion(ServiceWorkerVersion* version); | 90 void SetActiveVersion(ServiceWorkerVersion* version); |
83 void SetWaitingVersion(ServiceWorkerVersion* version); | 91 void SetWaitingVersion(ServiceWorkerVersion* version); |
84 void SetInstallingVersion(ServiceWorkerVersion* version); | 92 void SetInstallingVersion(ServiceWorkerVersion* version); |
michaeln
2014/08/05 23:57:15
I think these methods to alter versions on this cl
nhiroki
2014/08/06 06:57:27
Moved.
| |
85 | 93 |
86 // If |version| is the installing, waiting, or active version of this | 94 // If |version| is the installing, waiting, or active version of this |
87 // provider, the method will reset that field to NULL. | 95 // provider, the method will reset that field to NULL. |
88 void UnsetVersion(ServiceWorkerVersion* version); | 96 void UnsetVersion(ServiceWorkerVersion* version); |
89 | 97 |
98 // Associates to |registration| to listen for its version change events. | |
99 void SetRegistration(ServiceWorkerRegistration* registration); | |
michaeln
2014/08/05 23:57:15
We'll need to clear this association too in some c
nhiroki
2014/08/06 06:57:27
Done (please see my reply comment in service_worke
| |
100 | |
90 // Returns false if the version is not in the expected STARTING in our | 101 // Returns false if the version is not in the expected STARTING in our |
91 // process state. That would be indicative of a bad IPC message. | 102 // process state. That would be indicative of a bad IPC message. |
92 bool SetHostedVersionId(int64 versions_id); | 103 bool SetHostedVersionId(int64 versions_id); |
93 | 104 |
94 // Returns a handler for a request, the handler may return NULL if | 105 // Returns a handler for a request, the handler may return NULL if |
95 // the request doesn't require special handling. | 106 // the request doesn't require special handling. |
96 scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( | 107 scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( |
97 ResourceType resource_type, | 108 ResourceType resource_type, |
98 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context); | 109 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context); |
99 | 110 |
100 // Returns true if |version| can be associated with this provider. | 111 // Returns true if |version| can be associated with this provider. |
101 bool CanAssociateVersion(ServiceWorkerVersion* version); | 112 bool CanAssociateVersion(ServiceWorkerVersion* version); |
102 | 113 |
114 // Returns true if this provider hasn't been associated with any registration | |
115 // yet. | |
116 bool CanAssociateRegistration(); | |
117 | |
103 // Returns true if the context referred to by this host (i.e. |context_|) is | 118 // Returns true if the context referred to by this host (i.e. |context_|) is |
104 // still alive. | 119 // still alive. |
105 bool IsContextAlive(); | 120 bool IsContextAlive(); |
106 | 121 |
107 // Dispatches message event to the document. | 122 // Dispatches message event to the document. |
108 void PostMessage(const base::string16& message, | 123 void PostMessage(const base::string16& message, |
109 const std::vector<int>& sent_message_port_ids); | 124 const std::vector<int>& sent_message_port_ids); |
110 | 125 |
111 private: | 126 private: |
112 // Creates a ServiceWorkerHandle to retain |version| and returns a | 127 // Creates a ServiceWorkerHandle to retain |version| and returns a |
113 // ServiceWorkerInfo with the handle ID to pass to the provider. The | 128 // ServiceWorkerInfo with the handle ID to pass to the provider. The |
114 // provider is responsible for releasing the handle. | 129 // provider is responsible for releasing the handle. |
115 ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version); | 130 ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version); |
116 | 131 |
117 const int process_id_; | 132 const int process_id_; |
118 const int provider_id_; | 133 const int provider_id_; |
119 GURL document_url_; | 134 GURL document_url_; |
120 | 135 |
136 scoped_refptr<ServiceWorkerRegistration> associated_registration_; | |
137 | |
121 scoped_refptr<ServiceWorkerVersion> controlling_version_; | 138 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
122 scoped_refptr<ServiceWorkerVersion> active_version_; | 139 scoped_refptr<ServiceWorkerVersion> active_version_; |
123 scoped_refptr<ServiceWorkerVersion> waiting_version_; | 140 scoped_refptr<ServiceWorkerVersion> waiting_version_; |
124 scoped_refptr<ServiceWorkerVersion> installing_version_; | 141 scoped_refptr<ServiceWorkerVersion> installing_version_; |
125 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 142 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
126 base::WeakPtr<ServiceWorkerContextCore> context_; | 143 base::WeakPtr<ServiceWorkerContextCore> context_; |
127 ServiceWorkerDispatcherHost* dispatcher_host_; | 144 ServiceWorkerDispatcherHost* dispatcher_host_; |
128 | 145 |
129 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 146 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
130 }; | 147 }; |
131 | 148 |
132 } // namespace content | 149 } // namespace content |
133 | 150 |
134 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 151 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |