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(); |
48 | 50 |
49 int process_id() const { return process_id_; } | 51 int process_id() const { return process_id_; } |
50 int provider_id() const { return provider_id_; } | 52 int provider_id() const { return provider_id_; } |
51 | 53 |
52 bool IsHostToRunningServiceWorker() { | 54 bool IsHostToRunningServiceWorker() { |
53 return running_hosted_version_ != NULL; | 55 return running_hosted_version_ != NULL; |
54 } | 56 } |
55 | 57 |
56 // Getters for the navigator.serviceWorker attribute values. | 58 // Getters for the navigator.serviceWorker attribute values. |
57 ServiceWorkerVersion* controlling_version() const { | 59 ServiceWorkerVersion* controlling_version() const { |
(...skipping 11 matching lines...) Expand all Loading... | |
69 | 71 |
70 // The running version, if any, that this provider is providing resource | 72 // The running version, if any, that this provider is providing resource |
71 // loads for. | 73 // loads for. |
72 ServiceWorkerVersion* running_hosted_version() const { | 74 ServiceWorkerVersion* running_hosted_version() const { |
73 return running_hosted_version_.get(); | 75 return running_hosted_version_.get(); |
74 } | 76 } |
75 | 77 |
76 void SetDocumentUrl(const GURL& url); | 78 void SetDocumentUrl(const GURL& url); |
77 const GURL& document_url() const { return document_url_; } | 79 const GURL& document_url() const { return document_url_; } |
78 | 80 |
79 // Associates |version| to the corresponding field or if |version| is NULL | 81 // Associates |version| to the controller field or if |version| is NULL clears |
80 // clears the field. | 82 // the field. |
81 void SetControllerVersion(ServiceWorkerVersion* version); | 83 void SetControllerVersion(ServiceWorkerVersion* version); |
82 void SetActiveVersion(ServiceWorkerVersion* version); | |
83 void SetWaitingVersion(ServiceWorkerVersion* version); | |
84 void SetInstallingVersion(ServiceWorkerVersion* version); | |
85 | 84 |
86 // If |version| is the installing, waiting, or active version of this | 85 // Associates to |registration| to listen for its version change events. |
87 // provider, the method will reset that field to NULL. | 86 void SetRegistration(ServiceWorkerRegistration* registration); |
michaeln
2014/08/07 01:34:35
For similarity with the Can method, i'd call this
nhiroki
2014/08/07 02:57:27
Done.
nhiroki
2014/08/07 03:13:54
Ah, maybe I got it... you mean that having the get
michaeln
2014/08/07 20:33:07
Seems more reflective of the object model. The get
| |
88 void UnsetVersion(ServiceWorkerVersion* version); | |
89 | 87 |
90 // Returns false if the version is not in the expected STARTING in our | 88 // 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. | 89 // process state. That would be indicative of a bad IPC message. |
92 bool SetHostedVersionId(int64 versions_id); | 90 bool SetHostedVersionId(int64 versions_id); |
93 | 91 |
94 // Returns a handler for a request, the handler may return NULL if | 92 // Returns a handler for a request, the handler may return NULL if |
95 // the request doesn't require special handling. | 93 // the request doesn't require special handling. |
96 scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( | 94 scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( |
97 ResourceType resource_type, | 95 ResourceType resource_type, |
98 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context); | 96 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context); |
99 | 97 |
100 // Returns true if |version| can be associated with this provider. | 98 // Returns true if |version| can be associated with this provider. |
101 bool CanAssociateVersion(ServiceWorkerVersion* version); | 99 bool CanAssociateVersion(ServiceWorkerVersion* version); |
102 | 100 |
101 // Returns true if |registration| can be associated with this provider. | |
102 bool CanAssociateRegistration(ServiceWorkerRegistration* registration); | |
103 | |
103 // Returns true if the context referred to by this host (i.e. |context_|) is | 104 // Returns true if the context referred to by this host (i.e. |context_|) is |
104 // still alive. | 105 // still alive. |
105 bool IsContextAlive(); | 106 bool IsContextAlive(); |
106 | 107 |
107 // Dispatches message event to the document. | 108 // Dispatches message event to the document. |
108 void PostMessage(const base::string16& message, | 109 void PostMessage(const base::string16& message, |
109 const std::vector<int>& sent_message_port_ids); | 110 const std::vector<int>& sent_message_port_ids); |
110 | 111 |
111 private: | 112 private: |
113 friend class ServiceWorkerProviderHostTest; | |
114 | |
115 // ServiceWorkerRegistration::Listener overrides. | |
116 virtual void OnVersionAttributesChanged( | |
117 ServiceWorkerRegistration* registration, | |
118 ChangedVersionAttributesMask changed_mask, | |
119 const ServiceWorkerRegistrationInfo& info) OVERRIDE; | |
120 virtual void OnRegistrationDeleted( | |
121 ServiceWorkerRegistration* registration) OVERRIDE; | |
122 | |
123 // Associates |version| to the corresponding field or if |version| is NULL | |
124 // clears the field. | |
125 void SetActiveVersion(ServiceWorkerVersion* version); | |
126 void SetWaitingVersion(ServiceWorkerVersion* version); | |
127 void SetInstallingVersion(ServiceWorkerVersion* version); | |
128 | |
129 // If |version| is the installing, waiting, or active version of this | |
130 // provider, the method will reset that field to NULL. | |
131 void UnsetVersion(ServiceWorkerVersion* version); | |
132 | |
112 // Creates a ServiceWorkerHandle to retain |version| and returns a | 133 // Creates a ServiceWorkerHandle to retain |version| and returns a |
113 // ServiceWorkerInfo with the handle ID to pass to the provider. The | 134 // ServiceWorkerInfo with the handle ID to pass to the provider. The |
114 // provider is responsible for releasing the handle. | 135 // provider is responsible for releasing the handle. |
115 ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version); | 136 ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version); |
116 | 137 |
117 const int process_id_; | 138 const int process_id_; |
118 const int provider_id_; | 139 const int provider_id_; |
119 GURL document_url_; | 140 GURL document_url_; |
120 | 141 |
142 scoped_refptr<ServiceWorkerRegistration> associated_registration_; | |
143 | |
121 scoped_refptr<ServiceWorkerVersion> controlling_version_; | 144 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
122 scoped_refptr<ServiceWorkerVersion> active_version_; | 145 scoped_refptr<ServiceWorkerVersion> active_version_; |
123 scoped_refptr<ServiceWorkerVersion> waiting_version_; | 146 scoped_refptr<ServiceWorkerVersion> waiting_version_; |
124 scoped_refptr<ServiceWorkerVersion> installing_version_; | 147 scoped_refptr<ServiceWorkerVersion> installing_version_; |
125 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 148 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
126 base::WeakPtr<ServiceWorkerContextCore> context_; | 149 base::WeakPtr<ServiceWorkerContextCore> context_; |
127 ServiceWorkerDispatcherHost* dispatcher_host_; | 150 ServiceWorkerDispatcherHost* dispatcher_host_; |
128 | 151 |
129 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 152 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
130 }; | 153 }; |
131 | 154 |
132 } // namespace content | 155 } // namespace content |
133 | 156 |
134 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 157 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |