| 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 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 // The running version, if any, that this provider is providing resource | 72 // The running version, if any, that this provider is providing resource |
| 73 // loads for. | 73 // loads for. |
| 74 ServiceWorkerVersion* running_hosted_version() const { | 74 ServiceWorkerVersion* running_hosted_version() const { |
| 75 return running_hosted_version_.get(); | 75 return running_hosted_version_.get(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void SetDocumentUrl(const GURL& url); | 78 void SetDocumentUrl(const GURL& url); |
| 79 const GURL& document_url() const { return document_url_; } | 79 const GURL& document_url() const { return document_url_; } |
| 80 | 80 |
| 81 // Associates |version| to the controller field or if |version| is NULL clears | |
| 82 // the field. | |
| 83 void SetControllerVersion(ServiceWorkerVersion* version); | |
| 84 | |
| 85 // Associates to |registration| to listen for its version change events. | 81 // Associates to |registration| to listen for its version change events. |
| 86 void AssociateRegistration(ServiceWorkerRegistration* registration); | 82 void AssociateRegistration(ServiceWorkerRegistration* registration); |
| 87 | 83 |
| 88 // Clears the associated registration and stop listening to it. | 84 // Clears the associated registration and stop listening to it. |
| 89 void UnassociateRegistration(); | 85 void UnassociateRegistration(); |
| 90 | 86 |
| 91 // Returns false if the version is not in the expected STARTING in our | 87 // Returns false if the version is not in the expected STARTING in our |
| 92 // process state. That would be indicative of a bad IPC message. | 88 // process state. That would be indicative of a bad IPC message. |
| 93 bool SetHostedVersionId(int64 versions_id); | 89 bool SetHostedVersionId(int64 versions_id); |
| 94 | 90 |
| 95 // Returns a handler for a request, the handler may return NULL if | 91 // Returns a handler for a request, the handler may return NULL if |
| 96 // the request doesn't require special handling. | 92 // the request doesn't require special handling. |
| 97 scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( | 93 scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( |
| 98 ResourceType resource_type, | 94 ResourceType resource_type, |
| 99 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context); | 95 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context); |
| 100 | 96 |
| 101 // Returns true if |version| can be associated with this provider. | |
| 102 bool CanAssociateVersion(ServiceWorkerVersion* version); | |
| 103 | |
| 104 // Returns true if |registration| can be associated with this provider. | 97 // Returns true if |registration| can be associated with this provider. |
| 105 bool CanAssociateRegistration(ServiceWorkerRegistration* registration); | 98 bool CanAssociateRegistration(ServiceWorkerRegistration* registration); |
| 106 | 99 |
| 107 // Returns true if the context referred to by this host (i.e. |context_|) is | 100 // Returns true if the context referred to by this host (i.e. |context_|) is |
| 108 // still alive. | 101 // still alive. |
| 109 bool IsContextAlive(); | 102 bool IsContextAlive(); |
| 110 | 103 |
| 111 // Dispatches message event to the document. | 104 // Dispatches message event to the document. |
| 112 void PostMessage(const base::string16& message, | 105 void PostMessage(const base::string16& message, |
| 113 const std::vector<int>& sent_message_port_ids); | 106 const std::vector<int>& sent_message_port_ids); |
| 114 | 107 |
| 115 private: | 108 private: |
| 116 friend class ServiceWorkerProviderHostTest; | 109 friend class ServiceWorkerProviderHostTest; |
| 117 | 110 |
| 118 // ServiceWorkerRegistration::Listener overrides. | 111 // ServiceWorkerRegistration::Listener overrides. |
| 119 virtual void OnVersionAttributesChanged( | 112 virtual void OnVersionAttributesChanged( |
| 120 ServiceWorkerRegistration* registration, | 113 ServiceWorkerRegistration* registration, |
| 121 ChangedVersionAttributesMask changed_mask, | 114 ChangedVersionAttributesMask changed_mask, |
| 122 const ServiceWorkerRegistrationInfo& info) OVERRIDE; | 115 const ServiceWorkerRegistrationInfo& info) OVERRIDE; |
| 123 virtual void OnRegistrationFailed( | 116 virtual void OnRegistrationFailed( |
| 124 ServiceWorkerRegistration* registration) OVERRIDE; | 117 ServiceWorkerRegistration* registration) OVERRIDE; |
| 125 | 118 |
| 126 // Associates |version| to the corresponding field or if |version| is NULL | 119 // Returns true if the version field corresponding to |type| can be set to |
| 120 // |version|. |
| 121 bool CanSetVersionAttribute( |
| 122 ChangedVersionAttributesMask::AttributeType type, |
| 123 ServiceWorkerVersion* version); |
| 124 |
| 125 // Sets the corresponding version field to the given version or if the given |
| 126 // version is NULL, clears the field. |
| 127 void SetVersionAttributes( |
| 128 ServiceWorkerVersion* installing_version, |
| 129 ServiceWorkerVersion* waiting_version, |
| 130 ServiceWorkerVersion* active_version); |
| 131 void SetVersionAttributesInternal( |
| 132 ChangedVersionAttributesMask::AttributeType type, |
| 133 ServiceWorkerVersion* version); |
| 134 |
| 135 // Sets the controller version field to |version| or if |version| is NULL, |
| 127 // clears the field. | 136 // clears the field. |
| 128 void SetActiveVersion(ServiceWorkerVersion* version); | 137 void SetControllerVersionAttribute(ServiceWorkerVersion* version); |
| 129 void SetWaitingVersion(ServiceWorkerVersion* version); | |
| 130 void SetInstallingVersion(ServiceWorkerVersion* version); | |
| 131 | 138 |
| 132 // If |version| is the installing, waiting, or active version of this | 139 // Clears all version fields. |
| 133 // provider, the method will reset that field to NULL. | 140 void ClearVersionAttributes(); |
| 134 void UnsetVersion(ServiceWorkerVersion* version); | |
| 135 | 141 |
| 136 // Creates a ServiceWorkerHandle to retain |version| and returns a | 142 // Creates a ServiceWorkerHandle to retain |version| and returns a |
| 137 // ServiceWorkerInfo with the handle ID to pass to the provider. The | 143 // ServiceWorkerInfo with the handle ID to pass to the provider. The |
| 138 // provider is responsible for releasing the handle. | 144 // provider is responsible for releasing the handle. |
| 139 ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version); | 145 ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version); |
| 140 | 146 |
| 141 const int process_id_; | 147 const int process_id_; |
| 142 const int provider_id_; | 148 const int provider_id_; |
| 143 GURL document_url_; | 149 GURL document_url_; |
| 144 | 150 |
| 145 scoped_refptr<ServiceWorkerRegistration> associated_registration_; | 151 scoped_refptr<ServiceWorkerRegistration> associated_registration_; |
| 146 | 152 |
| 147 scoped_refptr<ServiceWorkerVersion> controlling_version_; | 153 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
| 148 scoped_refptr<ServiceWorkerVersion> active_version_; | 154 scoped_refptr<ServiceWorkerVersion> active_version_; |
| 149 scoped_refptr<ServiceWorkerVersion> waiting_version_; | 155 scoped_refptr<ServiceWorkerVersion> waiting_version_; |
| 150 scoped_refptr<ServiceWorkerVersion> installing_version_; | 156 scoped_refptr<ServiceWorkerVersion> installing_version_; |
| 151 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 157 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
| 152 base::WeakPtr<ServiceWorkerContextCore> context_; | 158 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 153 ServiceWorkerDispatcherHost* dispatcher_host_; | 159 ServiceWorkerDispatcherHost* dispatcher_host_; |
| 154 | 160 |
| 155 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 161 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
| 156 }; | 162 }; |
| 157 | 163 |
| 158 } // namespace content | 164 } // namespace content |
| 159 | 165 |
| 160 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 166 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
| OLD | NEW |