| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 ServiceWorkerDispatcherHost* dispatcher_host); | 46 ServiceWorkerDispatcherHost* dispatcher_host); |
| 47 ~ServiceWorkerProviderHost(); | 47 ~ServiceWorkerProviderHost(); |
| 48 | 48 |
| 49 int process_id() const { return process_id_; } | 49 int process_id() const { return process_id_; } |
| 50 int provider_id() const { return provider_id_; } | 50 int provider_id() const { return provider_id_; } |
| 51 | 51 |
| 52 bool IsHostToRunningServiceWorker() { | 52 bool IsHostToRunningServiceWorker() { |
| 53 return running_hosted_version_ != NULL; | 53 return running_hosted_version_ != NULL; |
| 54 } | 54 } |
| 55 | 55 |
| 56 // The service worker version that corresponds with | 56 // Getters for the navigator.serviceWorker attribute values. |
| 57 // navigator.serviceWorker.active for our document. | 57 ServiceWorkerVersion* controlling_version() const { |
| 58 return controlling_version_.get(); |
| 59 } |
| 58 ServiceWorkerVersion* active_version() const { | 60 ServiceWorkerVersion* active_version() const { |
| 59 return active_version_.get(); | 61 return active_version_.get(); |
| 60 } | 62 } |
| 61 | |
| 62 // The service worker version that corresponds with | |
| 63 // navigate.serviceWorker.waiting for our document. | |
| 64 ServiceWorkerVersion* waiting_version() const { | 63 ServiceWorkerVersion* waiting_version() const { |
| 65 return waiting_version_.get(); | 64 return waiting_version_.get(); |
| 66 } | 65 } |
| 66 ServiceWorkerVersion* installing_version() const { |
| 67 return installing_version_.get(); |
| 68 } |
| 67 | 69 |
| 68 // The running version, if any, that this provider is providing resource | 70 // The running version, if any, that this provider is providing resource |
| 69 // loads for. | 71 // loads for. |
| 70 ServiceWorkerVersion* running_hosted_version() const { | 72 ServiceWorkerVersion* running_hosted_version() const { |
| 71 return running_hosted_version_.get(); | 73 return running_hosted_version_.get(); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void SetDocumentUrl(const GURL& url); | 76 void SetDocumentUrl(const GURL& url); |
| 75 const GURL& document_url() const { return document_url_; } | 77 const GURL& document_url() const { return document_url_; } |
| 76 | 78 |
| 77 // Associates |version| to this provider as its '.active' or '.waiting' | 79 // Associates |version| to the corresponding field or if |version| is NULL |
| 78 // version. | 80 // clears the field. |
| 79 // Giving NULL to this method will unset the corresponding field. | |
| 80 void SetActiveVersion(ServiceWorkerVersion* version); | 81 void SetActiveVersion(ServiceWorkerVersion* version); |
| 81 void SetWaitingVersion(ServiceWorkerVersion* version); | 82 void SetWaitingVersion(ServiceWorkerVersion* version); |
| 83 void SetInstallingVersion(ServiceWorkerVersion* version); |
| 84 |
| 85 // If |version| is the installing, waiting, or active version of this |
| 86 // provider, the method will reset that field to NULL. |
| 87 void UnsetVersion(ServiceWorkerVersion* version); |
| 82 | 88 |
| 83 // Returns false if the version is not in the expected STARTING in our | 89 // Returns false if the version is not in the expected STARTING in our |
| 84 // process state. That would be indicative of a bad IPC message. | 90 // process state. That would be indicative of a bad IPC message. |
| 85 bool SetHostedVersionId(int64 versions_id); | 91 bool SetHostedVersionId(int64 versions_id); |
| 86 | 92 |
| 87 // Returns a handler for a request, the handler may return NULL if | 93 // Returns a handler for a request, the handler may return NULL if |
| 88 // the request doesn't require special handling. | 94 // the request doesn't require special handling. |
| 89 scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( | 95 scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( |
| 90 ResourceType::Type resource_type, | 96 ResourceType::Type resource_type, |
| 91 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context); | 97 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context); |
| 92 | 98 |
| 93 // Returns true if |version| has the same registration as active and waiting | 99 // Returns true if |version| can be associated with this provider. |
| 94 // versions. | 100 bool CanAssociateVersion(ServiceWorkerVersion* version); |
| 95 bool ValidateVersionForAssociation(ServiceWorkerVersion* version); | |
| 96 | 101 |
| 97 // Returns true if the context referred to by this host (i.e. |context_|) is | 102 // Returns true if the context referred to by this host (i.e. |context_|) is |
| 98 // still alive. | 103 // still alive. |
| 99 bool IsContextAlive(); | 104 bool IsContextAlive(); |
| 100 | 105 |
| 101 // Dispatches message event to the document. | 106 // Dispatches message event to the document. |
| 102 void PostMessage(const base::string16& message, | 107 void PostMessage(const base::string16& message, |
| 103 const std::vector<int>& sent_message_port_ids); | 108 const std::vector<int>& sent_message_port_ids); |
| 104 | 109 |
| 105 private: | 110 private: |
| 106 // Creates a ServiceWorkerHandle to retain |version| and returns a | 111 // Creates a ServiceWorkerHandle to retain |version| and returns a |
| 107 // ServiceWorkerInfo with the handle ID to pass to the provider. The | 112 // ServiceWorkerInfo with the handle ID to pass to the provider. The |
| 108 // provider is responsible for releasing the handle. | 113 // provider is responsible for releasing the handle. |
| 109 ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version); | 114 ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version); |
| 110 | 115 |
| 111 const int process_id_; | 116 const int process_id_; |
| 112 const int provider_id_; | 117 const int provider_id_; |
| 113 GURL document_url_; | 118 GURL document_url_; |
| 119 |
| 120 // TODO(michaeln): controlling_version_ is not used yet. |
| 121 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
| 114 scoped_refptr<ServiceWorkerVersion> active_version_; | 122 scoped_refptr<ServiceWorkerVersion> active_version_; |
| 115 scoped_refptr<ServiceWorkerVersion> waiting_version_; | 123 scoped_refptr<ServiceWorkerVersion> waiting_version_; |
| 124 scoped_refptr<ServiceWorkerVersion> installing_version_; |
| 116 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 125 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
| 117 base::WeakPtr<ServiceWorkerContextCore> context_; | 126 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 118 ServiceWorkerDispatcherHost* dispatcher_host_; | 127 ServiceWorkerDispatcherHost* dispatcher_host_; |
| 119 | 128 |
| 120 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 129 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
| 121 }; | 130 }; |
| 122 | 131 |
| 123 } // namespace content | 132 } // namespace content |
| 124 | 133 |
| 125 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 134 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
| OLD | NEW |