class Sender;
}
-namespace webkit_blob {
+namespace storage {
class BlobStorageContext;
}
namespace content {
+class ResourceRequestBody;
class ServiceWorkerContextCore;
class ServiceWorkerDispatcherHost;
class ServiceWorkerRequestHandler;
// Note this class can also host a running service worker, in which
// case it will observe resource loads made directly by the service worker.
class CONTENT_EXPORT ServiceWorkerProviderHost
- : public ServiceWorkerRegistration::Listener,
+ : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener),
public base::SupportsWeakPtr<ServiceWorkerProviderHost> {
public:
ServiceWorkerProviderHost(int process_id,
int provider_id() const { return provider_id_; }
bool IsHostToRunningServiceWorker() {
- return running_hosted_version_ != NULL;
+ return running_hosted_version_.get() != NULL;
}
- // Getters for the navigator.serviceWorker attribute values.
ServiceWorkerVersion* controlling_version() const {
return controlling_version_.get();
}
ServiceWorkerVersion* active_version() const {
- return active_version_.get();
+ return associated_registration_.get() ?
+ associated_registration_->active_version() : NULL;
}
ServiceWorkerVersion* waiting_version() const {
- return waiting_version_.get();
+ return associated_registration_.get() ?
+ associated_registration_->waiting_version() : NULL;
}
ServiceWorkerVersion* installing_version() const {
- return installing_version_.get();
+ return associated_registration_.get() ?
+ associated_registration_->installing_version() : NULL;
}
// The running version, if any, that this provider is providing resource
void AssociateRegistration(ServiceWorkerRegistration* registration);
// Clears the associated registration and stop listening to it.
- void UnassociateRegistration();
+ void DisassociateRegistration();
// Returns false if the version is not in the expected STARTING in our
// process state. That would be indicative of a bad IPC message.
// the request doesn't require special handling.
scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler(
ResourceType resource_type,
- base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context);
+ base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
+ scoped_refptr<ResourceRequestBody> body);
// Returns true if |registration| can be associated with this provider.
bool CanAssociateRegistration(ServiceWorkerRegistration* registration);
+ // For use by the ServiceWorkerControlleeRequestHandler to disallow
+ // new registration association while a navigation is occurring and
+ // an existing registration is being looked for.
+ void SetAllowAssociation(bool allow) { allow_association_ = allow; }
+
// Returns true if the context referred to by this host (i.e. |context_|) is
// still alive.
bool IsContextAlive();
void PostMessage(const base::string16& message,
const std::vector<int>& sent_message_port_ids);
+ // Adds reference of this host's process to the |pattern|, the reference will
+ // be removed in destructor.
+ void AddScopedProcessReferenceToPattern(const GURL& pattern);
+
private:
friend class ServiceWorkerProviderHostTest;
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
UpdateAfter24Hours);
// ServiceWorkerRegistration::Listener overrides.
- virtual void OnVersionAttributesChanged(
- ServiceWorkerRegistration* registration,
- ChangedVersionAttributesMask changed_mask,
- const ServiceWorkerRegistrationInfo& info) OVERRIDE;
virtual void OnRegistrationFailed(
ServiceWorkerRegistration* registration) OVERRIDE;
- // Sets the corresponding version field to the given version or if the given
- // version is NULL, clears the field.
- void SetVersionAttributes(
- ServiceWorkerVersion* installing_version,
- ServiceWorkerVersion* waiting_version,
- ServiceWorkerVersion* active_version);
- void SetVersionAttributesInternal(
- ServiceWorkerVersion* version,
- scoped_refptr<ServiceWorkerVersion>* data_member);
-
// Sets the controller version field to |version| or if |version| is NULL,
// clears the field.
void SetControllerVersionAttribute(ServiceWorkerVersion* version);
- // Clears all version fields.
- void ClearVersionAttributes();
-
// Creates a ServiceWorkerHandle to retain |version| and returns a
// ServiceWorkerInfo with the handle ID to pass to the provider. The
// provider is responsible for releasing the handle.
ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version);
+ // Increase/decrease this host's process reference for |pattern|.
+ void IncreaseProcessReference(const GURL& pattern);
+ void DecreaseProcessReference(const GURL& pattern);
+
const int process_id_;
const int provider_id_;
GURL document_url_;
+ std::vector<GURL> associated_patterns_;
scoped_refptr<ServiceWorkerRegistration> associated_registration_;
scoped_refptr<ServiceWorkerVersion> controlling_version_;
- scoped_refptr<ServiceWorkerVersion> active_version_;
- scoped_refptr<ServiceWorkerVersion> waiting_version_;
- scoped_refptr<ServiceWorkerVersion> installing_version_;
scoped_refptr<ServiceWorkerVersion> running_hosted_version_;
base::WeakPtr<ServiceWorkerContextCore> context_;
ServiceWorkerDispatcherHost* dispatcher_host_;
+ bool allow_association_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
};