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

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

Issue 2891903002: ServiceWorker: Keep info as a member of ServiceWorkerProviderHost (Closed)
Patch Set: Rebased Created 3 years, 7 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_provider_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 static std::unique_ptr<ServiceWorkerProviderHost> Create( 81 static std::unique_ptr<ServiceWorkerProviderHost> Create(
82 int process_id, 82 int process_id,
83 ServiceWorkerProviderHostInfo info, 83 ServiceWorkerProviderHostInfo info,
84 base::WeakPtr<ServiceWorkerContextCore> context, 84 base::WeakPtr<ServiceWorkerContextCore> context,
85 ServiceWorkerDispatcherHost* dispatcher_host); 85 ServiceWorkerDispatcherHost* dispatcher_host);
86 86
87 virtual ~ServiceWorkerProviderHost(); 87 virtual ~ServiceWorkerProviderHost();
88 88
89 const std::string& client_uuid() const { return client_uuid_; } 89 const std::string& client_uuid() const { return client_uuid_; }
90 int process_id() const { return render_process_id_; } 90 int process_id() const { return render_process_id_; }
91 int provider_id() const { return provider_id_; } 91 int provider_id() const { return info_.provider_id; }
92 int frame_id() const; 92 int frame_id() const;
93 int route_id() const { return route_id_; } 93 int route_id() const { return info_.route_id; }
94 const WebContentsGetter& web_contents_getter() const { 94 const WebContentsGetter& web_contents_getter() const {
95 return web_contents_getter_; 95 return web_contents_getter_;
96 } 96 }
97 97
98 bool is_parent_frame_secure() const { return is_parent_frame_secure_; } 98 bool is_parent_frame_secure() const { return info_.is_parent_frame_secure; }
99 99
100 // Returns whether this provider host is secure enough to have a service 100 // Returns whether this provider host is secure enough to have a service
101 // worker controller. 101 // worker controller.
102 // Analogous to Blink's Document::isSecureContext. Because of how service 102 // Analogous to Blink's Document::isSecureContext. Because of how service
103 // worker intercepts main resource requests, this check must be done 103 // worker intercepts main resource requests, this check must be done
104 // browser-side once the URL is known (see comments in 104 // browser-side once the URL is known (see comments in
105 // ServiceWorkerNetworkProvider::CreateForNavigation). This function uses 105 // ServiceWorkerNetworkProvider::CreateForNavigation). This function uses
106 // |document_url_| and |is_parent_frame_secure_| to determine context 106 // |document_url_| and |is_parent_frame_secure_| to determine context
107 // security, so they must be set properly before calling this function. 107 // security, so they must be set properly before calling this function.
108 bool IsContextSecureForServiceWorker() const; 108 bool IsContextSecureForServiceWorker() const;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // Only clients can have an associated registration. 150 // Only clients can have an associated registration.
151 DCHECK(!associated_registration_ || IsProviderForClient()); 151 DCHECK(!associated_registration_ || IsProviderForClient());
152 return associated_registration_.get(); 152 return associated_registration_.get();
153 } 153 }
154 154
155 // The running version, if any, that this provider is providing resource 155 // The running version, if any, that this provider is providing resource
156 // loads for. 156 // loads for.
157 ServiceWorkerVersion* running_hosted_version() const { 157 ServiceWorkerVersion* running_hosted_version() const {
158 // Only providers for controllers can host a running version. 158 // Only providers for controllers can host a running version.
159 DCHECK(!running_hosted_version_ || 159 DCHECK(!running_hosted_version_ ||
160 provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER); 160 info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER);
161 return running_hosted_version_.get(); 161 return running_hosted_version_.get();
162 } 162 }
163 163
164 // Sets the |document_url_|. When this object is for a client, 164 // Sets the |document_url_|. When this object is for a client,
165 // |matching_registrations_| gets also updated to ensure that |document_url_| 165 // |matching_registrations_| gets also updated to ensure that |document_url_|
166 // is in scope of all |matching_registrations_|. 166 // is in scope of all |matching_registrations_|.
167 void SetDocumentUrl(const GURL& url); 167 void SetDocumentUrl(const GURL& url);
168 const GURL& document_url() const { return document_url_; } 168 const GURL& document_url() const { return document_url_; }
169 169
170 void SetTopmostFrameUrl(const GURL& url); 170 void SetTopmostFrameUrl(const GURL& url);
171 const GURL& topmost_frame_url() const { return topmost_frame_url_; } 171 const GURL& topmost_frame_url() const { return topmost_frame_url_; }
172 172
173 ServiceWorkerProviderType provider_type() const { return provider_type_; } 173 ServiceWorkerProviderType provider_type() const { return info_.type; }
174 bool IsProviderForClient() const; 174 bool IsProviderForClient() const;
175 blink::WebServiceWorkerClientType client_type() const; 175 blink::WebServiceWorkerClientType client_type() const;
176 176
177 // Associates to |registration| to listen for its version change events and 177 // Associates to |registration| to listen for its version change events and
178 // sets the controller. If |notify_controllerchange| is true, instructs the 178 // sets the controller. If |notify_controllerchange| is true, instructs the
179 // renderer to dispatch a 'controllerchange' event. 179 // renderer to dispatch a 'controllerchange' event.
180 void AssociateRegistration(ServiceWorkerRegistration* registration, 180 void AssociateRegistration(ServiceWorkerRegistration* registration,
181 bool notify_controllerchange); 181 bool notify_controllerchange);
182 182
183 // Clears the associated registration and stop listening to it. 183 // Clears the associated registration and stop listening to it.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 struct OneShotGetReadyCallback { 312 struct OneShotGetReadyCallback {
313 GetRegistrationForReadyCallback callback; 313 GetRegistrationForReadyCallback callback;
314 bool called; 314 bool called;
315 315
316 explicit OneShotGetReadyCallback( 316 explicit OneShotGetReadyCallback(
317 const GetRegistrationForReadyCallback& callback); 317 const GetRegistrationForReadyCallback& callback);
318 ~OneShotGetReadyCallback(); 318 ~OneShotGetReadyCallback();
319 }; 319 };
320 320
321 ServiceWorkerProviderHost(int render_process_id, 321 ServiceWorkerProviderHost(int render_process_id,
322 int route_id, 322 ServiceWorkerProviderHostInfo info,
323 int provider_id,
324 ServiceWorkerProviderType provider_type,
325 bool is_parent_frame_secure,
326 base::WeakPtr<ServiceWorkerContextCore> context, 323 base::WeakPtr<ServiceWorkerContextCore> context,
327 ServiceWorkerDispatcherHost* dispatcher_host); 324 ServiceWorkerDispatcherHost* dispatcher_host);
328 325
329 // ServiceWorkerRegistration::Listener overrides. 326 // ServiceWorkerRegistration::Listener overrides.
330 void OnVersionAttributesChanged( 327 void OnVersionAttributesChanged(
331 ServiceWorkerRegistration* registration, 328 ServiceWorkerRegistration* registration,
332 ChangedVersionAttributesMask changed_mask, 329 ChangedVersionAttributesMask changed_mask,
333 const ServiceWorkerRegistrationInfo& info) override; 330 const ServiceWorkerRegistrationInfo& info) override;
334 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; 331 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override;
335 void OnRegistrationFinishedUninstalling( 332 void OnRegistrationFinishedUninstalling(
(...skipping 28 matching lines...) Expand all
364 int frame_routing_id, 361 int frame_routing_id,
365 ServiceWorkerDispatcherHost* dispatcher_host); 362 ServiceWorkerDispatcherHost* dispatcher_host);
366 363
367 // Clears the information of the ServiceWorkerWorkerClient of dedicated (or 364 // Clears the information of the ServiceWorkerWorkerClient of dedicated (or
368 // shared) worker, when the connection to the worker is disconnected. 365 // shared) worker, when the connection to the worker is disconnected.
369 void UnregisterWorkerFetchContext(mojom::ServiceWorkerWorkerClient*); 366 void UnregisterWorkerFetchContext(mojom::ServiceWorkerWorkerClient*);
370 367
371 std::string client_uuid_; 368 std::string client_uuid_;
372 int render_process_id_; 369 int render_process_id_;
373 370
374 // See the constructor's documentation.
375 int route_id_;
376
377 // For provider hosts that are hosting a running service worker, the id of the 371 // For provider hosts that are hosting a running service worker, the id of the
378 // service worker thread. Otherwise, |kDocumentMainThreadId|. May be 372 // service worker thread. Otherwise, |kDocumentMainThreadId|. May be
379 // |kInvalidEmbeddedWorkerThreadId| before the hosted service worker starts 373 // |kInvalidEmbeddedWorkerThreadId| before the hosted service worker starts
380 // up, or during cross-site transfers. 374 // up, or during cross-site transfers.
381 int render_thread_id_; 375 int render_thread_id_;
382 376
383 // Unique within the renderer process. 377 // Keeps the basic provider's info provided from the renderer side.
384 int provider_id_; 378 ServiceWorkerProviderHostInfo info_;
385 379
386 // PlzNavigate 380 // PlzNavigate
387 // Only set when this object is pre-created for a navigation. It indicates the 381 // Only set when this object is pre-created for a navigation. It indicates the
388 // tab where the navigation occurs. 382 // tab where the navigation occurs.
389 WebContentsGetter web_contents_getter_; 383 WebContentsGetter web_contents_getter_;
390 384
391 ServiceWorkerProviderType provider_type_;
392 const bool is_parent_frame_secure_;
393 GURL document_url_; 385 GURL document_url_;
394 GURL topmost_frame_url_; 386 GURL topmost_frame_url_;
395 387
396 std::vector<GURL> associated_patterns_; 388 std::vector<GURL> associated_patterns_;
397 scoped_refptr<ServiceWorkerRegistration> associated_registration_; 389 scoped_refptr<ServiceWorkerRegistration> associated_registration_;
398 390
399 // Keyed by registration scope URL length. 391 // Keyed by registration scope URL length.
400 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> 392 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>>
401 ServiceWorkerRegistrationMap; 393 ServiceWorkerRegistrationMap;
402 // Contains all living registrations whose pattern this document's URL 394 // Contains all living registrations whose pattern this document's URL
(...skipping 15 matching lines...) Expand all
418 std::unordered_map<mojom::ServiceWorkerWorkerClient*, 410 std::unordered_map<mojom::ServiceWorkerWorkerClient*,
419 mojom::ServiceWorkerWorkerClientAssociatedPtr> 411 mojom::ServiceWorkerWorkerClientAssociatedPtr>
420 worker_clients_; 412 worker_clients_;
421 413
422 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); 414 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
423 }; 415 };
424 416
425 } // namespace content 417 } // namespace content
426 418
427 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ 419 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_provider_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698