Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.h

Issue 417043006: ServiceWorker: Make SWProviderHost listen to SWRegistration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 101
94 // Returns a handler for a request, the handler may return NULL if 102 // Returns a handler for a request, the handler may return NULL if
95 // the request doesn't require special handling. 103 // the request doesn't require special handling.
96 scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( 104 scoped_ptr<ServiceWorkerRequestHandler> CreateRequestHandler(
97 ResourceType resource_type, 105 ResourceType resource_type,
98 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context); 106 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context);
99 107
100 // Returns true if |version| can be associated with this provider. 108 // Returns true if |version| can be associated with this provider.
101 bool CanAssociateVersion(ServiceWorkerVersion* version); 109 bool CanAssociateVersion(ServiceWorkerVersion* version);
102 110
111 // Associates to |registration| to listen its version change events.
falken 2014/08/05 02:41:28 s/listen/listen for/g
nhiroki 2014/08/05 15:51:12 Done.
112 void AssociateRegistration(ServiceWorkerRegistration* registration);
113
103 // Returns true if the context referred to by this host (i.e. |context_|) is 114 // Returns true if the context referred to by this host (i.e. |context_|) is
104 // still alive. 115 // still alive.
105 bool IsContextAlive(); 116 bool IsContextAlive();
106 117
107 // Dispatches message event to the document. 118 // Dispatches message event to the document.
108 void PostMessage(const base::string16& message, 119 void PostMessage(const base::string16& message,
109 const std::vector<int>& sent_message_port_ids); 120 const std::vector<int>& sent_message_port_ids);
110 121
111 private: 122 private:
112 // Creates a ServiceWorkerHandle to retain |version| and returns a 123 // Creates a ServiceWorkerHandle to retain |version| and returns a
113 // ServiceWorkerInfo with the handle ID to pass to the provider. The 124 // ServiceWorkerInfo with the handle ID to pass to the provider. The
114 // provider is responsible for releasing the handle. 125 // provider is responsible for releasing the handle.
115 ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version); 126 ServiceWorkerObjectInfo CreateHandleAndPass(ServiceWorkerVersion* version);
116 127
117 const int process_id_; 128 const int process_id_;
118 const int provider_id_; 129 const int provider_id_;
119 GURL document_url_; 130 GURL document_url_;
120 131
132 scoped_refptr<ServiceWorkerRegistration> associated_registration_;
133
121 scoped_refptr<ServiceWorkerVersion> controlling_version_; 134 scoped_refptr<ServiceWorkerVersion> controlling_version_;
122 scoped_refptr<ServiceWorkerVersion> active_version_; 135 scoped_refptr<ServiceWorkerVersion> active_version_;
123 scoped_refptr<ServiceWorkerVersion> waiting_version_; 136 scoped_refptr<ServiceWorkerVersion> waiting_version_;
124 scoped_refptr<ServiceWorkerVersion> installing_version_; 137 scoped_refptr<ServiceWorkerVersion> installing_version_;
125 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; 138 scoped_refptr<ServiceWorkerVersion> running_hosted_version_;
126 base::WeakPtr<ServiceWorkerContextCore> context_; 139 base::WeakPtr<ServiceWorkerContextCore> context_;
127 ServiceWorkerDispatcherHost* dispatcher_host_; 140 ServiceWorkerDispatcherHost* dispatcher_host_;
128 141
129 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); 142 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
130 }; 143 };
131 144
132 } // namespace content 145 } // namespace content
133 146
134 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ 147 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698