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

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

Issue 1210643002: Update navigator.services API to use the new services.onconnect event [2/3]. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serviceport
Patch Set: properly close connections when a worker is stopped Created 5 years, 5 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
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_VERSION_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
7 7
8 #include <map> 8 #include <map>
9 #include <queue> 9 #include <queue>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
17 #include "base/id_map.h" 17 #include "base/id_map.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/observer_list.h" 20 #include "base/observer_list.h"
21 #include "base/timer/timer.h" 21 #include "base/timer/timer.h"
22 #include "content/browser/service_worker/embedded_worker_instance.h" 22 #include "content/browser/service_worker/embedded_worker_instance.h"
23 #include "content/browser/service_worker/service_worker_script_cache_map.h" 23 #include "content/browser/service_worker/service_worker_script_cache_map.h"
24 #include "content/common/content_export.h" 24 #include "content/common/content_export.h"
25 #include "content/common/service_port_service.mojom.h"
25 #include "content/common/service_worker/service_worker_status_code.h" 26 #include "content/common/service_worker/service_worker_status_code.h"
26 #include "content/common/service_worker/service_worker_types.h" 27 #include "content/common/service_worker/service_worker_types.h"
28 #include "content/public/common/service_registry.h"
29 #include "mojo/common/common_type_converters.h"
30 #include "mojo/common/url_type_converters.h"
27 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h" 31 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h"
28 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" 32 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
29 33
30 // Windows headers will redefine SendMessage. 34 // Windows headers will redefine SendMessage.
31 #ifdef SendMessage 35 #ifdef SendMessage
32 #undef SendMessage 36 #undef SendMessage
33 #endif 37 #endif
34 38
35 class GURL; 39 class GURL;
36 40
(...skipping 25 matching lines...) Expand all
62 // running worker. 66 // running worker.
63 class CONTENT_EXPORT ServiceWorkerVersion 67 class CONTENT_EXPORT ServiceWorkerVersion
64 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), 68 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>),
65 public EmbeddedWorkerInstance::Listener { 69 public EmbeddedWorkerInstance::Listener {
66 public: 70 public:
67 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; 71 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback;
68 typedef base::Callback<void(ServiceWorkerStatusCode, 72 typedef base::Callback<void(ServiceWorkerStatusCode,
69 ServiceWorkerFetchEventResult, 73 ServiceWorkerFetchEventResult,
70 const ServiceWorkerResponse&)> FetchCallback; 74 const ServiceWorkerResponse&)> FetchCallback;
71 typedef base::Callback<void(ServiceWorkerStatusCode, 75 typedef base::Callback<void(ServiceWorkerStatusCode,
72 bool /* accept_connction */)> 76 bool /* accept_connction */,
73 CrossOriginConnectCallback; 77 const base::string16& /* name */,
78 const base::string16& /* data */)>
79 ServicePortConnectCallback;
74 typedef base::Callback<void(ServiceWorkerStatusCode, const std::vector<int>&)> 80 typedef base::Callback<void(ServiceWorkerStatusCode, const std::vector<int>&)>
75 SendStashedPortsCallback; 81 SendStashedPortsCallback;
76 82
77 enum RunningStatus { 83 enum RunningStatus {
78 STOPPED = EmbeddedWorkerInstance::STOPPED, 84 STOPPED = EmbeddedWorkerInstance::STOPPED,
79 STARTING = EmbeddedWorkerInstance::STARTING, 85 STARTING = EmbeddedWorkerInstance::STARTING,
80 RUNNING = EmbeddedWorkerInstance::RUNNING, 86 RUNNING = EmbeddedWorkerInstance::RUNNING,
81 STOPPING = EmbeddedWorkerInstance::STOPPING, 87 STOPPING = EmbeddedWorkerInstance::STOPPING,
82 }; 88 };
83 89
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // calls |callback| when it errors out or it gets a response from the worker 236 // calls |callback| when it errors out or it gets a response from the worker
231 // to notify completion. 237 // to notify completion.
232 // 238 //
233 // This must be called when the status() is ACTIVATED. 239 // This must be called when the status() is ACTIVATED.
234 void DispatchGeofencingEvent( 240 void DispatchGeofencingEvent(
235 const StatusCallback& callback, 241 const StatusCallback& callback,
236 blink::WebGeofencingEventType event_type, 242 blink::WebGeofencingEventType event_type,
237 const std::string& region_id, 243 const std::string& region_id,
238 const blink::WebCircularGeofencingRegion& region); 244 const blink::WebCircularGeofencingRegion& region);
239 245
240 // Sends a cross origin connect event to the associated embedded worker and 246 // Sends a ServicePort connect event to the associated embedded worker and
241 // asynchronously calls |callback| with the response from the worker. 247 // asynchronously calls |callback| with the response from the worker.
242 // 248 //
243 // This must be called when the status() is ACTIVATED. 249 // This must be called when the status() is ACTIVATED.
244 void DispatchCrossOriginConnectEvent( 250 void DispatchServicePortConnectEvent(
245 const CrossOriginConnectCallback& callback, 251 const ServicePortConnectCallback& callback,
246 const NavigatorConnectClient& client); 252 const GURL& target_url,
253 const GURL& origin,
254 int port_id);
247 255
248 // Sends a cross origin message event to the associated embedded worker and 256 // Sends a cross origin message event to the associated embedded worker and
249 // asynchronously calls |callback| when the message was sent (or failed to 257 // asynchronously calls |callback| when the message was sent (or failed to
250 // sent). 258 // sent).
251 // It is the responsibility of the code calling this method to make sure that 259 // It is the responsibility of the code calling this method to make sure that
252 // any transferred message ports are put on hold while potentially a process 260 // any transferred message ports are put on hold while potentially a process
253 // for the service worker is spun up. 261 // for the service worker is spun up.
254 // 262 //
255 // This must be called when the status() is ACTIVATED. 263 // This must be called when the status() is ACTIVATED.
256 void DispatchCrossOriginMessageEvent( 264 void DispatchCrossOriginMessageEvent(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; 364 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>;
357 365
358 enum RequestType { 366 enum RequestType {
359 REQUEST_ACTIVATE, 367 REQUEST_ACTIVATE,
360 REQUEST_INSTALL, 368 REQUEST_INSTALL,
361 REQUEST_FETCH, 369 REQUEST_FETCH,
362 REQUEST_SYNC, 370 REQUEST_SYNC,
363 REQUEST_NOTIFICATION_CLICK, 371 REQUEST_NOTIFICATION_CLICK,
364 REQUEST_PUSH, 372 REQUEST_PUSH,
365 REQUEST_GEOFENCING, 373 REQUEST_GEOFENCING,
366 REQUEST_CROSS_ORIGIN_CONNECT 374 REQUEST_SERVICE_PORT_CONNECT
367 }; 375 };
368 376
369 struct RequestInfo { 377 struct RequestInfo {
370 RequestInfo(int id, RequestType type); 378 RequestInfo(int id, RequestType type);
371 ~RequestInfo(); 379 ~RequestInfo();
372 int id; 380 int id;
373 RequestType type; 381 RequestType type;
374 base::TimeTicks time; 382 base::TimeTicks time;
375 }; 383 };
376 384
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 blink::WebServiceWorkerEventResult result); 429 blink::WebServiceWorkerEventResult result);
422 void OnFetchEventFinished(int request_id, 430 void OnFetchEventFinished(int request_id,
423 ServiceWorkerFetchEventResult result, 431 ServiceWorkerFetchEventResult result,
424 const ServiceWorkerResponse& response); 432 const ServiceWorkerResponse& response);
425 void OnSyncEventFinished(int request_id, 433 void OnSyncEventFinished(int request_id,
426 blink::WebServiceWorkerEventResult result); 434 blink::WebServiceWorkerEventResult result);
427 void OnNotificationClickEventFinished(int request_id); 435 void OnNotificationClickEventFinished(int request_id);
428 void OnPushEventFinished(int request_id, 436 void OnPushEventFinished(int request_id,
429 blink::WebServiceWorkerEventResult result); 437 blink::WebServiceWorkerEventResult result);
430 void OnGeofencingEventFinished(int request_id); 438 void OnGeofencingEventFinished(int request_id);
431 void OnCrossOriginConnectEventFinished(int request_id, 439 void OnServicePortConnectEventFinished(int request_id,
432 bool accept_connection); 440 ServicePortConnectResult result,
441 const mojo::String& name,
442 const mojo::String& data);
433 void OnOpenWindow(int request_id, GURL url); 443 void OnOpenWindow(int request_id, GURL url);
434 void DidOpenWindow(int request_id, 444 void DidOpenWindow(int request_id,
435 int render_process_id, 445 int render_process_id,
436 int render_frame_id); 446 int render_frame_id);
437 void OnOpenWindowFinished(int request_id, 447 void OnOpenWindowFinished(int request_id,
438 const std::string& client_uuid, 448 const std::string& client_uuid,
439 const ServiceWorkerClientInfo& client_info); 449 const ServiceWorkerClientInfo& client_info);
440 450
441 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data); 451 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data);
442 void OnSetCachedMetadataFinished(int64 callback_id, int result); 452 void OnSetCachedMetadataFinished(int64 callback_id, int result);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 // Sets |stale_time_| if this worker is stale, causing an update to eventually 525 // Sets |stale_time_| if this worker is stale, causing an update to eventually
516 // occur once the worker stops or is running too long. 526 // occur once the worker stops or is running too long.
517 void MarkIfStale(); 527 void MarkIfStale();
518 528
519 void FoundRegistrationForUpdate( 529 void FoundRegistrationForUpdate(
520 ServiceWorkerStatusCode status, 530 ServiceWorkerStatusCode status,
521 const scoped_refptr<ServiceWorkerRegistration>& registration); 531 const scoped_refptr<ServiceWorkerRegistration>& registration);
522 532
523 void OnStoppedInternal(EmbeddedWorkerInstance::Status old_status); 533 void OnStoppedInternal(EmbeddedWorkerInstance::Status old_status);
524 534
535 template <typename Interface, typename Callback>
536 void OnMojoConnectionError(
537 mojo::InterfacePtr<Interface>* interface,
538 IDMap<Callback, IDMapOwnPointer>* callbacks,
539 const base::Callback<void(const Callback&, ServiceWorkerStatusCode)>
540 callback);
541
525 const int64 version_id_; 542 const int64 version_id_;
526 const int64 registration_id_; 543 const int64 registration_id_;
527 const GURL script_url_; 544 const GURL script_url_;
528 const GURL scope_; 545 const GURL scope_;
529 546
530 Status status_ = NEW; 547 Status status_ = NEW;
531 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; 548 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_;
532 std::vector<StatusCallback> start_callbacks_; 549 std::vector<StatusCallback> start_callbacks_;
533 std::vector<StatusCallback> stop_callbacks_; 550 std::vector<StatusCallback> stop_callbacks_;
534 std::vector<base::Closure> status_change_callbacks_; 551 std::vector<base::Closure> status_change_callbacks_;
535 552
536 // Message callbacks. (Update HasInflightRequests() too when you update this 553 // Message callbacks. (Update HasInflightRequests() too when you update this
537 // list.) 554 // list.)
538 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; 555 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_;
539 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; 556 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_;
540 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; 557 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_;
541 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; 558 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_;
542 IDMap<StatusCallback, IDMapOwnPointer> notification_click_callbacks_; 559 IDMap<StatusCallback, IDMapOwnPointer> notification_click_callbacks_;
543 IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_; 560 IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_;
544 IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_; 561 IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_;
545 IDMap<CrossOriginConnectCallback, IDMapOwnPointer> 562 IDMap<ServicePortConnectCallback, IDMapOwnPointer>
546 cross_origin_connect_callbacks_; 563 service_port_connect_callbacks_;
564
565 ServicePortDispatcherPtr service_port_dispatcher_;
547 566
548 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; 567 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_;
549 568
550 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_; 569 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_;
551 // Will be null while shutting down. 570 // Will be null while shutting down.
552 base::WeakPtr<ServiceWorkerContextCore> context_; 571 base::WeakPtr<ServiceWorkerContextCore> context_;
553 base::ObserverList<Listener> listeners_; 572 base::ObserverList<Listener> listeners_;
554 ServiceWorkerScriptCacheMap script_cache_map_; 573 ServiceWorkerScriptCacheMap script_cache_map_;
555 base::OneShotTimer<ServiceWorkerVersion> update_timer_; 574 base::OneShotTimer<ServiceWorkerVersion> update_timer_;
556 575
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 scoped_ptr<Metrics> metrics_; 610 scoped_ptr<Metrics> metrics_;
592 611
593 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; 612 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_;
594 613
595 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); 614 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
596 }; 615 };
597 616
598 } // namespace content 617 } // namespace content
599 618
600 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 619 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698